Page 1 of 1

define the page and echoing out row from table

Posted: Wed Dec 07, 2011 4:01 am
by Rob_Scott
Hi,

I have a range of products in a table in my database and each of these has their own page,

What i want to be able to do is have one piece of code that recognises what page i am on and then echos out the row in table which relates to the page.

Sorry its probably a simple solution but i am a newbie :)

Rob

Re: define the page and echoing out row from table

Posted: Wed Dec 07, 2011 4:28 am
by maxx99
Thats a bit other way around. If you're already on that page you don't need to check where you are :)
If you want to use same script to generate more pages you can use a parameter passed by url:
http://php.net/manual/en/reserved.variables.get.php

Re: define the page and echoing out row from table

Posted: Wed Dec 07, 2011 4:36 am
by Rob_Scott
Its ok I have just figured it out :)

thanks for the help.

I used this code:

<?php

if (arg(0) == 'node' && is_numeric(arg(1))) $nodeid = arg(1);

//echo $nodeid;

include_once("connect_to_mysql.php");

$sqlcommand = "SELECT * FROM cars where link = $nodeid";

$query = mysql_query($sqlcommand) or die(mysql_error());
while ($bert = mysql_fetch_array($query))
{
echo $bert['car_name'] . " <br/> ";
}

?>