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>";

}

?>

Link to comment
Share on other sites

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>";

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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