Jump to content


Photo

php?id= url problem


  • Please log in to reply
4 replies to this topic

#1 dosser

dosser
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 24 May 2006 - 02:47 PM

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?

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 24 May 2006 - 03:00 PM

Its quite hard to debug when we can't see the code! Fancy posting it up?

#3 dosser

dosser
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 24 May 2006 - 03:31 PM

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.

#4 dosser

dosser
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 24 May 2006 - 03:50 PM

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";
}



#5 urbandsigns.com

urbandsigns.com
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 24 May 2006 - 04:50 PM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users