Forum Moderators: coopster

Message Too Old, No Replies

Passing 'var' via GET and then populating page (mysql)

How to populate page using $GET var from previous page

         

knippysing

2:28 pm on May 20, 2005 (gmt 0)

10+ Year Member



First post here. Thanks!
___________________
I have a table with a column of numbers (random):
0000000001
0000000026
0000000059
0000000034
And I would like to link them to go to 1 specific template page. Then once on that page, the number that was clicked gets "posted" to the MySQL Query and the information for the page populated dynamically rather than having to have 4 different pages for each number (that's the way I'm doing it now).

I am passing the data via GET to my template.php page successfully. When I get there, I can't format the page correctly. I may have to post this in MySQL forum but thought I would try here first.
Below is what I have on my initial page. It's populating an array from a MySQL query and then printing the following:

print "<td align=left><font size=2 px><a href=\dev\invoice.php?var='$a'>$a</a></font></td>";
print "<td align=left><font size=2 px>$b</font></td>";
print "<td align=left><font size=2 px>$c</font></td>";
etc...

This passes "http://www.domain.com/dev/template.php?var='0000000026' to the next page (template.php).

Once on the template.php page, I am trying to run a SQL Query that says "WHERE invoice='var'" but I don't know what I need to put in for 'var'...
Basically, whatever "0000000026" is, I want that to be passed to where 'var' is in the query so that it can populate the correct data.

Actual code of template.php page:
<?PHP
require './connect.php';
$result = mysql_query('SELECT Sales.Invoice, Sales.InvDate, SalesLed.Prod
FROM SalesLed INNER JOIN Sales ON SalesLed.Invoice = Sales.Invoice
WHERE (((Sales.Invoice)="0000000026") AND ((SalesLed.Prod)="LAB"))');
while ($row = mysql_fetch_array($result)) {
printf ("%s <br>", $row['InvDate']);
}
mysql_free_result($result);
?>

I want to replace "0000000026" with the 'var' element.

I realize it's probably something simple but I have been looking at this code for too long to figure it out.

Thanks for everything!

dreamcatcher

3:45 pm on May 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[domain.com...]

$var = $_GET['var'];

WHERE var = '$var'

dc

H2O_aa

3:47 pm on May 20, 2005 (gmt 0)

10+ Year Member



you need to use $_GET superglobal to pass the variable contained in your initial script.

$var_new = $_GET['var'];

Then set that to a variable to use on your new page. Put that line of code above your query statement.

Edit: haha, I was writing this and then Dreamcatcher already posted his.

dreamcatcher

3:51 pm on May 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Edit: haha, I was writing this and then Dreamcatcher already posted his.

LOL.

knippysing

4:00 pm on May 20, 2005 (gmt 0)

10+ Year Member



Cool. Thanks guys. I will give this a shot and let you know what I get.
C-

knippysing

8:09 pm on May 20, 2005 (gmt 0)

10+ Year Member



Still not working -- What the heck am I doing wrong? I know I am so close. The template.php will display but not the info. that should come out of it (a date). When I manually type in what's in the 'var' (i.e. 0000000026), I get the date correctly.
Any more ideas before I pull my hair out?
Thanks again for the help with this. I hope to return the favor.

<?PHP
require './connect.php';
$varsome = $_GET['var'];

$result = mysql_query('SELECT Sales.Invoice, Sales.InvDate, SalesLed.Prod
FROM SalesLed INNER JOIN Sales ON SalesLed.Invoice = Sales.Invoice
WHERE Sales.Invoice="$varsome" AND SalesLed.Prod="LAB"');

while ($row = mysql_fetch_array($result)) {
printf ("%s <br>", $row['InvDate']);
}
mysql_free_result($result);

?>

knippysing

8:27 pm on May 20, 2005 (gmt 0)

10+ Year Member



nevermind...
Got it working with the code below. Hopefully it will help someone later:
<?PHP
require './connect.php';
$varsome = $_GET['var'];
$sqlquery1 = "SELECT Sales.Invoice, Sales.InvDate, SalesLed.Prod
FROM SalesLed INNER JOIN Sales ON SalesLed.Invoice = Sales.Invoice
WHERE Sales.Invoice='$varsome' AND SalesLed.Prod='LAB'";
$result = mysql_query($sqlquery1) or die (mysql_error());

while ($row = mysql_fetch_array($result)) {
printf ("%s <br>", $row['InvDate']);
}
mysql_free_result($result);

?>