Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/128034-passing-results-to-another-script/
Share on other sites

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

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

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'];
}
?>

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

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.

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;

?> 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.