Namtip Posted October 8, 2010 Share Posted October 8, 2010 Problem: I want to echo out every order_id and the rest of the information in that row that is relevant to the name_id. What actually happens: Variables are can be eachoed out and they have the correct values. but the while loop does not echo anything out. What I've tried: I've tried extracting the '$row2'. I've tried using mysql_fetch_assoc instead of array. There is another select table join above with a different echo while loop that works. $query2 = 'SELECT d.name_id, d.order_qty, d.product_code, p.title, c.order_id, c.shipping_first_name, c.shipping_last_name, c.shipping_address_1, c.shipping_city, c.shipping_state, c.shipping_zip_code, c.shipping_email FROM ecomm_order_details d LEFT JOIN ecomm_products p ON d.product_code = p.product_code LEFT JOIN ecomm_orders c ON d.buyer_id = c.customer_id WHERE d.name_id = "' . mysql_real_escape_string($_SESSION['name_id']) . '"'; $result2 = mysql_query($query2, $db) or die(mysql_error());$row2 = mysql_fetch_array($result2);echo $row2['shipping_first_name'];$odd = true;while ($row2 = mysql_fetch_array($result2)) { echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">'; $odd = !$odd; echo '<td style="text-align: center; width:100px;">' . $row2['title'] . ' <table> <tr> <th colspan="2">Shipping Information</th> </tr><tr> <td>First Name:</td> <td>' . $row2['shipping_first_name']. '</td> </tr><tr> <td>Last Name:</td> <td>' . $row2['shipping_last_name']. '</td> </tr><tr> <td>Billing Address:</td> <td>' . $row2['shipping_address_1']. '</td> </tr><tr> <td>City:</td> <td>' . $row2['shipping_city']. '</td> </tr><tr> <td>State:</td> <td>' . $row2['shipping_state'] . '</td> </tr><tr> <td>Zip Code:</td> <td>' . $row2['shipping_zip_code'] . '</td> </tr><tr> <td>Email Address:</td> <td>' . $row2['shipping_email'] . '</td> </tr> </table> </tr>';} Just wanted to get your opinions on what I've done, and possible problems. Any help appreciated. Quote Link to comment Share on other sites More sharing options...
Pawn Posted October 8, 2010 Share Posted October 8, 2010 The only thing that jumps out is that because you're calling mysql_fetch_array() twice, the while loop won't do anything unless two or more rows are returned by the query. Quote Link to comment Share on other sites More sharing options...
Namtip Posted October 8, 2010 Author Share Posted October 8, 2010 You're spot on! I typed in another order then checked the the loop and it shows one row (instead of two). PHP is easy but it has so many quirks to it. I'm to mess around with it. See if I can get it to work with that in mind. Quote Link to comment Share on other sites More sharing options...
Namtip Posted October 8, 2010 Author Share Posted October 8, 2010 $query2 = 'SELECT d.name_id, d.order_qty, d.product_code, p.title, c.order_id, c.shipping_first_name, c.shipping_last_name, c.shipping_address_1, c.shipping_city, c.shipping_state, c.shipping_zip_code, c.shipping_email FROM ecomm_order_details d LEFT JOIN ecomm_products p ON d.product_code = p.product_code LEFT JOIN ecomm_orders c ON d.buyer_id = c.customer_id WHERE d.name_id = "' . mysql_real_escape_string($_SESSION['name_id']) . '"'; $result2 = mysql_query($query2, $db) or die(mysql_error()); $odd = true; while ($row2 = mysql_fetch_array($result2)) { echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">'; $odd = !$odd; echo '<td style="text-align: center; width:100px;">' . $row2['title'] . ' <table> <tr> <th colspan="2">Shipping Information</th> </tr><tr> <td>First Name:</td> <td>' . $row2['shipping_first_name']. '</td> </tr><tr> <td>Last Name:</td> <td>' . $row2['shipping_last_name']. '</td> </tr><tr> <td>Billing Address:</td> <td>' . $row2['shipping_address_1']. '</td> </tr><tr> <td>City:</td> <td>' . $row2['shipping_city']. '</td> </tr><tr> <td>State:</td> <td>' . $row2['shipping_state'] . '</td> </tr><tr> <td>Zip Code:</td> <td>' . $row2['shipping_zip_code'] . '</td> </tr><tr> <td>Email Address:</td> <td>' . $row2['shipping_email'] . '</td> </tr> </table> </tr>'; } Yup, thanks so much, above is the fixed code. Quote Link to comment 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.