proctk Posted September 30, 2007 Share Posted September 30, 2007 Hi I have created a form where the number of rows are displayed based on a value from a select box. Everything works excellent this far. however I need to take it to the next step where I display the information back into the form based on values in a mysql table. The values that would file these select options is stored in a column called ingredients Each ingredient group is separated by a '-' data in the table "1 Cup Milk-2 Teaspoon sugar-" The each space represents a value from the select options below. I'm thinking that I need to do a double explode some how. The first explode would be at the "-" to determine the number of rows and the second would be at each space to separate each group. Hope this makes sense any help is excellent <select name="numItems" id="numItems" onchange="this.form.submit()" class="selectBorder"> <?php $range = range(0, 20); foreach($range as $value) { $newValue = 21 - $value; echo '<option value="' . $newValue . '"'; if($newValue == $items) { echo ' selected="selected"'; } echo '>' . $value . "</option>\n"; } ?> </select> </td> </tr> <?php $numItems = $_POST['numItems']; if(isset($_POST['numItems'])) { $numItems = $_POST['numItems']; while ($numItems <= 20) { ?> <tr> <td colspan="2"> <select title="Select Measure Whole Number" name="wholeNum[]" class="selectBorder"> <option value=""></option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">0</option> <option value="10">10</option> </select> <select title="Select Measure Fraction" name="fraction[]" class="selectBorder"> <option value=""></option> <option value="1/16">1/16</option> <option value="1/8">1/8</option> <option value="1/4">1/4</option> <option value="1/2">1/2</option> <option value="3/4">3/4</option> </select> <select title="Select Measurement Type" name="meassure[]" class="selectBorder"> <option value=""></option> <option value="Teaspoon">Teaspoon</option> <option value="Tablespoon">Tablespoon</option> <option value="Cup">Cup</option> <option value="Pint">Pint</option> <option value="Quart">Quart</option> <option value="Pound">Pound</option> <option value="Pintch">Pintch</option> <option value="Ounce">Ounce</option> </select> <input name="ingredient[]" type="text" class="textBorder" /> <?php $numItems ++; ?> </td> </tr> <?php } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71216-display-results/ Share on other sites More sharing options...
proctk Posted September 30, 2007 Author Share Posted September 30, 2007 this is what I'm working with this far which is not get me any where $getIngredients = $recipe['ingredients']; $ingredients = explode('-',$getIngredients); $getIngredientsCount = sizeof($ingredients)-1; Quote Link to comment https://forums.phpfreaks.com/topic/71216-display-results/#findComment-358200 Share on other sites More sharing options...
proctk Posted September 30, 2007 Author Share Posted September 30, 2007 this shows the correct number of rows, now its to get the information into the rowss <?php $getIngredients = $recipe['ingredients']; $ingredients = explode('-',$getIngredients); $getIngredientsCount = 22-sizeof($ingredients); if(isset($_POST['numItems'])) { $numItems = $_POST['numItems']; }else{ $numItems = 22-sizeof($ingredients); } while ($numItems <= 20) { ?> Quote Link to comment https://forums.phpfreaks.com/topic/71216-display-results/#findComment-358211 Share on other sites More sharing options...
proctk Posted September 30, 2007 Author Share Posted September 30, 2007 This is what I have this far it displays the results but its not splitting at each new ingredient in the table <?php $getIngredients = $recipe['ingredients']; $ingredients = explode('-',$getIngredients); $getIngredientsCount = 22-sizeof($ingredients); if(isset($_POST['numItems'])) { $numItems = $_POST['numItems']; }else{ $numItems = 22-sizeof($ingredients); } while ($numItems <= 20) { ?> <?php $splitingredients = explode(" ",$getIngredients); $wholeNum = $splitingredients[0]; $fraction = $splitingredients[1]; $measure = $splitingredients[2]; $ingredient = ($splitingredients[3]); $newIngredient = substr($ingredient, 0, -2); print_r ($wholeNum); print_r ($fraction); print_r ($measure); print_r ($newIngredient); ?> <tr> <td colspan="2"> <select title="Select Measure Whole Number" name="wholeNum[]" class="selectBorder"> <?php foreach(array("","01","02","03","04","05","06","07","08","09","10") as $value) { echo "<option"; if($value == $wholeNum) { echo " selected='selected'"; } echo ">$value</option>\n"; } ?> </select> <select title="Select Measure Fraction" name="fraction[]" class="selectBorder"> <?php foreach(array("","1/16","1/8","1/4","1/2","3/4") as $value) { echo "<option"; if($value == $fraction) { echo " selected='selected'"; } echo ">$value</option>\n"; } ?> </select> <select title="Select Measurement Type" name="meassure[]" class="selectBorder"> <?php foreach(array("","Teaspoon","Tablespoon","Cup","Pint","Quart","Pound","Pintch","Ounce") as $value) { echo "<option"; if($value == $measure) { echo " selected='selected'"; } echo ">$value</option>\n"; } ?> </select> <input name="ingredient[]" type="text" class="textBorder" value="<?php echo $newIngredient; ?>" /> <?php $numItems ++; ?> </td> </tr> <?php } Quote Link to comment https://forums.phpfreaks.com/topic/71216-display-results/#findComment-358214 Share on other sites More sharing options...
proctk Posted October 1, 2007 Author Share Posted October 1, 2007 I'm still having a hard time with this one. here is a link to the form. http://www.familyclick.ca/recipes/editRecipe.php notice the text at the top of the form well that is what I'm trying to populate into the select option. the below is the code that creates the page <?php session_start(); // Start Session include ("../Connections/db.php"); $user_id = $_SESSION['user_id']; $title = $_POST['tile']; $category = $_POST['category']; $description = $_POST['description']; $preperation = $_POST['preperation']; $numServing = $_POST['numServing']; $yield = $_POST['yield']; $cockTime = $_POST['cockTime']; $prepTime = $_POST['prepTime']; if(isset($_POST['enterRecipe'])) { for($i = 0; $i < count($_POST['ingredient']); $i++) { $quantity = $_POST['wholeNum'][$i]; $fraction = ($_POST['fraction'][$i] !== '00') ? $_POST['fraction'][$i] : null; $measurement = ($_POST['meassure'][$i] !== '00') ? $_POST['meassure'][$i] : null; $ingrediant = $_POST['ingredient'][$i]; $stringIngrediant .= $quantity . ' ' . $fraction . ' ' . $measurement . ' ' . $ingrediant . '-'; } $query_add_recipe = ("INSERT INTO recipes (title, category, description, ingredients, preperation, servings, yield, PreparationTime, cookTime, user_id, add_date) VALUES('$title', '$category', '$description', '$stringIngrediant ', '$preperation', '$numServing', '$yield', '$prepTime', '$cockTime', '$user_id', now())"); mysql_query($query_add_recipe)or die("SQL Error: $query_add_recipe<br>" . mysql_error()); $msg .= 'Thank you for submiting your recipe'; $recipeID = mysql_insert_id(); if (is_uploaded_file($_FILES['uploadImage']['tmp_name'])) { // This is the temporary file created by PHP $uploadedfile = $HTTP_POST_FILES['uploadImage']['tmp_name']; // Create an Image from it so we can do the resize $src = imagecreatefromjpeg($uploadedfile); // Capture the original size of the uploaded image list($width,$height)=getimagesize($uploadedfile); // For our purposes, I have resized the image to be // 600 pixels wide, and maintain the original aspect // ratio. This prevents the image from being "stretched" // or "squashed". If you prefer some max width other than // 600, simply change the $newwidth variable $newwidth=200; $newheight=($height/$width)*200; $tmp=imagecreatetruecolor($newwidth,$newheight); // this line actually does the image resizing, copying from the original // image into the $tmp image imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); // now write the resized image to disk. I have assumed that you want the // resized, uploaded image file to reside in the ./images subdirectory. $filename = "../user_images/". $user_id."-"."recipe"."-".$HTTP_POST_FILES['uploadImage']['name']; imagejpeg($tmp,$filename,60); imagedestroy($src); imagedestroy($tmp); // NOTE: PHP will clean up the temp file it crated when the request // has completed. $image_size = filesize($filename); $image_name = $user_id."-"."recipe"."-".$HTTP_POST_FILES['uploadImage']['name']; $add_image = ("UPDATE recipes SET image_file = '$image_name' WHERE recipe_id = '$recipeID'"); $sql = mysql_query($add_image)or die("SQL Error: $add_image<br>" . mysql_error()); } header("Location: addRecipe.php?msg=$msg"); } else { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/twoCoumn.dwt.php" codeOutsideHTMLIsLocked="false" --> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <!-- InstanceBeginEditable name="doctitle" --> <title>Family Click | Add Recipe</title> <!-- InstanceEndEditable --> <link rel="stylesheet" href="../design/tabbler.css" type="text/css" media="screen" /> <link rel="stylesheet" href="../design/tabbler-print.css" type="text/css" media="print" /> <link rel="stylesheet" type="text/css" href="../design/layout.css" /> <link rel="stylesheet" type="text/css" href="../design/design.css" /> <script type="text/javascript" src="../design/tabber.js"></script> <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --> </head> <body> <div id="outer"> <div id="hdr"> <div id="logo-div"> <h2 id="logo"><a href="../index.php">Family Click</a></h2> <h4 id="slogan-text">Keeping Families Connected</h4> </div> <div class="headerText"> <h5> </h5> </div> </div> <div style="clear:left"></div> <div id="bar"><!-- InstanceBeginEditable name="Bar" --><?php include('../design/bar.php'); ?><!-- InstanceEndEditable --></div> <div id="bodyblock" align="right"> <div id="l-col" align="left"><!-- InstanceBeginEditable name="Left Column" --><!-- InstanceEndEditable --></div> <div id="cont"><!-- InstanceBeginEditable name="Body Content" --> <?php $msg = (isset($_GET['msg']) AND $_GET['msg']<> "") ? urldecode($_GET['msg']) : ''; if ($msg <> "") { if (get_magic_quotes_gpc()) { $msg = stripslashes($msg); } echo "<div id='alertMessage'><p style='margin-left:40px;'>$msg</p></div>"; } ?> <?php //Get recipe $recipe_id = 28/*$_GET['recipeID']*/; $query_get_recipe = ("SELECT * FROM recipes WHERE recipe_id = '$recipe_id'"); $get_recipe = mysql_query($query_get_recipe)or die ("$query_get_recipe<br />:" .mysql_error()); $recipe = mysql_fetch_assoc($get_recipe); ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="enterReceipt"> <table class="table" style="width:70%;"> <tr> <td colspan="2"><span style="font-size:12px; font-weight:bold;">Title:</span><span style="font-size:10px;"> *Required</span> <input type="text" name="tile" id="tile" class="message_to" value="<?php echo $recipe['title']; ?>" /> </td> </tr> <tr> <td colspan="2"><span style="font-size:12px; font-weight:bold;">Category:</span><span style="font-size:10px;"> *Required</span> <select name="category" id="category"> <?php $category = $recipe['category']; foreach(array("","Appetizer Recipes", "Beverage Recipes","Bread, Cake, & Pie Recipes","Breakfast Recipes","Cookie Recipes","Dessert Recipes","Main Course Recipes","Misc Recipes","Rice, Potato, & Pasta Recipes","Salad Recipes","Sandwich Recipes","Seasonal & Holiday Recipes","Side Dish Recipes","Soup Recipes","Vegetarian Recipes") as $value) { echo "<option"; if($value == $category) { echo " selected='selected'"; } echo ">$value</option>\n"; } ?> </select> </td> </tr> <tr> <td colspan="2"><span style="font-size:12px; font-weight:bold;">Number of ingredients:</span><span style="font-size:10px;"> *Required</span> <select name="numItems" id="numItems" onchange="this.form.submit()" class="selectBorder"> <?php $range = range(0, 20); foreach($range as $value) { $newValue = 21 - $value; echo '<option value="' . $newValue . '"'; if($newValue == $items) { echo ' selected="selected"'; } echo '>' . $value . "</option>\n"; } ?> </select> </td> </tr> <?php $getIngredients = $recipe['ingredients']; $ingredients = explode('-',$getIngredients); $getIngredientsCount = 22-sizeof($ingredients); foreach ($ingredients as $value){ $splitingredients = explode(" ",$value); $wholeNum = $splitingredients[0]; $fraction = $splitingredients[1]; $measure = $splitingredients[2]; $ingredient = ($splitingredients[3]); print_r ($wholeNum); print_r ($fraction); print_r ($measure); print_r ($ingredient); } if(isset($_POST['numItems'])) { $numItems = $_POST['numItems']; }else{ $numItems = 22-sizeof($ingredients); } while ($numItems <= 20) { ?> <tr> <td colspan="2"> <select title="Select Measure Whole Number" name="wholeNum[]" class="selectBorder"> <?php foreach(array("","01","02","03","04","05","06","07","08","09","10") as $value) { echo "<option"; if($value == $wholeNum) { echo " selected='selected'"; } echo ">$value</option>\n"; } ?> </select> <select title="Select Measure Fraction" name="fraction[]" class="selectBorder"> <?php foreach(array("","1/16","1/8","1/4","1/2","3/4") as $value) { echo "<option"; if($value == $fraction) { echo " selected='selected'"; } echo ">$value</option>\n"; } ?> </select> <select title="Select Measurement Type" name="meassure[]" class="selectBorder"> <?php foreach(array("","Teaspoon","Tablespoon","Cup","Pint","Quart","Pound","Pintch","Ounce") as $value) { echo "<option"; if($value == $measure) { echo " selected='selected'"; } echo ">$value</option>\n"; } ?> </select> <input name="ingredient[]" type="text" class="textBorder" value="<?php echo $newIngredient; ?>" /> <?php $numItems ++; ?> </td> </tr> <?php } ?> <tr><td colspan="2"><span style="font-size:12px; font-weight:bold;">Description:</span></td></tr> <tr> <td colspan="2"><textarea name="description" id="description" cols="45" rows="5" class="textAreaBorder"><?php echo $recipe['description']; ?></textarea></td> </tr> <tr><td colspan="2"><span style="font-size:12px; font-weight:bold;">Preperation:</span><span style="font-size:10px;"> *Required</span><a style="text-decoration:none" href="#"><img src="../images/question_mark_over.gif" width="13" height="14" /><span>One line per step, do not include step numbers.</span></a></td> </tr> <tr> <td colspan="2"><textarea name="preperation" cols="45" rows="5" class="textAreaBorder"><?php echo $recipe['preperation']; ?></textarea></td> </tr> <tr> <td style="width:25%;"> <span style="font-size:12px; font-weight:bold;">Num Servings:</span></td> <td style="width:25%;"><span style="font-size:12px; font-weight:bold;">Yield:</span></td> </tr> <tr> <td><input type="text" name="numServing" id="numServing" class="recipeSmallInput" value="<?php echo $recipe['servings']; ?>" /></td> <td><input type="text" name="yield" id="yield" class="recipeSmallInput" value="<?php echo $recipe['yield']; ?>" /></td> </tr> <tr> <td style="width:25%;"><span style="font-size:12px; font-weight:bold;">Cook Time:</span></td> <td style="width:25%;"><span style="font-size:12px; font-weight:bold;">Prep Time:</span></td> </tr> <tr> <td><input type="text" name="cockTime" id="cockTime" class="recipeSmallInput" value="<?php echo $recipe['cookTime']; ?>" /></td> <td><input type="text" name="prepTime" id="prepTime" class="recipeSmallInput" value="<?php echo $recipe['PreparationTime']; ?>" /> </td> </tr> <tr> <td colspan="2"><span style="font-size:12px; font-weight:bold;">Add Image of Prepared Dish:</span> <input style="width:150px;" type="file" name="uploadImage" id="uploadImage" /></td> </tr> <tr> <td colspan="2"> <label> <input type="submit" name="enterRecipe" id="button" value="Enter Recipe" /> <input type="reset" name="reset" id="reset" value="Reset" /> </label> </td> </tr> </table> <label></label> </form> <?php } ?><!-- InstanceEndEditable --></div> </div> <div id="ftr"><!-- InstanceBeginEditable name="Footer" --><?php include('../design/ftr.php'); ?> <!-- InstanceEndEditable --></div> </div> </body> <!-- InstanceEnd --></html> Quote Link to comment https://forums.phpfreaks.com/topic/71216-display-results/#findComment-358770 Share on other sites More sharing options...
proctk Posted October 13, 2007 Author Share Posted October 13, 2007 HI all, I'm still trying to figure this one out any ideas Quote Link to comment https://forums.phpfreaks.com/topic/71216-display-results/#findComment-368279 Share on other sites More sharing options...
darkfreaks Posted October 13, 2007 Share Posted October 13, 2007 whats the problem first off? Quote Link to comment https://forums.phpfreaks.com/topic/71216-display-results/#findComment-368291 Share on other sites More sharing options...
proctk Posted October 13, 2007 Author Share Posted October 13, 2007 I can't get it to populate the selection options with the information found in the table see the link and location of the text at the top of the form, its suposed to add a new row for each record set Quote Link to comment https://forums.phpfreaks.com/topic/71216-display-results/#findComment-368342 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.