Jump to content


Photo

Outputting data in wrong places


  • Please log in to reply
2 replies to this topic

#1 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 25 March 2006 - 03:42 PM

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:

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

#2 annihilate

annihilate
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts
  • LocationUK

Posted 25 March 2006 - 04:39 PM

How about this?
<?
$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>';
?>

Personal site: NewEnigma  |  Java and JSF Discussion

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 25 March 2006 - 07:17 PM

As I said in previous topic of yours, data in tables needs to go in a cell eg <TD>data</TD>

You have rows like this

echo "<tr>OrderID</tr><br>";

where the text isn't inside a cell and the <br> isn't even in a row (and completely unnecessary)
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users