Jump to content


Photo

help please


  • Please log in to reply
2 replies to this topic

#1 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 19 May 2006 - 12:24 PM

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

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 19 May 2006 - 12:45 PM

Rather than using a for loop, use a while loop, then you don't need the extra $num:
<?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>";
?>
Also, why did you have a period (.) at the end of your echo lines, after the closing quote, but before the semicolon?

#3 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 19 May 2006 - 01:06 PM

cheers sorted.. thanks mate




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users