Jump to content

Archived

This topic is now archived and is closed to further replies.

brown2005

help please

Recommended Posts

$query = "SELECT * FROM table order by amount desc";

$result = mysql_query($query) or die (mysql_error());

$num = mysql_num_rows($result);

$current_price = 0;


echo "<table cellpadding=5 cellspacing=0>";

for($i=0;$i<$num;$i++)
{

$row = mysql_fetch_array($result);

if($row['amount'] != $current_price)
{

echo "<tr><td>".$row['amount']."</td></tr>".;

$current_price = $row['amount'];

}
echo "<tr><td>".$row['text']."</td></tr>".;
}

echo "</table>";



i have the above code but nothing comes out, any ideas why not please?

Share this post


Link to post
Share on other sites
Rather than using a for loop, use a while loop, then you don't need the extra $num:
[code]
<?php
$query = "SELECT * FROM table order by amount desc";
$result = mysql_query($query) or die (mysql_error());
$current_price = 0;

echo '<table cellpadding="5" cellspacing="0">';
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    if($row['amount'] != $current_price) {
        echo "
            <tr>
                <td>".$row['amount']."</td>
            </tr>";
        $current_price = $row['amount'];

    }
    echo "
        <tr>
            <td>".$row['text']."</td>
        </tr>";
}
echo "</table>";
?>
[/code]
Also, why did you have a period (.) at the end of your echo lines, after the closing quote, but before the semicolon?

Share this post


Link to post
Share on other sites

×

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.