[SOLVED] I'm sure this has been posted before but I can't fi
Posted: Mon Aug 30, 2004 12:39 pm
Getting data from multiple tables
Ok, simply I am trying to get data from two different tables but I can only get it from one. I am using PHP4 and MySQL (Not sure the version)
Here is my code:Any takers on why it's not working? I'm sure it's really obvious to you guys but I'm no expert and I've never pulled info from more than one table at a time
Thanks guys!
Ok, simply I am trying to get data from two different tables but I can only get it from one. I am using PHP4 and MySQL (Not sure the version)
Here is my code:
Code: Select all
<?php
session_start();
header("Cache-control: private"); // LEAVE ME IN ELSE YOU'LL GET PROBLEMS IN IE!!! //
//-- Include the connection script --//
include ("../action/connect.php");
//-- Start setting variables --//
//-- Message Counter --//
$msgs = "0";
//-- Fetch Message queries --//
$sql = "SELECT * FROM message WHERE send_to ='".$username."' ORDER by new DESC, important DESC, realdate DESC, datesent DESC";
$query = mysql_query($sql);
//-- Fetch Username queries --//
$sql1 = "SELECT * FROM verify WHERE username ='".$from."'";
$query1 = mysql_query($sql1);
$fetchname = mysql_fetch_array($query1);
//-- Start of Table --//
echo '
<table width="770" border="0">
<tr>
<td width="20"> </td>
<td width="150"><font face="Tahoma, Arial" size="3"><b>From</b></font></td>
<td width="250"><font face="Tahoma, Arial" size="3"><b>Date Sent</b></font></td>
<td width="350"><font face="Tahoma, Arial" size="3"><b>Subject</b></font></td>
</tr>
<tr>';
//-- Start fetching messages from Database --//
while ($fetchdoggy = mysql_fetch_array($query)) {
echo '<td><font face="Tahoma, Arial" size="2">';
//-- Count messages as you go --//
$msgs = $msgs + "1";
//-- Label if the message is new or not --//
if ($fetchdoggy['new'] == "1") {
echo "NEW</font></td>";
} else {
echo "</font></td>";
}
//-- THIS IS THE PROBLEM BIT, IGNORE TRYING TO FIX THE REST!!! --//
//-- Get the senders name from the database --//
$from = $fetchdoggy['from'];
echo '<td><font face="Tahoma, Arial" size="2">'.$fetchname['firstname'].' '.$fetchname['lastname'].'</font></td>';
//-- END OF PROBLEM CODE --//
//-- Get the date the message was sent --//
echo '<td><font face="Tahoma, Arial" size="2">'.$fetchdoggy['datesent'].'</font></td>';
//-- Get the subject and create a link to open the message --//
echo '<td><font face="Tahoma, Arial" size="2"><a style="text-decoration: none" href="readmail.php?msgid='.$fetchdoggy['id'].'" target="_top">';
//-- Highlight message subject if is important --//
if ($fetchdoggy['important'] == "1") {
echo '<font color=#CC0000>'.$fetchdoggy['subject'].'</font></a></font></td></tr>';
} else {
echo $fetchdoggy['subject'].'</a></font></td></tr>';
}
}
//-- End of table --//
echo "</table>";
//-- If there are no messages to display, show a message saying so --//
if ($msgs == "0") {
echo '<div align="center"><font face="Tahoma, Arial" size="3"><b><br/><br/><br/><br/><br/><br/>There are no messages in your inbox</b></font></div>';
}
?>Thanks guys!