Jump to content

Loop question


TimUSA

Recommended Posts

I created this code for SMF and TP so there is no mysql_connect as it is not needed.

 

Just an example of what i am trying to do here. I have this code which pulls a list of names from a database in a selection box. I need to repeat it a designated number of times. What I am getting is the list in one box but not the rest. Any ideas?

$query = "SELECT `memberName` FROM `smf_members` WHERE `ID_GROUP` IN (1, 9, 10, 11, 13) ORDER BY `memberName`;";
$result = mysql_query($query);
$times = 13;
$x = 0;

while ($x < $times) {
echo'
<SELECT id="name" name="name[ ]" style="WIDTH: 160px" value ="';
echo '" />';

if(mysql_num_rows($result)) {
// we have at least one user, so show all users as options in select form
while($row = mysql_fetch_row($result))
{
print("<option value=\"$row[0]\">$row[0]</option>");
}
} else {
print("<option value=\"\">No users created yet</option>");
}
++$x;
}

Link to comment
https://forums.phpfreaks.com/topic/83388-loop-question/
Share on other sites

Once you have looped through the return results once any further fetch_row() calls return false as there is no more data to read.

 

You need to rewind to the beginning of the resultset each time with

 

mysql_data_seek($result, 0)

Link to comment
https://forums.phpfreaks.com/topic/83388-loop-question/#findComment-424397
Share on other sites

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.