Jump to content

Archived

This topic is now archived and is closed to further replies.

dosser

php?id= url problem

Recommended Posts

Hi guys, hope you can help me with this.

I have set up my mysql database and several php pages to view and enter data. All working fine.

I discovered a problem when I came to try to produce a list of all entries as links. I then realised that any queries I entered in the 'browse.php' page (which issues a query to the DB and shows the results in a table), although returned the correct results, never actually altered the url. I.E was always ...localhost/browse.php (i.e. missing any ?id=3 etc).

If I try to just type in the url eg ....browse.php?id=3 the entire contents of the database is returned. Anyone have any ideas what the problem could be?

Share this post


Link to post
Share on other sites
Its quite hard to debug when we can't see the code! Fancy posting it up?

Share this post


Link to post
Share on other sites
browse.php

$recipe=addslashes($_POST[recipe]);

$result=@mysql_query("select recipe_name, restaurant_info,chef_name from recipes,restaurant,chefs where recipes.recipe_id=restaurant.recipe_id and chefs.chef_id=restaurant.chef_id and recipe_name like
'%$recipe%' order by restaurant_id");
if(!$result) {echo("<p>Error performing query: " . mysql_error() .
"</p>");
exit();
}

while ($row = mysql_fetch_array($result) ) {
echo("<table border= \"2\" align= \"center\" width=\"900\" cellpadding=\"7\" ><tr><th width\"20\%\">Recipe</th><th width=\"60\%\">Restaurant</th><th width=\"20\%\">Chef</th></tr><tr align= \"center\"><td>"
. $row["recipe_name"] . " </td><td> " . $row["restaurant_info"] . " </td><td> " . $row["chef_name"] . " </td></tr></table>" );}

So this creates a table with the correct info when i search a recipe name from search.html

<form action="browse.php" method="post">

Name:<input type="text" name="recipe" size="50">

<input type="submit" value="submit">
<input type="reset" name="reset" value="reset">

I am looking for 2 things.

a) That in the table above, I can click on eg $row["restaurant_info"] and it will research and provide all info for that restaurant and produce a similar table with the results. (At moment I have a separate page called searchrest.html and browserest.php which do exactly the same as above but searching for restaurants instead. I think I could combine them using OR in the query but that doesnt matter for now).

b) How do I create a list of all entries in the database as links, that when clicked would produce a table with the results as above.

Thanks in advance.

Share this post


Link to post
Share on other sites
I should add that here is the script I tried to use for listing all the entries in the eg recipe table. I can get a list of the recipes, appearing as links, but then when I click on one, instead of outputting the table with just that one recipe, the entire database is listed.

$sql_query = "SELECT * FROM recipes";

$result = mysql_query($sql_query);
if(mysql_num_rows($result))
{

while($row = mysql_fetch_row($result))
{
echo ("<a href=\"browse.php?recipe_id=$row[0]\">$row[1]</a>");

}
}
else
{
echo "no values in the database";
}

Share this post


Link to post
Share on other sites
I would send it to a new page once the link is clicked. Then do a select where ID = $ID and it will display just the information about that 1 restaurant. Does that help or am I reading your question wrong?

Share this post


Link to post
Share on other sites

×

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.