Assistance With Code To List Data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Snatchio
Forum Newbie
Posts: 3
Joined: Tue Apr 21, 2009 12:06 pm

Assistance With Code To List Data

Post by Snatchio »

I am having an issue creating a listing of names. Currently people can sign up but then when you look at who signed up it only lists that last person who signed up and not everyone in the list. When I test it in Dreamweaver it seems to work correctly but when it is live I am having the issue. Here is the code...

<?php
mysql_select_db($database_Bunker, $Bunker);
$query_Recordset1 = "SELECT element_1_1, element_1_2 FROM ap_form_1 ORDER BY element_1_1 ASC";
$Recordset1 = mysql_query($query_Recordset1, $Bunker) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>

Then in the body...
<table border='0' align="center" cellpadding='0' cellspacing='0'>

<tr>
<th>
<form>
<?php echo $row_Recordset1['element_1_1']; ?> <?php echo $row_Recordset1['element_1_2']; ?>
</form> </th>
</tr>
</table>

Can anyone please assist?
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Assistance With Code To List Data

Post by McInfo »

The mysql_fetch_assoc() function returns only one row at a time. You need to call it multiple times to get more than one row. The most common way to do that is by using a loop, as is demonstrated in the documentation.

PHP Manual: mysql_fetch_assoc

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Mon Jun 14, 2010 4:10 pm, edited 1 time in total.
Snatchio
Forum Newbie
Posts: 3
Joined: Tue Apr 21, 2009 12:06 pm

Re: Assistance With Code To List Data

Post by Snatchio »

Thanks for the response but I am using the assoc( ). I even tested to code on the link and it is not working. Any other ideas using my code above?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Assistance With Code To List Data

Post by califdon »

Snatchio wrote:Thanks for the response but I am using the assoc( ). I even tested to code on the link and it is not working. Any other ideas using my code above?
Read what McInfo told you. You are misunderstanding what a "fetch" does. The "assoc" form of fetch has nothing whatsoever to do with how many rows are returned.
Snatchio
Forum Newbie
Posts: 3
Joined: Tue Apr 21, 2009 12:06 pm

Re: Assistance With Code To List Data

Post by Snatchio »

Thanks Jack,

In looking at my code where do you see I am going wrong?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Assistance With Code To List Data

Post by califdon »

Snatchio wrote:Thanks Jack,

In looking at my code where do you see I am going wrong?
Before you look at your code, go back and read what McInfo told you. It's all there.
Post Reply