When i put in this code WHERE to='$username' won't work?

<?php
$connect = mysql_connect ("localhost","root","") or die (mysql_error());
mysql_select_db ("login4") or die (mysql_error());
session_start();
$_SESSION['username'];
$username = $_SESSION['username'];
$query = mysql_query("SELECT * FROM pm ORDER BY id DESC");
$message = '' ;
while ($row = mysql_fetch_array($query)){
$id = $row['id'];
$to = $row['to'];
$from = $row['from'];
$title = $row['title'];
$date = $row['date'];
$message .= "<tr><td><a href='viewpm.php?&id=".$id."'>".$title."</a><br /></td><td>".$date."<br /></td></tr>";
}
?>
<table width="100%">
<tr><td>Title</td><td>Date</td></tr>
<?php
print $message;
?>

Are you able to print the array?

It should be this way, thats why -

<?php
$connect = mysql_connect ("localhost","root","") or die (mysql_error());
mysql_select_db ("login4") or die (mysql_error());
session_start();
$_SESSION['username'];
$username = $_SESSION['username'];
$query = mysql_query("SELECT * FROM pm where to='".$username."' ORDER BY id DESC");
$message = '' ;
while ($row = mysql_fetch_array($query)){
$id = $row['id'];
$to = $row['to'];
$from = $row['from'];
$title = $row['title'];
$date = $row['date'];
$message .= "<tr><td><a href='viewpm.php?&id=".$id."'>".$title."</a><br /></td><td>".$date."<br /></td></tr>";
}
?>
<table width="100%">
<tr><td>Title</td><td>Date</td></tr>
<?php
print $message;
?>

provided your column name is 'to' in the pm table

@macneato
i can print array without where to='".$username."'
@network18
code didn't work

Thanks, pritaeas!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.