Skip to main content
Participating Frequently
August 1, 2009
Question

Displaying database entry's after using a loop

  • August 1, 2009
  • 1 reply
  • 2469 views

Hello. I am getting entry's from a database for one person after they login. I displayed multiple entries that are specific to them using a do while loop. However, the problem I am having is after I have displayed the entries, I cannot display anymore entries later on in the page.

I'm assinging the variable from the database using:
$getTv_type = mysql_fetch_assoc($getTv_type);

The loop uses:
do {
} while ($getTv_type = mysql_fetch_assoc($getTv_type))

I want to display it later again, for example by using:
echo $getTv_type['brand_name'];

I can't get the entries to display again. Any ideas?
Thanks

This topic has been closed for replies.

1 reply

David_Powers
Inspiring
August 2, 2009

After you have looped through a database result, you need to reset it with mysql_data_seek().

mysql_data_seek($recordsetName, 0);

Dreamweaver will not let you create a second repeat region with the same recordset. You need to hand-code the second loop.

kelsey720Author
Participating Frequently
August 2, 2009

Thanks for the reply. I tried using that function but it didn't work for me. I must be doing something wrong. However, I tried the following and it worked. I'm not sure if its the proper way to do it though

The loop uses:

do {

} while ($row_getTv_type = mysql_fetch_assoc($getTv_type));

To display the recordset later on I begin it with:

$getTv_type2 = mysql_query($query_getTv_type, $mydatabase) or die(mysql_error());

$row_getTv_type2 = mysql_fetch_assoc($getTv_type2);

echo $row_getTv_type2['brand_name'];

Is there a better way or is this OK?

Thanks

David_Powers
Inspiring
August 3, 2009

Basically, what you're doing is running the SQL query again. This should work:

// first loop through recordset

do {

} while ($row_getTv_type = mysql_fetch_assoc($getTv_type));

// reset database result

mysql_data_seek($getTv_type, 0);

// get first result

$row_getTv_type = mysql_fetch_assoc($getTv_type);

// you can now access the first row again,

// and use another do... while loop