piznac Posted August 22, 2007 Share Posted August 22, 2007 Ok,.. I always get confused when it comes to this. Im pulling some data from a db with the intentions of letting the user edit it. I start with a do while loop to get the data. Inside that is a listing of "artwork" chossen for each line. What I need to do is show (in a drop down box) the list of all available artwork (in another table in db) to the customer. Or all the ones they have uploaded so they can change which one goes with which. I have tried a while loop inside the main while loop and a for each loop inside the main loop. Niether has worked for me,.. possibly becuase it has me confused,.. anywho here is the code,.. any help would be appreciated. Oh and Im not getting an error,.. it is simply not displaying the rest of the items. <?php //function to change items ordered(form) function ch_or_items_form($num){ //query for single location details $mo_details_query = "SELECT * FROM `c_or_details` WHERE `num` = '$num'"; $mo_details = mysql_query($mo_details_query) or die ("c_order_details error:" . mysql_error()); $mo_details_row = mysql_fetch_assoc($mo_details); $mo_details_row_num = mysql_num_rows($mo_details); //query for multi location details if($mo_details_row_num == 0){ $m_details_query = "SELECT * FROM `loc_logo_ex` WHERE `num` = '$num'"; $m_details = mysql_query($m_details_query) or die ("c_order_details error:" . mysql_error()); $m_details_row = mysql_fetch_assoc($m_details); $m_details_row_num = mysql_num_rows($m_details); } /*query for artwork $im_query = "SELECT * FROM `or_logo` WHERE `num` = '$num' GROUP BY `path`"; $im = mysql_query($im_query) or die ("Images error:" . mysql_error()); $im_rows = mysql_fetch_assoc($im); $im_rows_num = mysql_num_rows($im);*/ //query for artwork $sql_art = "SELECT * FROM `or_logo` WHERE `c_name` = '$_SESSION[MM_Username]' GROUP BY `path` ORDER BY `num` DESC"; $art = mysql_query($sql_art) or die ("Artwork error:" . mysql_error()); $art_row = mysql_fetch_assoc($art); $totalRows_art = mysql_num_rows($art); echo "<form action=\"confirm.php?action=&num=$num\" method=\"POST\" name=\"items_form\">"; echo "<table align=\"center\" class=\"log\" bgcolor=\"E5E5E5\" cellspacing=\"0\">"; //figure out which type we have,. multi or not if($mo_details_row_num != 0){ echo "<tr><td><b> Item#</b></td><td><b>Item Description</b></td><td><b>Quanity</b></td><td><b>Size</b></td><td><b>Emb Location</b></td><td><b>ArtWork</b></td></tr>"; do{ echo "<tr><td> <input type=\"text\" size=\"5\" name=\"num[]\" value=\"$mo_details_row[item_num]\" /></td> <td><input type=\"text\" size=\"15\" name=\"desc[]\" value=\"$mo_details_row[item_desc]\" /></td> <td><input type=\"text\" size=\"5\" name=\"qty[]\" value=\"$mo_details_row[item_qty]\"</td> <td><select size=\"1\" name=\"size[]\"> <option selected=\"selected\">$mo_details_row[size]</option> <option>ONE SIZE</option> <option>XS</option> <option>S</option> <option>M</option> <option>L</option> <option>XL</option> <option>2XL</option> <option>3XL</option> <option>4XL</option> <option>1X</option> <option>2X</option> <option>3X</option> <option>4X</option> <option>5X</option> <option>6X</option> <option>YXS</option> <option>YS</option> <option>YM</option> <option>YL</option> <option>YXL</option> <option>6M</option> <option>12M</option> <option>T2</option> <option>T4</option> <option>XXL</option> <option>XXXL</option> <option>XXXXL</option> <option>XXXXXL</option> <option>XXXXXXL</option> <option>OSFM</option> <option>OSFA</option> <option>1XL</option> <option>SMALL</option> <option>MEDIUM</option> <option>LARGE</option> <option>5XL</option> <option>0</option> <option>0-6M</option> <option>12-18M</option> <option>18-24M</option> <option>2</option> <option>2T</option> <option>3-6M</option> <option>3T</option> <option>4</option> <option>4T</option> <option>6</option> <option>6-12M</option> <option>8</option> <option>L-XL</option> <option>Plus2X</option> <option>Plus3X</option> <option>Plus4X</option> <option>S-M</option> <option>XXS</option> <option>10-12Y</option> <option>14-16</option> <option>18-20</option> <option>18M</option> <option>24M</option> <option>2XG</option> <option>5-6Y</option> <option>6-8Y</option> <option>7Y</option> <option>AO</option> <option>2XL-3XL</option> <option>6XL</option> <option>Plus1X</option> <option>W27</option> <option>W28</option> <option>W29</option> <option>W30</option> <option>W31</option> <option>W32</option> <option>W33</option> <option>W34</option> <option>W35</option> <option>W36</option> <option>W37</option> <option>W38</option> <option>W40</option> <option>W42</option> <option>W44</option> <option>W46</option> <option>W48</option> <option>W50</option> <option>W52</option> <option>W54</option> <option>W56</option> <option>W58</option> <option>W60</option> </select></td> <td><select size=\"1\" name=\"emb_loc1[]\"> <option selected=\"selected\">$mo_details_row[emb_loc1] </option> <option>Left Chest</option> <option>Right Chest</option> <option>Center Chest</option> <option>Left Sleeve</option> <option>Right Sleeve</option> <option>Left Cuff(Long Sleeve)</option> <option>Right Cuff(Long SLeeve)</option> <option>Shirt Back Full</option> <option>Shirt Back Yoke</option> <option>Front Hat</option> <option>Hat Back</option> <option>Left Side Hat</option> <option>Right Side Hat</option> <option>Bag Center Flap</option> <option>Bag Center Of Pocket</option> <option>End Of Bag</option> <option>Center</option> <option>Top Center</option> <option>Top Left</option> <option>Top Right</option> <option>Bottom Center</option> <option>Bottom Left</option> <option>Bottom Right</option> <option>Other(See Work Order)</option> </select></td> <td>"; echo "<select size=\"1\" name=\"art[]\">"; echo "<option selected=\"selected\">$mo_details_row[artwork]</option>"; $art = implode(",",$art_row[path]); do { foreach($art as $key => $value){ $filename = explode("/", $art_row[path]); $short_filename = substr($filename[4],0,10); echo "<option>$short_filename</option>"; } }while ($art_row = mysql_fetch_assoc($art)); echo "</selected>"; echo "</td></tr>"; }while ($mo_details_row = mysql_fetch_assoc($mo_details)); echo "</table>"; echo "</form>"; } } ?> BTW this final loop is what Im refering to,.. the "foreach": <?php echo "<select size=\"1\" name=\"art[]\">"; echo "<option selected=\"selected\">$mo_details_row[artwork]</option>"; $art = implode(",",$art_row[path]); do { foreach($art as $key => $value){ $filename = explode("/", $art_row[path]); $short_filename = substr($filename[4],0,10); echo "<option>$short_filename</option>"; } }while ($art_row = mysql_fetch_assoc($art)); echo "</selected>"; echo "</td></tr>"; }while ($mo_details_row = mysql_fetch_assoc($mo_details)); echo "</table>"; echo "</form>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/66169-loop-confusion/ Share on other sites More sharing options...
piznac Posted August 22, 2007 Author Share Posted August 22, 2007 If I leave out the foreach loop I can get it to work for the first row,.. but not the others. This why I included the foreach,.. but I dont think Im using it properly. Quote Link to comment https://forums.phpfreaks.com/topic/66169-loop-confusion/#findComment-331049 Share on other sites More sharing options...
piznac Posted August 22, 2007 Author Share Posted August 22, 2007 anyone?.. Or am I being to confusing? Quote Link to comment https://forums.phpfreaks.com/topic/66169-loop-confusion/#findComment-331090 Share on other sites More sharing options...
piznac Posted August 22, 2007 Author Share Posted August 22, 2007 Ok let me try to simplify this,.. Im grabbing a query from my database to show orders taken,.. it will look something like this: row 1 - 1.name 2.blah 3.blah etc,... 6.(this has to be a drop down,.. populated from another table) row 2 - 1.name 2.blah 3.blah etc,... 6.(this has to be a drop down,.. populated from another table) etc...... In theory what I need to do is a while loop inside a while loop: <?php while ($mo_details_row = mysql_fetch_assoc($mo_details)){ echo "1.$mo_details_row[1]"; echo "2.$mo_details_row[2]"; echo "3.$mo_details_row[3]"; etc,.. echo "6. <select size=\"1\" name=\"art[]\">"; while ($art_row = mysql_fetch_assoc($art)){ <option>$art_row[path]</option> } echo "</select>"; } ?> Does that make more sense? I hope so cause Im stuck (BTW if I have bumped this too many times,.. sorry Quote Link to comment https://forums.phpfreaks.com/topic/66169-loop-confusion/#findComment-331166 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.