confused_aswell Posted October 11, 2008 Share Posted October 11, 2008 Hi I have got a db with a lot of records in it, and I would like to know how to create a form where a user enters a number that corresponds to the database entry, this then gets passed to another script where the results are downloaded from that number. Any pointers or help would be great. Thanks, Phil Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/ Share on other sites More sharing options...
Stooney Posted October 11, 2008 Share Posted October 11, 2008 Google 'php mysql tutorial' and you'll find what you need. Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-663016 Share on other sites More sharing options...
confused_aswell Posted October 13, 2008 Author Share Posted October 13, 2008 Hi I have looked on the php-mysql-tutorial website and can't find anything specific to what I want. I have a script that will connect to a database and download all of the rows from that db, now if I use a form to pass a variable (number)to that script how will I tell it to start from that number in the db that has been passed from the form, would it be through ORDER BY in the sql query or by some other way? Any help would be appreciated. Thanks, Phil Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664301 Share on other sites More sharing options...
Maq Posted October 13, 2008 Share Posted October 13, 2008 You should either use the $_POST or $_GET method. $_GET goes through the URL, $_POST is through input field. What do you want to do? Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664315 Share on other sites More sharing options...
confused_aswell Posted October 13, 2008 Author Share Posted October 13, 2008 Hi I can easily pass the url through to the other script, what I want to know is how I get the script that it is passed, to take that variable and use it in that script. For example if the number 5000 is passed to the script, then I would want to download all rows starting from 5000 onwards. Does that make sense? Thanks, Phil Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664319 Share on other sites More sharing options...
Maq Posted October 13, 2008 Share Posted October 13, 2008 What's your variable name? All you do is: $_GET['var_name']; Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664330 Share on other sites More sharing options...
Stooney Posted October 13, 2008 Share Posted October 13, 2008 Assuming the url: http://site.com?number=5000 <?php $code=mysql_real_escape_string($_GET['number']); //SQL Injection Prevention $result=mysql_query("SELECT * FROM tablename WHERE id>='$code'"); while($row=mysql_fetch_array($result)){ echo $row['fieldname']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664337 Share on other sites More sharing options...
confused_aswell Posted October 13, 2008 Author Share Posted October 13, 2008 Hi My variable name would be number. So $_GET['number']; would be the variable, but how would I tell the script that would download the rows from the db to start at $number? Can you see what I am trying to do? Thanks, Phil Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664345 Share on other sites More sharing options...
Stooney Posted October 13, 2008 Share Posted October 13, 2008 Like in my above example: <?php $result=mysql_query("SELECT * FROM tablename WHERE id>='$code'"); That's saying Select all columns from tablename where column named id is greater than or equal to the value of $code. So if code is 5000, it will select all of the rows starting from 5000 and up. Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664349 Share on other sites More sharing options...
Maq Posted October 13, 2008 Share Posted October 13, 2008 SELECT * FROM table LIMIT $number, 5000; Starts at $number and continues for 5000 after that. Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664358 Share on other sites More sharing options...
confused_aswell Posted October 13, 2008 Author Share Posted October 13, 2008 Hi I will give it a try a bit later, I have to go now, but thanks for your help so far. I will come back to the tomorrow. Thanks, Phil Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664359 Share on other sites More sharing options...
confused_aswell Posted October 13, 2008 Author Share Posted October 13, 2008 Hi I have tried both pieces of code but both seem not to work, here are the two scripts. I always think it's better if you can see what you are working with. Thanks, Phil <?php require_once('Connections/zen.php'); ?> <?php mysql_select_db($database_zen, $zen); $query_Recordset1 = "SELECT orders_id, customers_name FROM zen_orders ORDER BY zen_orders.date_purchased desc"; $Recordset1 = mysql_query($query_Recordset1, $zen) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <table width="470" border="0" cellspacing="0" cellpadding="0"> <tr> <td><?php echo "You have $totalRows_Recordset1 records in your database";?>,</td> <td>the last entry was <?php echo $row_Recordset1['customers_name']; ?></td> </tr> </table> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> <form action="excel1.php" method="POST"> <p>Please enter the number which you want to download from? <input name="number" type="text" size="8" > </p> <p> <input type="submit" name="Submit" value="Submit"> </p> </form> </body> </html> <?php mysql_free_result($Recordset1); ?> This is passed to this script - <?php require_once('Connections/zen.php'); ?> <?php $replace = array( 'address_book_id' => '', 'customers_name' => 'Customer Job', 'entry_firstname' => 'First Name', 'entry_lastname' => 'Last Name', 'entry_street_address' => 'Billing Address1', 'entry_suburb' => 'Billing Address2', 'entry_city' => 'Billing Address3', 'entry_state' => 'Billing Address4', 'entry_postcode' => 'Billing Address5', 'customers_email_address' => 'Email', 'customers_telephone' => 'Phone' ); function split_num($num){ $num = substr($num, 0, 5) . ' ' . substr($num, 5); return $num; } $code=mysql_real_escape_string($_GET['number']); //SQL Injection Prevention $values = mysql_query("SELECT zen_orders.customers_name, zen_address_book.entry_firstname, zen_address_book.entry_lastname, zen_address_book.entry_street_address, zen_address_book.entry_suburb, zen_address_book.entry_city, zen_address_book.entry_state, zen_address_book.entry_postcode, zen_orders.customers_telephone, zen_orders.customers_email_address FROM (zen_address_book INNER JOIN zen_orders ON zen_address_book.customers_id = zen_orders.customers_id) INNER JOIN zen_customers ON (zen_address_book.address_book_id = zen_customers.customers_default_address_id) AND (zen_address_book.customers_id = zen_customers.customers_id)"); $i=0; while ($rowr = mysql_fetch_assoc($values)) { if($rowr['entry_suburb'] ==""){ $rowr['entry_suburb'] = $rowr['entry_city']; } if(!preg_match('#\x20#', $rowr['customers_telephone'], $match)){ // does not find a space... $rowr['customers_telephone'] = split_num($rowr['customers_telephone']); } if($i==0) { foreach(array_keys($rowr) as $title) $csv_output .= '"'.str_replace(array_keys($replace), $replace, $title).'",'; $csv_output .= "\n"; } foreach ($rowr as $key => $value) { $csv_output .= '"'.$value.'",'; } $csv_output .= "\n"; $i++; } $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $csv_output; exit; ?> Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664423 Share on other sites More sharing options...
iversonm Posted October 13, 2008 Share Posted October 13, 2008 not sure if its a typo, but you close you php tag on the first line and you dont reopen it.. Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664429 Share on other sites More sharing options...
confused_aswell Posted October 13, 2008 Author Share Posted October 13, 2008 Hi It doesn't matter, as long as the script is readable. Phil Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664434 Share on other sites More sharing options...
DarkWater Posted October 13, 2008 Share Posted October 13, 2008 not sure if its a typo, but you close you php tag on the first line and you dont reopen it.. Uhh, what? Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664444 Share on other sites More sharing options...
confused_aswell Posted October 13, 2008 Author Share Posted October 13, 2008 Lol I thought that too!!! Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664446 Share on other sites More sharing options...
iversonm Posted October 13, 2008 Share Posted October 13, 2008 he edited his code but before he closed his php with ?> and then never reopened it with <?Php Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664465 Share on other sites More sharing options...
Maq Posted October 13, 2008 Share Posted October 13, 2008 he edited his code but before he closed his php with ?> and then never reopened it with <?php sure... Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664510 Share on other sites More sharing options...
Lamez Posted October 13, 2008 Share Posted October 13, 2008 you could also use session variables. Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664523 Share on other sites More sharing options...
iversonm Posted October 14, 2008 Share Posted October 14, 2008 ya alright Maq Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664684 Share on other sites More sharing options...
Maq Posted October 14, 2008 Share Posted October 14, 2008 ya alright Maq I'm just kidding. I didn't even read the posts before this... Let's get back on topic. Sessions could work have you considered this confused_aswell? Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664728 Share on other sites More sharing options...
confused_aswell Posted October 14, 2008 Author Share Posted October 14, 2008 Hi In what way would sessions work, surely it is just passing the variable from the form to the script? The script is part of an admin section of a shopping cart, so I suppose there are already seesions being used. Thanks, Phil Quote Link to comment https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/#findComment-664823 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.