Jump to content

Echoing a Table in PHP


dean7

Recommended Posts

Hi all, I have this code which is suppose to display everymessage that the User has, but when im trying to display the messages its displaying them all in different tables..

 

Im trying to get it so it will be like:

 

inbox

------------------

subject | From

subject | username

 

Read Messages

------------------

subject | From

subject | username

 

So two tables which one displays the messages which havent been read while the other does

 

<?php
session_start();
include "includes/config.php";
include "includes/functions.php";
logincheck();
ini_set ('display_errors', 1);
error_reporting (E_ALL);
$user=$_SESSION['username'];

// Grab whats needed...
$all_msgs = mysql_query("SELECT `id` FROM `inbox` WHERE `to`='$user' ORDER BY `id` DESC") or die("Error on line 9 - " . mysql_error());
$get_msg = mysql_query("SELECT * FROM `inbox` WHERE `to`='$user' ORDER BY `id` DESC") or die("Error on line 10 - " . mysql_error());
$msg_num = mysql_num_rows($all_msgs);
// lets echo the subject + A linking to the message...

    echo '<table width="50%" cellpadding="0" align="center" cellspacing="0" border="1" class="table">
        <tr>
            <td class="header" algin="center" colspan="2">Inbox</td>
        </tr>
	<tr>
		<td class="omg" align="center">Subject</td><td align="center" class="omg">From</td>
	</tr>';

for($number = 1; $number <= $msg_num; $number++)
{
    $line = mysql_fetch_array($get_msg);
 //if the message is not read...

 if($line['read'] == 0){

    echo '<tr>    
           <td width="50%" align="center"><a href="rmessage.php?messageid=' . $line['id'] . '">' . $line['title'] . '</a>(New)</td><td width="50%" align="center"><a href="profile.php?viewuser=' . $line['from'] . '">' . $line['from'] . '</a></td>
	</tr></table>
	<br />
	<br />'; 
}else{ 
// If message is read...
echo '<br /><table width="50%" cellpadding="0" align="center" cellspacing="0" border="1" class="table">
        <tr>
            <td class="header" algin="center" colspan="2">Messages Read</td>
        </tr>
	<tr>
		<td class="omg" align="center">Subject</td><td class="omg" align="center">From</td></td>
	</tr>	
	<tr>
		<td width="50%" align="center"><a href="rmessage.php?messageid=' . $line['id'] . '">' . $line['title'] . '</a></td><td width="50%" align="center"><a href="profile.php?viewuser=' . $line['from'] . '">' . $line['from'] . '</td>
        </tr></table>';
}}
?>

 

Anyone see a way I can sort it so it don't show a table for every message they have?

 

Thanks for any help given :)

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.