Jump to content

Problems with my while loop.


Namtip

Recommended Posts

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.

Link to comment
Share on other sites

$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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.