Jump to content

help please


brown2005

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?
Link to comment
https://forums.phpfreaks.com/topic/9996-help-please/
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?
Link to comment
https://forums.phpfreaks.com/topic/9996-help-please/#findComment-37137
Share on other sites

Archived

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

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