Jump to content

Outputting data in wrong places


OriginalSunny

Recommended Posts

The trouble i am is that all the headings for my table are being output and then the values in the columns are being output below the table. I want them in the following format:

OrderID 200 233 ...
Surname Smith Terry ...

...

The code i am using is:

[i]echo "<table cellspacing='20'>";
$connect = connect_to_db("cnn.inc");
$query = "select * from products";
$result = mysql_query($query,$connect)
or die("sql_del: ".mysql_error($connect));

echo "<tr>OrderID</tr><br>";
while($row = mysql_fetch_array($result))
{
echo "<td>";
echo($row['orderID'].'<br>');
echo"</td>";
}
echo "<tr>Surname</tr><br>";
while($row1 = mysql_fetch_array($result))
{
echo "<td>";
echo($row['surname'].'<br>');
echo"</td>";
}[/i]

I cant see what i have done wrong here. In addition to this only the values for orderID are output and the values stored for surname are not ouput unless i get rid of the array displaying the orderID's. Your help would be appreciated.
Thanks.
Link to comment
Share on other sites

How about this?
[code]<?
$connect = connect_to_db("cnn.inc");
$query = "SELECT * FROM products";
$result = mysql_query($query,$connect) or die("sql_del: ".mysql_error($connect));

echo '<table cellspacing="20">';

while($row = mysql_fetch_array($result))
{
echo '<tr><td>OrderID</td><td>'.$row['orderID'].'</td></tr>
      <tr><td>Surname</td><td>'.$row['surname'].'</td></tr>';
}

echo '</table>';
?>[/code]
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.