Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.