VickP07
10-01-2011, 04:09 AM
Hey guys,
Okay so here is what i am working on. Right now I am displaying a page with data from a Database. The data is being displayed in a table. The table columns contain the recipe name | Prep Time | Total Time | Rating
Then in each row the recipe info is displayed. I have added checkboxes before each recipe name to allow the user to select one or multiple recipes and then after clicking a submit button display additional data for that recipe or recipes.
Right now if only one recipe is selected (the checkbox) and you hit the submit button another page opens to display the additional info. This is working GREAT!!!
The problem i am having is if the user selects multiple recipes (checkboxes) the next page only shows one recipe and not the others as well.
Here is my code where I display on the home page the data along with the (checkboxes) and submit button ( THE CHECKBOXES CAN BE FOUND INSIDE THE WHILE STATEMENT):
<?php
$db = mysql_connect( "localhost","root", "temp1234");
mysql_select_db( "Peters_restaurantDB");
$sql = "
SELECT id, name, preptime, totaltime, rating
FROM recipes;
";
#test if select statement works
$result = mysql_query( $sql );
$result or die("My query ($sql) failed." );
if (mysql_num_rows ($result ) == 0 )
{
$err = true;
}
?>
<html>
<head>
<title>3342 Recipe DB</title>
</head>
<body>
<h2>Recipes in the Database...</h2><hr />
<p></p>
<h3>*Click on a recipe name to view additional info on it. </h3>
<h3>***You can also sort the recipes based on Recipe Name, Prep Time, Total time, or Rating. </h3>
<p></p>
<p></p>
<!--The code below creates the table to display all the data from the DB. The headers of all the column contain a link
to this same php file. The link allows the user to sort based on Recipe name, preptime, total time, and rating
I used a switch statement to test for what the user clicks on to sort, and then i pass the sql query.
-->
<table border="2" width ="500">
<tr>
<th><a href="PetersRecipeDB.php?sort=recipe">Recipe Name</a></th>
<th><a href="PetersRecipeDB.php?sort=prep">Prep Time</a></th>
<th><a href="PetersRecipeDB.php?sort=total">Total Time</a></th>
<th><a href="PetersRecipeDB.php?sort=rating">Rating</a></th>
</tr>
<?
$sortswitch = $_GET['sort'];
switch ($sortswitch) {
case "recipe":
$sql = "SELECT id, name, preptime, totaltime, rating FROM recipes ORDER BY name";
break;
case "prep":
$sql = "SELECT id, name, preptime, totaltime, rating FROM recipes ORDER BY preptime";
break;
case "total":
$sql = "SELECT id, name, preptime, totaltime, rating FROM recipes ORDER BY totaltime";
break;
case "rating":
$sql = "SELECT id, name, preptime, totaltime, rating FROM recipes ORDER BY rating";
break;
default:
$sql = "SELECT id, name, preptime, totaltime, rating FROM recipes";
break;
}
#test if select statement works
$result = mysql_query( $sql );
$result or die("My query ($sql) failed." );
#While statement used to pass data from DB into tables -->
while( $row = mysql_fetch_array( $result ) ) { ?>
<form name="input" action="ShoppingList.php" method="get">
<tr>
<td><a href="ShowRecipe.php?id=<?=$row['id'] ?>"><input type="checkbox" name="r_name" value="<?=$row['id']?>" /><?=$row['name'] ?></a></td>
<td><?=$row['preptime']?> mins</td>
<td><?=$row['totaltime']?> mins</td>
<td><?=$row['rating']?></td>
</tr>
<? } ?>
</table>
<input type="submit" value="Submit" />
</form>
<p>If you click the "Submit" button, the shopping list needed for t".</p>
<hr />
<p>The current date and time is: </h4></p> <code> <?php print strftime('%a') ?> <?php print strftime('%b') ?> <?php print strftime('%e') ?> <?php print strftime('%r') ?> <?php print strftime('%G')?> </code>
</body>
</html>
Here is the second page where i display my additional info based on the what checkbox the user chose:
<?
$db = mysql_connect( "localhost","root", "temp1234");
mysql_select_db( "Peters_restaurantDB");
$id = $_GET['r_name'];
$sql = "
SELECT id, name, description, preptime, totaltime, rating
FROM recipes
WHERE id = $id;
";
$sql4 = "
SELECT recipe_ingredient.amount, units_of_measure.name AS U_Name, ingredients.name
FROM recipe_ingredient
LEFT JOIN ingredients ON recipe_ingredient.ingredient_id = ingredients.id
LEFT JOIN units_of_measure ON ingredients.unit_id = units_of_measure.id
WHERE recipe_ingredient.recipe_id = $id;
";
$result = mysql_query( $sql );
$result or die("My query ($sql) failed." );
$row = mysql_fetch_array( $result);
#test if select statement works
$result4 = mysql_query( $sql4 );
$result4 or die("My query ($sql4) failed." );
?>
<html>
<head>
<title>3342 Recipe DB</title>
</head>
<body>
<h2>Shopping List</h2><hr />
<img src="http://www.bestgraph.com/gifs/gastronomie/cuisiniers/cuisiniers-03.gif" alt="Cooking" width="250" height="280" />
<p></p>
<p></p>
<table border="2" width ="700">
<tr>
<th>Recipe Name</th>
<th>Desc.</th>
<th>Prep Time</th>
<th>Total Time</th>
<th>Rating</th>
</tr>
<!--display the data for the recipe that the user clicked on -->
<tr><td><?=$row['name']?></td>
<td><?=$row['description']?></td>
<td><?=$row['preptime']?></td>
<td><?=$row['totaltime']?></td>
<td><?=$row['rating']?></td>
</tr>
</table>
<h4>Ingredients you need to buy:</h4>
<ul>
<? while ($row4 = mysql_fetch_array($result4) ) {?>
<li><?=$row4['amount']?> <?=$row4['U_Name']?> <?=$row4['name']?></li>
<? } ?>
</ul>
<!--Now this following line of code will be used to return to previous page-->
<p> </p>
<form method="get" ACTION="PetersRecipeDB.php">
<input type="submit" value="Back">
</form>
<hr />
<p>The current date and time is: </h4></p> <code> <?php print strftime('%a') ?> <?php print strftime('%b') ?> <?php print strftime('%e') ?> <?php print strftime('%r') ?> <?php print strftime('%G')?> </code>
</body>
</html>
Okay so here is what i am working on. Right now I am displaying a page with data from a Database. The data is being displayed in a table. The table columns contain the recipe name | Prep Time | Total Time | Rating
Then in each row the recipe info is displayed. I have added checkboxes before each recipe name to allow the user to select one or multiple recipes and then after clicking a submit button display additional data for that recipe or recipes.
Right now if only one recipe is selected (the checkbox) and you hit the submit button another page opens to display the additional info. This is working GREAT!!!
The problem i am having is if the user selects multiple recipes (checkboxes) the next page only shows one recipe and not the others as well.
Here is my code where I display on the home page the data along with the (checkboxes) and submit button ( THE CHECKBOXES CAN BE FOUND INSIDE THE WHILE STATEMENT):
<?php
$db = mysql_connect( "localhost","root", "temp1234");
mysql_select_db( "Peters_restaurantDB");
$sql = "
SELECT id, name, preptime, totaltime, rating
FROM recipes;
";
#test if select statement works
$result = mysql_query( $sql );
$result or die("My query ($sql) failed." );
if (mysql_num_rows ($result ) == 0 )
{
$err = true;
}
?>
<html>
<head>
<title>3342 Recipe DB</title>
</head>
<body>
<h2>Recipes in the Database...</h2><hr />
<p></p>
<h3>*Click on a recipe name to view additional info on it. </h3>
<h3>***You can also sort the recipes based on Recipe Name, Prep Time, Total time, or Rating. </h3>
<p></p>
<p></p>
<!--The code below creates the table to display all the data from the DB. The headers of all the column contain a link
to this same php file. The link allows the user to sort based on Recipe name, preptime, total time, and rating
I used a switch statement to test for what the user clicks on to sort, and then i pass the sql query.
-->
<table border="2" width ="500">
<tr>
<th><a href="PetersRecipeDB.php?sort=recipe">Recipe Name</a></th>
<th><a href="PetersRecipeDB.php?sort=prep">Prep Time</a></th>
<th><a href="PetersRecipeDB.php?sort=total">Total Time</a></th>
<th><a href="PetersRecipeDB.php?sort=rating">Rating</a></th>
</tr>
<?
$sortswitch = $_GET['sort'];
switch ($sortswitch) {
case "recipe":
$sql = "SELECT id, name, preptime, totaltime, rating FROM recipes ORDER BY name";
break;
case "prep":
$sql = "SELECT id, name, preptime, totaltime, rating FROM recipes ORDER BY preptime";
break;
case "total":
$sql = "SELECT id, name, preptime, totaltime, rating FROM recipes ORDER BY totaltime";
break;
case "rating":
$sql = "SELECT id, name, preptime, totaltime, rating FROM recipes ORDER BY rating";
break;
default:
$sql = "SELECT id, name, preptime, totaltime, rating FROM recipes";
break;
}
#test if select statement works
$result = mysql_query( $sql );
$result or die("My query ($sql) failed." );
#While statement used to pass data from DB into tables -->
while( $row = mysql_fetch_array( $result ) ) { ?>
<form name="input" action="ShoppingList.php" method="get">
<tr>
<td><a href="ShowRecipe.php?id=<?=$row['id'] ?>"><input type="checkbox" name="r_name" value="<?=$row['id']?>" /><?=$row['name'] ?></a></td>
<td><?=$row['preptime']?> mins</td>
<td><?=$row['totaltime']?> mins</td>
<td><?=$row['rating']?></td>
</tr>
<? } ?>
</table>
<input type="submit" value="Submit" />
</form>
<p>If you click the "Submit" button, the shopping list needed for t".</p>
<hr />
<p>The current date and time is: </h4></p> <code> <?php print strftime('%a') ?> <?php print strftime('%b') ?> <?php print strftime('%e') ?> <?php print strftime('%r') ?> <?php print strftime('%G')?> </code>
</body>
</html>
Here is the second page where i display my additional info based on the what checkbox the user chose:
<?
$db = mysql_connect( "localhost","root", "temp1234");
mysql_select_db( "Peters_restaurantDB");
$id = $_GET['r_name'];
$sql = "
SELECT id, name, description, preptime, totaltime, rating
FROM recipes
WHERE id = $id;
";
$sql4 = "
SELECT recipe_ingredient.amount, units_of_measure.name AS U_Name, ingredients.name
FROM recipe_ingredient
LEFT JOIN ingredients ON recipe_ingredient.ingredient_id = ingredients.id
LEFT JOIN units_of_measure ON ingredients.unit_id = units_of_measure.id
WHERE recipe_ingredient.recipe_id = $id;
";
$result = mysql_query( $sql );
$result or die("My query ($sql) failed." );
$row = mysql_fetch_array( $result);
#test if select statement works
$result4 = mysql_query( $sql4 );
$result4 or die("My query ($sql4) failed." );
?>
<html>
<head>
<title>3342 Recipe DB</title>
</head>
<body>
<h2>Shopping List</h2><hr />
<img src="http://www.bestgraph.com/gifs/gastronomie/cuisiniers/cuisiniers-03.gif" alt="Cooking" width="250" height="280" />
<p></p>
<p></p>
<table border="2" width ="700">
<tr>
<th>Recipe Name</th>
<th>Desc.</th>
<th>Prep Time</th>
<th>Total Time</th>
<th>Rating</th>
</tr>
<!--display the data for the recipe that the user clicked on -->
<tr><td><?=$row['name']?></td>
<td><?=$row['description']?></td>
<td><?=$row['preptime']?></td>
<td><?=$row['totaltime']?></td>
<td><?=$row['rating']?></td>
</tr>
</table>
<h4>Ingredients you need to buy:</h4>
<ul>
<? while ($row4 = mysql_fetch_array($result4) ) {?>
<li><?=$row4['amount']?> <?=$row4['U_Name']?> <?=$row4['name']?></li>
<? } ?>
</ul>
<!--Now this following line of code will be used to return to previous page-->
<p> </p>
<form method="get" ACTION="PetersRecipeDB.php">
<input type="submit" value="Back">
</form>
<hr />
<p>The current date and time is: </h4></p> <code> <?php print strftime('%a') ?> <?php print strftime('%b') ?> <?php print strftime('%e') ?> <?php print strftime('%r') ?> <?php print strftime('%G')?> </code>
</body>
</html>