Jump to content

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?
Link to comment
https://forums.phpfreaks.com/topic/10354-phpid-url-problem/
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.
Link to comment
https://forums.phpfreaks.com/topic/10354-phpid-url-problem/#findComment-38605
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";
}

Link to comment
https://forums.phpfreaks.com/topic/10354-phpid-url-problem/#findComment-38616
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.