Jump to content

[SOLVED] Outputting tabular data


play_

Recommended Posts

Hi all

Here's the issue i'm having.

 

I know that when we output result from a table, and we use  <td>, we can insert a new row easily by using the modulus operator to inset a <tr>.

 

But what i'm trying to do is the contrary.

 

I have this:

$sql->query("select * from users");
echo "<table>";
while($sql->fetchArray()) {
echo "<tr>";
echo "<td>$row[0]</td>";
echo "<td>$row[1]</td>";
echo "<tr>";
}

echo "</table>";

 

So it outputs 12 results.

instead of having it listed in 12 rows, i'd like to display 6. and 6 next to it, and so on.

here's an image to better portray my problem:

p.jpg

 

The only thing i can think of is storing the mysql_fetch_array() results in an array,

and then output the array because if the fetch_array_result is stored in an arryay,

i can advance the pointer to the next td.

Link to comment
Share on other sites

<?php
echo "<table>";
$sql->query("select * from users");
$result = @mysql_query($sql,$connection) or die('Ouch!');
$num=mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>$row['0']</td>";
echo "<td>$row['1']</td>";
echo "<tr>";
}
echo "</table>";
?>

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.