Jump to content

dosser

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

dosser's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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"; }
  2. 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.
  3. 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?
  4. <? $conn=mysql_connect("localhost","*****","******"); if (!$conn) {die('Could not connect to mysql');} $db= mysql_select_db("food",$conn); //just to see what would happen - this bit works ok $total=count($_POST[chef]); echo("$total"); echo "<pre>"; print_r($_POST); //this bit goes into the database fine $recipe_name=mysql_query("insert into recipe values('null','$_POST[recipe]')"); $recipe_id=mysql_insert_id(); //this is the actual problem $total = count($_POST[chef]); $a_chef = $_POST[chef]; $a_restaurant = $_POST[restaurant]; $a_meal = $_POST[meal]; for ($i=0; $i>=$total; $i++) { $chef_name=mysql_query("insert into chef values('null',$a_chef[$i])"); $chef_id=mysql_insert_id(); $restaurant_name=mysql_query("insert into restaurant values('null',$a_restaurant[$i])"); $retaurant_id=mysql_insert_id(); $meal_info=mysql_query("insert into meal values('null',$recipe_id,$chef_id,$a_meal[$i],$restaurant_id)");} ?> As I say the recipe table works fine, but the other tables have no new entries. No error message appears, only the: echo("$total"); echo "<pre>"; print_r($_POST); Thanks in advance
  5. Not working - no error messages but no data going into tables. Interestingly if i just do: $total=count($_POST[chef]); echo("$total"); I get the result 3, which is correct number of total chef boxes available - however I need to know the number of boxes with any information in. when i try $total=count($_POST[chef]!=null); echo("$total"); I get 1 - no matter how many of the boxes are filled in. Thoughts? Thanks for taking the time gijs! D
  6. ok so now what? I can print the list but what I want to be able to do is put them straight into the database with eg $sql=mysql_query("insert into chef values (".... but I don't understand how to construct the loop because the array has both chef[], restaurant [] and meal []? Any ideas? D P.S Sorry for the double post - just read the old one and realised it made little sense!
  7. Hi all, I need to construct a loop to deal with an HTML form I have written. Reason is that there is some information that will always need to be entered, but then the number of other entries is not fixed - could be one, but could be lots. <html> <form action="process.php" method="post"> Recipe: <input type=text name="recipe" size=40><br/><br/> Chef: <input type="text" name="chef1" size=40><br/><br/> Restaurant: <input type="text" name="restaurant1" size=40><br/><br/> Meal: <input type=text name="meal1" size=140><br /><br/> Chef: <input type="text" name="chef2" size=40><br/><br/> Restaurant: <input type="text" name="restaurant2" size=40><br/><br/> Meal: <input type=text name="meal2" size=140><br /><br/> <INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!"> <input type=reset name"reset" value="reset"> </form></html> I.E There must be one entry for recipe (and always only one), chef, restaurant and meal. But there could be more than one instance of the recipe and thus the need for 2nd boxes for chef/restaurant/meal (this will eventually have about 50 repetitions of these). At the moment I have it working but only by writing it all out long hand - and this will not be practical if there are eg 20 repetitions. At moment looks like: <?php $conn=mysql_connect("localhost","******","******"); if (!$conn) {die('Could not connect to mysql');} $db= mysql_select_db("food",$conn); $recipe_name=mysql_query("insert into recipe values('null','$_POST[recipe]')"); $recipe_id=mysql_insert_id(); $chef_name=mysql_query("insert into chef values('null','$_POST[chef1]')"); $chef_id=mysql_insert_id(); $restaurant_name=mysql_query("insert into restaurant values('null','$_POST[restaurant1]','null','null')"); $restaurant_id=mysql_insert_id(); $meal_info=mysql_query("insert into meal values('null',$recipe_id,$creator_id,'$_POST[meal1]',$restaurant_id)"); if ($_POST[chef2]!=null) {$chef_name2=mysql_query("insert into chef values('null','$_POST[chef2]')"); $chef_id2=mysql_insert_id();} if ($_POST[restaurant2]!=null) {$restaurant_name2=mysql_query("insert into restaurant values('null','$_POST[restaurant2]','null','null')"); $restaurant_id2=mysql_insert_id();} if ($_POST[meal2]) {$meal_info2=mysql_query("insert into meal values('null',$recipe_id,$creator_id2,'$_POST[meal2]',$restaurant_id2)"); ?> (NB. The database is called food. Four tables are: recipe - recipe_id (primary key, auto-incr), and recipe_name chef - chef_id (pr.key, auto-incr) and chef_name restaurant - restaurant_id (pr.key, auto-incr) and restaurant_name meal - meal_id (pr.key, auto-incr), meal_info, recipe_id, creator_id, restaurant_id. ) Obviously there must be a better way to do this, I assume using a loop and perhaps an array. What I can not work out is how to link the array in the 'process.php' to the correct box in the html form. What should the syntax be for the HTML form (eg 'chef[]'?), and how do i construct the php code so that it will loop and insert data in the DB if there is any there? Thanks in advance D
  8. Hi guys sure you can help me with this one, sorry for the long post just want to give as much info as poss. I have database set up in mysql and an html form set up to enter data into it. works fine and dandy. however I now have to go one step further and got stuck. The database is called food. Four tables are: recipe - recipe_id (primary key, auto-incr), and recipe_name chef - chef_id (pr.key, auto-incr) and chef_name restaurant - restaurant_id (pr.key, auto-incr) and restaurant_name meal - meal_id (pr.key, auto-incr), meal_info, recipe_id, creator_id, restaurant_id. Meal=the reason you were at the restaurant (eg Son's Birthday, Marriage etc) The code for the html form is as follows: <html><body> <form action="process.php" method="post"> Recipe: <input type=text name="recipe" size=40><br/><br/> Chef: <input type="text" name="chef1" size=40><br/><br/> Restaurant: <input type="text" name="restaurant1" size=40><br/><br/> Meal: <input type=text name="meal1" size=140><br /><br/> <INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!"> <input type=reset name"reset" value="reset"> </form> </body></html> This then goes to a to the process.php as follows. <?php $conn=mysql_connect("localhost","******","******"); if (!$conn) {die('Could not connect to mysql');} $db= mysql_select_db("food",$conn); $recipe_name=mysql_query("insert into recipe values('null','$_POST[recipe]')"); $recipe_id=mysql_insert_id(); $chef_name=mysql_query("insert into chef values('null','$_POST[chef1]')"); $chef_id=mysql_insert_id(); $restaurant_name=mysql_query("insert into restaurant values('null','$_POST[restaurant1]','null','null')"); $restaurant_id=mysql_insert_id(); $meal_info=mysql_query("insert into meal values('null',$recipe_id,$creator_id,'$_POST[meal1]',$restaurant_id)"); if (!$recipe) {die('Error with recipe');} echo"Recipe Success!"; if (!$chef1) {die('Error with artist');} echo"Chef Success!"; if (!$restaurant1) {die('Error with restaurant');} echo"Restaurant Success!"; if (!$ingredient1) {die('Error with meal');} echo"Meal Success!"; ?> Obviously this is all just to test it was working so not worried about the output just yet. However, I now realise that this will only work for one set of chef/restaurant/meal - hence why I put eg 'chef1' rather than chef.. So the problem is that this works fine for one set of data, but I want to have the html form set out to accept more than one chef/restaurant/meal eg: <form action="process.php" method="post"> Recipe: <input type=text name="recipe" size=40><br/><br/> Creator: <input type="text" name="creator1" size=40><br/><br/> Restaurant: <input type="text" name="restaurant1" size=40><br/><br/> Meal: <input type=text name="meal1" size=140><br /><br/> Creator: <input type="text" name="creator2" size=40><br/><br/> Restaurant: <input type="text" name="restaurant2" size=40><br/><br/> Meal: <input type=text name="meal2" size=140><br /><br/> Creator: <input type="text" name="creator2" size=40><br/><br/> Restaurant: <input type="text" name="restaurant2" size=40><br/><br/> Meal: <input type=text name="meal2" size=140><br /><br/> Creator: <input type="text" name="creator2" size=40><br/><br/> Restaurant: <input type="text" name="restaurant2" size=40><br/><br/> Meal: <input type=text name="meal2" size=140><br /><br/> <INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!"> <input type=reset name"reset" value="reset"> </form> The idea is, you could have eaten eg lasagna at many different restaurants by different chefs at different times, or the same chef at different restaurants etc etc. The recipe will be the same for all the So what I think I need is something like a PHP loop which encorporates the mysql INSERT command I have in process.php. But how do I then name the parts of the form? eg 'chef2', 'restaurant2', 'meal2'? Do i use while... or for ($i++) and if so what how does that fit into the rest of the process.php? Any ideas ? Thanks in advance D sorry one error - the line "insert into meal values('null',$recipe_id,$creator_id,'$_POST[meal1]',$restaurant_id)" it should read $chef_id not $creator_id
×
×
  • 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.