...

View Full Version : Resolved How to keep messages in one table?



elitis
07-23-2011, 04:12 AM
Having trouble keeping messages in one table. I understand why its printing multiple tables but do not know how to keep all the messages in one table.


<?php
$getmessages = mysql_query("SELECT * FROM `messages` where `to`='".$_SESSION['userid']."'");
while($message = mysql_fetch_array($getmessages))
{
$getname = mysql_query("SELECT * FROM `users` where `userid`='".$message['from']."'");
while($name = mysql_fetch_array($getname))
{
if ($_GET['message'] == "")
{
print "
<div class='bubble'>
<table border='1'>
<tr>
<th>Mark</th>
<th>Subject</th>
<th>From</th>
<th>Date</th>
</tr>
<tr>
<td><input type='checkbox' name='mark' value='Mark' /></td>
<td><a href=\"/home/messages?message={$message['id']}\">{$message['title']}</a></td>
<td>{$name['full_name']}</td>
<td>{$message['created']}</td>
<td>{$message['category']}</td>
</tr>
</table>
</div>";
}

Truffle
07-23-2011, 04:43 AM
try moving



<div class='bubble'>
<table border='1'>
<tr>
<th>Mark</th>
<th>Subject</th>
<th>From</th>
<th>Date</th>
</tr>


out of the while loop and up to the top of the script.

Leave


<tr>
<td><input type='checkbox' name='mark' value='Mark' /></td>
<td><a href=\"/home/messages?message={$message['id']}\">{$message['title']}</a></td>
<td>{$name['full_name']}</td>
<td>{$message['created']}</td>
<td>{$message['category']}</td>
</tr>


Inside the while loop where it's at since it's the only code that needs repeating

And then move



</table>
</div>


out of the while loop and to the bottom of the script.

That should create one table row for each recordset you get from your query.
Try that and then I also suggest looking up MySQL joins for what you are trying to do. This way you get all the data fields from multiple tables in one mysql query instead of having nested while loops.

elitis
07-23-2011, 06:39 PM
try moving



<div class='bubble'>
<table border='1'>
<tr>
<th>Mark</th>
<th>Subject</th>
<th>From</th>
<th>Date</th>
</tr>


out of the while loop and up to the top of the script.

Leave


<tr>
<td><input type='checkbox' name='mark' value='Mark' /></td>
<td><a href=\"/home/messages?message={$message['id']}\">{$message['title']}</a></td>
<td>{$name['full_name']}</td>
<td>{$message['created']}</td>
<td>{$message['category']}</td>
</tr>


Inside the while loop where it's at since it's the only code that needs repeating

And then move



</table>
</div>


out of the while loop and to the bottom of the script.

That should create one table row for each recordset you get from your query.
Try that and then I also suggest looking up MySQL joins for what you are trying to do. This way you get all the data fields from multiple tables in one mysql query instead of having nested while loops.

thanks. :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum