[SOLVED] I'm sure this has been posted before but I can't fi

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

User avatar
Lord Sauron
Forum Commoner
Posts: 85
Joined: Tue Apr 20, 2004 5:53 am
Location: Tilburg, NL

Post by Lord Sauron »

Code: Select all

<?php
while ($fetchdoggy = mysql_fetch_array($query)) { 
?>

Where is $fetchdoggy provided with a value for the second time? It's in a while loop, but I'm not sure it goes through the loop for a second time. Or...?
Antnee
Forum Newbie
Posts: 24
Joined: Fri Aug 27, 2004 7:04 am
Location: Nottingham

Post by Antnee »

OK, OK, I got it now! You couldn't have possibly known the real answer because it was a stupid mistake on my part so I'm sorry! I ended up using the wrong variable names in the script and managed to get a field in the database mixed up, I renamed it and it works perfectly! I'm baffled why it worked directly in MySQL then, I thought I copied the command into the code, obviously not!

I'm SOOO sorry! SQL is where I'm best at, not the PHP, I guess mistakes happy to newbies! Thanks for all your help guys

:oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops:

If you're interested, here is the working 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);

//-- Start of Table --//
echo '
<table width="770" border="0">
  <tr>
    <td width="20">&nbsp;</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>";
		}
	
	//-- Get the senders name from the database --//
	$msgfrom = $fetchdoggy['sent_from'];
	$sql1 = "SELECT * FROM verify WHERE username ='$msgfrom'";
	$query1 = mysql_query($sql1) or die(mysql_error());
	
	$fetchname = mysql_fetch_array($query1);
	echo '<td><font face="Tahoma, Arial" size="2">'.$fetchname['firstname'].' '.$fetchname['lastname'].'</font></td>';

	//-- 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>';
}
?>
Antnee
Forum Newbie
Posts: 24
Joined: Fri Aug 27, 2004 7:04 am
Location: Nottingham

Post by Antnee »

Just re-read through this thread, seems Lord Sauron edits all his posts afterwards? Either that or my quoting has gone haywire as none of the things I quoted seem to be in your original messages! I also seem to be answering questions that you haven't asked! :lol:

Still, thanks for your help, your advice (both of you) was much appreciated and it did help, I'm just sorry I made such a newbie mistake. Granted I've only been dealing with PHP for a couple of weeks but I should've known better, I've been using MySQL much longer!
Post Reply