Re: Filter Data based on Username



<?php
$username_xtr2 = "-1";
if (isset($_POST['username'])) {
$username_xtr2 = (get_magic_quotes_gpc()) ? $_POST['username'] :
addslashes($_POST['username']);
}

mysql_select_db($database_xcomm, $xcomm);
$query_xtr2 = sprintf("SELECT * FROM xtr WHERE %s = '%s'",
$username_xtr2,$username_xtr2);
$xtr2 = mysql_query($query_xtr2, $xcomm) or die(mysql_error());
$row_xtr2 = mysql_fetch_assoc($xtr2);
$totalRows_xtr2 = mysql_num_rows($xtr2);
?>

//dynamic text:

<?php echo $row_xtr2['firstname']; ?>

You only call mysql_fetch_assoc() once, hence you only get the first
row. If you call mysql_fetch_assoc() again you'll get the next row.
So, if you want to find the one where id = 7 or something, you could do
this:

while(($row_xtr2 = mysql_fetch_assoc($xtr2)) !== false) {
if($row_xtr2['id'] == 7) {
echo $row_xtr2['firstname'];
break;
}
}

.


Quantcast