Jump to content

For Loop Dispalying Horizonally instead of vertically


kpetsche20

Recommended Posts

I'm trying to select every invoice number from my database and have each displayed in a new row. However right now all the invoice and prices are showing up as new columns. Any help.

 

Link to output

http://floridafuelinjection.com/new/index.php

 

Code:

<?

$result = "SELECT * FROM name";
$query = mysql_query($result);
$array = mysql_fetch_array($query);

$result2 = "SELECT * FROM tax WHERE Num = ".$array['Num']." AND Memo = 'Sales Tax'";
$query2 = mysql_query($result2);

$result3 = "SELECT * FROM tax WHERE Num = ".$array['Num']." AND Memo = 'Florida State Tax'";
$query3 = mysql_query($result3);

for ($x=0; $x < mysql_num_rows($query); $x++)
{
$a = mysql_fetch_array($query);
$a['Num'];
$a['Amount'];

$b = mysql_fetch_array($query2);
$b['Amount'];

$c = mysql_fetch_array($query3);
$c['Amount'];

echo "<td>".$a['Num']."</td>
 <td>".$a['Amount']."</td>";

}

?>

You're missing the HTML tags that define table rows.

 

Change this:

echo "<td>".$a['Num']."</td>
 <td>".$a['Amount']."</td>";

 

To this:

echo "<tr><td>".$a['Num']."</td>
 <td>".$a['Amount']."</td></tr>";

 

Also:

for ($x=0; $x < mysql_num_rows($query); $x++)
{
$a = mysql_fetch_array($query);
$a['Num']; \\ this line of code does nothing
$a['Amount']; \\ this line of code does nothing

$b = mysql_fetch_array($query2);
$b['Amount']; \\ this line of code does nothing

$c = mysql_fetch_array($query3);
$c['Amount']; \\ this line of code does nothing

echo "<td>".$a['Num']."</td>
 <td>".$a['Amount']."</td>";

}

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.