Forum Moderators: coopster

Message Too Old, No Replies

Passing variable & SQL queries

         

field4000

9:35 am on Jul 10, 2005 (gmt 0)

10+ Year Member



Hey all,

I am having some trouble passing a variable from one page to another.

What I would like to do is pull data from table 1 - a list of categories - which will be clickable.
Then when the category is clicked the data from table 2 – the relative links – will be displayed dynamically.

I can display the links in a separate page, this is not the problem. Where I fall down is doing this all dynamically, adding the needed SQL statements.
I am essentially trying to build a really simple links directory - like DMOZ.

Cheers in advance.

mogenshoj

9:46 am on Jul 10, 2005 (gmt 0)

10+ Year Member



Do you mean something like this:

link: page2.php?category=something

SQL query on page2:
mysql_query("select * from db where category= '$_GET[category]'");

field4000

2:16 am on Jul 11, 2005 (gmt 0)

10+ Year Member



Hey,

Thanks for the help thus far.

I am still having a problem though.

Here is the code for the index/first page:

$query = "SELECT CatID, CatName FROM categories";
$result = mysql_query($query) or die('<p>Error: ' . mysql_error().'.</p>');

$result = mysql_query($query);
if(mysql_num_rows($result))
{
while($row = mysql_fetch_row($result))
{
list($CatID, $CatName) = $row;
echo "<p><a href=\"http://localhost/site/display.php?category=$CatID\">$CatName</a></p>\n";
}
}

Here is the code for the links/second page:

$query = "SELECT Name, URL, Description, Category FROM links WHERE Category = '$_GET[CatID]'";
$result = mysql_query($query) or die('<p>Error: ' . mysql_error().'.</p>');

$result = mysql_query($query);
if(mysql_num_rows($result))
{
while($row = mysql_fetch_row($result))
{
list($name, $url, $description, $category) = $row;
echo "<p><a href=\"http://$url\">$name</a><br />";
echo "$description<br /><span class=\"link\">$url</span></p>\n";
}
}

I would like to click on the link on the index page and dynamically generate the links/second page.

Cheers in advance. :)

field4000

2:28 am on Jul 11, 2005 (gmt 0)

10+ Year Member



Thanks for the help.

All solved!

Thread resolved.

Cheers.