Jump to content


Photo

format out put


  • Please log in to reply
1 reply to this topic

#1 proctk

proctk
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts

Posted 06 August 2006 - 11:38 PM

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


<?

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

}

?>
	




#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 07 August 2006 - 12:16 AM

I under stand what you are trying to do. Personaly I wouldn't have went about it this way. You should try a
mysql_fetch_assoc
.

Here is an example

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

I wrote this on the fly so you may want to check over it. It should give you a basic idea.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users