Jump to content

[SOLVED] while Not Working?


Nexy

Recommended Posts

Why Hello There!  :) I don't understand why the following won't echo anything:

 

<?php

if($_GET['page'] == "PM")
{
if($_SESSION['user']) { $sql = "SELECT * FROM pm_inbox WHERE user = '".$_SESSION['user']."' ORDER BY id DESC"; }
else if($_COOKIE['user']) { $sql = "SELECT * FROM pm_inbox WHERE user = '".$_COOKIE['user']."' ORDER BY id DESC"; }

$res = mysql_query($sql) OR die(mysql_error());
$db = mysql_fetch_array($res);

if($_GET['pg'] == "inbox")
{
	while($db = mysql_fetch_array($res))
	{
		echo "<div class='pm_inbox'>
			<table>
			<tr>
				<td> </td>
				<td>From:</td>
				<td>Subject:</td>
				<td>Date:</td>
				<td>Status</td>
			</tr>
			<tr>
				<td><input type='checkbox' id='$del' name='delete[]' value='$del' style='border: 0' /></td>
				<td><a href='index.php?page=Profile&user=".$db['from']."'>" . $db['from'] . '</a></td>';
		echo		"<td><a href='index.php?page=PM&pg=read&do=".$db['id']."'>" . $db['subject'] . '</a></td>
				<td>' . $db['date'] . '</td>
				<td>' . $db['status'] . '</td>
			</tr>
			</table>
			</div>';
	}
}		
}

?>

 

I get no errors, it just doesn't display anything on the page. There is 1 entry into pm_inbox, so it should spit out something at least. Any help would be appreciated.

 

Thank You!  :)

Link to comment
https://forums.phpfreaks.com/topic/112934-solved-while-not-working/
Share on other sites

Your code contains the following line immediately after the mysql_query() statement and before the while() loop -

 

$db = mysql_fetch_array($res);

Why is that line in your code? It is fetching and discarding the first row (if any) from the result set.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.