I have a php file that exports my MySQL DB to a spreadsheet (see below). This is great, but I need one more piece of functionality to finish what I'm doing. I need a form (HTML) to come up, prompting the user for a lead number (the primary key). I then want all the records AFTER AND INCLUDING that number to be exported to the spreadhseet, instead of the current way I have it set up, where it exports the entire DB every time.
I'm assuming I need to take the data, in this case the primary key number, in through an HTML form, set that data as a variable, and then do something like
SELECT * from TABLENAME WHERE Leadnumber>$enteredvariable
This seems easy, but, well, you know... 😉
Any help is apprec..
Thx!
PHP
<?php
mysql_connect ("localhost","orlandoi_dbuser","******");
mysql_select_db ("orlandoi_") or die ('I cannot connect to the database because: ' . mysql_error());;
$select = "SELECT * FROM Orlandoleads";
$export = mysql_query ( $select ) or die ( "Sql error : " . mysql_error( ) );
$fields = mysql_num_fields ( $export );
for ( $i = 0; $i < $fields; $i++ )
{
$header .= mysql_field_name( $export , $i ) . "\t";
}
while( $row = mysql_fetch_row( $export ) )
{
$line = '';
foreach( $row as $value )
{
if ( ( !isset( $value ) ) || ( $value == "" ) )
{
$value = "\t";
}
else
{
$value = str_replace( '"' , '""' , $value );
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim( $line ) . "\n";
}
$data = str_replace( "\r" , "" , $data );
if ( $data == "" )
{
$data = "\n(0) Records Found!\n";
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=orlando.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
?>