Jump to content

format out put


proctk

Recommended Posts

Hi

Below is code that get data from a table an displays it on the page. I'm trying to figure out a way so that instead of displaying as a vertical list it displays across the screen. say three enteries side by side.  when the line is full it would move down to next row

[code=php:0]

<?

include 'db.php';

$user_id = $_SESSION['user_id'];


$child_query= ("SELECT * FROM children WHERE user_id = '$user_id'
OR Otheruser_id = '$user_id'")or die("Create table Error: ".mysql_error());

$child_result=mysql_query($child_query)or die("Create table Error: ".mysql_error());

$child_num=mysql_numrows($child_result);

mysql_close();

$i=0;

while ($i < $child_num) {
$childfistname = mysql_result($child_result,$i,"childfirstname");
$childlastname = mysql_result($child_result,$i,"childlastname");
$childdob = mysql_result($child_result,$i,"childdob");
$childsex = mysql_result($child_result,$i,"childsex");
$childage = round(dateDiff("/", date("m/d/Y", time()), $childdob)/365, 0);
$child_id = mysql_result($child_result,$i,"child_id");

echo "<p class='$childsex'><b>First Name:</b> $childfistname<br>
<b>Last Name:</b> $childlastname<br>
<b>DOB:</b> $childdob<br>
<b>Age:</b> $childage<br>
<a href='UpdateChildren.php?id=$child_id&user_id=$user_id'>Edit</a>
<a href='deleteChild.php?id=$child_id&user_id=$user_id'>Delete</a>

</p>";
$i++;

}

?>



[/code]
Link to comment
Share on other sites

I under stand what you are trying to do. Personaly I wouldn't have went about it this way. You should try a [code=php:0]mysql_fetch_assoc[/code].

Here is an example

[code=php:0]
while ($rw = mysql_fetch_assoc($child_result)) {
     echo '
<p class="' . $rw['childsex'] . '"><b>First Name:</b>' .  $rw['childfistname'] . '<br>
<b>Last Name:</b>' .  $rw['childlastname'] . '<br>
<b>DOB:</b>' . $rw['childdob'] . '<br>
<b>Age:</b>' . $rw['childage'] . '<br>
<a href="UpdateChildren.php?id=' . $rw['child_id'] . '&user_id=' . $user_id . '">Edit</a>
<a href="deleteChild.php?id=' . $rw['child_id'] . '&user_id=' . $user_id . '">Delete</a>';
}
mysql_free_result($child_result);[/code]

I wrote this on the fly so you may want to check over it. It should give you a basic idea.
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.