Jump to content

php mysql is only listing one row at a time please help!!


jamesxg1

Recommended Posts

here's the code:

 

$query2 = mysql_query("SELECT * from users where username = '$username' order by firstname");

        while ($row = mysql_fetch_assoc($query2)) {

                          $firstname = $row['firstname'];
                          $lastname = $row['lastname'];
}
        ?>
<P ALIGN=CENTER><h3>Friend Requests:</h3></P>
  	<center>
  	<table border="1" width="400" cellpadding="5" bgcolor="#ffffff" bordercolor="#808080" style="border-collapse: collapse;" id="">
  	<tr> 
  		<td align="center" width="" bgcolor="#c0c0c0"><?php print $firstname ?> <?php print $lastname ?></td>
  		<td align="center" width="" bgcolor="#c0c0c0"><a href='../friends/Accept.php?username=<?php print $username ?>'>Accept</a> | <a href='../friends/Decline.php?username=<?php print $username ?>'>Decline</a></td>

  	</tr>

 

that isnt the whole code but thats the part i need working,

 

i need it to list everything from the query and not just one at a time but i wont any ideas anyone ?

you need to include the html in your while loop like

<?php
$query2 = mysql_query("SELECT * from users where username = '$username' order by firstname");

        while ($row = mysql_fetch_assoc($query2)) {

                          $firstname = $row['firstname'];
                          $lastname = $row['lastname'];
//}
        ?>
<P ALIGN=CENTER><h3>Friend Requests:</h3></P>
  	<center>
  	<table border="1" width="400" cellpadding="5" bgcolor="#ffffff" bordercolor="#808080" style="border-collapse: collapse;" id="">
  	<tr> 
  		<td align="center" width="" bgcolor="#c0c0c0"><?php print $firstname ?> <?php print $lastname ?></td>
  		<td align="center" width="" bgcolor="#c0c0c0"><a href='../friends/Accept.php?username=<?php print $username ?>'>Accept</a> | <a href='../friends/Decline.php?username=<?php print $username ?>'>Decline</a></td>

  	</tr>
<?php
}
?>

 

Scott.

you need to include the html in your while loop like

<?php
$query2 = mysql_query("SELECT * from users where username = '$username' order by firstname");

        while ($row = mysql_fetch_assoc($query2)) {

                          $firstname = $row['firstname'];
                          $lastname = $row['lastname'];
//}
        ?>
<P ALIGN=CENTER><h3>Friend Requests:</h3></P>
  	<center>
  	<table border="1" width="400" cellpadding="5" bgcolor="#ffffff" bordercolor="#808080" style="border-collapse: collapse;" id="">
  	<tr> 
  		<td align="center" width="" bgcolor="#c0c0c0"><?php print $firstname ?> <?php print $lastname ?></td>
  		<td align="center" width="" bgcolor="#c0c0c0"><a href='../friends/Accept.php?username=<?php print $username ?>'>Accept</a> | <a href='../friends/Decline.php?username=<?php print $username ?>'>Decline</a></td>

  	</tr>
<?php
}
?>

 

Scott.

 

Hiya Scott,

 

Do you mean i have to put this code into a external php and include it in the page i need it to work ?,

 

Or is the code that you posted above the code i should use ?,

 

Thanks mate.

replace the code you posted with the code i posted

you may need to remove the opening <?php tag

 

Scott.

 

iv got a error :S,

 

Parse error: syntax error, unexpected $end in Pending.php on line 37

 

<?php session_start(); 

require("../db/db.php"); //include database file
require("../db/config.php"); //include configuration file
require("../db/util.php");
require("../db/settings.php");

isloggedin();
accessneeded("C");

        $User_to = $_SESSION['username'];
        $Status = "Pending";

        $query = mysql_query("SELECT * from friend where friend.User_to = '$User_to' and friend.Status = '$Status'");

        while ($row = mysql_fetch_assoc($query)) {

                          $username = $row['User_fr'];
}

$query2 = mysql_query("SELECT * from users where username = '$username' order by firstname");

while ($row = mysql_fetch_assoc($query2)) {

$firstname = $row['firstname'];
$lastname = $row['lastname'];
//}
?>
<P ALIGN=CENTER><h3>Friend Requests:</h3></P>
<center>
<table border="1" width="400" cellpadding="5" bgcolor="#ffffff" bordercolor="#808080" style="border-collapse: collapse;" id="">
<tr> 
<td align="center" width="" bgcolor="#c0c0c0"><?php print $firstname ?> <?php print $lastname ?></td>
<td align="center" width="" bgcolor="#c0c0c0"><a href='../friends/Accept.php?username=<?php print $username ?>'>Accept</a> | <a href='../friends/Decline.php?username=<?php print $username ?>'>Decline</a></td>

</tr>

 

thats the whole code so u know what the error is :),

 

Thanks Scott.

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.