Mysql
 sql >> Database >  >> RDS >> Mysql

Elenco ordini/problema di ciclo while php

Un modo per farlo è prendere prima la riga, quindi utilizzare un ciclo do/while invece di un semplice ciclo while. In questo modo:

if (mysql_num_rows($result)) { // Valid user ID, show the form.

    /*********** I added this line ***********/
    $row = mysql_fetch_array($result, MYSQL_NUM);

    echo    '<p>Order for:<strong>' . $row[2] . ' ' . $row[3] . ' </strong> </p>
            <table border="0" style="font-size:11px;" cellspacing="1" cellpadding="5">
                <tr class="top">
                <td align="left"><b>Product</b></td>
                <td align="center"><b>Price</b></td>
                <td align="center"><b>Qty</b></td>
                </tr>';

    $bg = '#dddddd'; // Set the background color.

    /*********** I changed this from a while loop to a do-while loop ***********/
    do { // WHILE loop start

    $bg = ($bg=='#eaeced' ? '#dddddd' : '#eaeced');

    echo        '<tr bgcolor="' . $bg . '">';

    echo        '<td align="left">' . $row[15] . '</td>
            <td align="center">' . $row[13] . ' pts</td>
            <td align="center">' . $row[12] . '</td>
            </tr>';

    echo        '';         

    } while($row = mysql_fetch_array($result, MYSQL_NUM)); // end of WHILE loop