Jump to content

Recall query several times


Julian

Recommended Posts

Hi guys.

Maybe this is a silly question but here's goes:

I have a form that calls info from the DB #1 in order to be included in DB#2, here's the query:

        mysql_select_db($database_bb, $bb);
$query_package = "SELECT * FROM packages ORDER BY name ASC";
$package = mysql_query($query_package, $bb) or die(mysql_error());
$row_package = mysql_fetch_assoc($package);
$totalRows_package = mysql_num_rows($package);

Everything's work fine.  The thing is...  I need to call the "packages" table 5 times on popups menues like this:

<select name="top1">[color=red]//(I want to create 5 of this)[/color]
<?php do {?>
<option value="<?php echo $row_package['id_package']?>"><?php echo $row_package['name']?></option><?php
} while ($row_package = mysql_fetch_assoc($package));
?></select>

The problem is when I print the form only the first popup menu show the info from the DB #1 the other doesn't work.  I tried to solve it by creating 5 different querys :-S

I think should be an easier way to do that because I'm calling the same info 5 times.

Thanks for the help, as always it will be appreciated.
Link to comment
Share on other sites

when you
[code]
while($row = mysql_fetch_assoc($package)) {
do something
}
[/code]
it runs through the list of returned rows it has and then it stops so it will only ever run through the rows once unless you either re-run the query or
[code]
mysql_data_seek($package,0);

[/code]
and reset the pointer to the first record again

hope that is what you were after
Link to comment
Share on other sites

Thanks for the help Paul....

But what I'm trying to do is call 5 different popups menus with the info from the DB#1

The script code on the first popup works fine.  But the second shows nothing look:

<select name="top1">//(First)
<?php do {?>
  <option value="<?php echo $row_package['id_package']?>"><?php echo $row_package['name']?></option><?php
} while ($row_package = mysql_fetch_assoc($package));
?></select>

<select name="top2">//(Second)
<?php do {?>
  <option value="<?php echo $row_package['id_package']?>"><?php echo $row_package['name']?></option><?php
} while ($row_package = mysql_fetch_assoc($package));
?></select>

Thanks
Link to comment
Share on other sites

yes because when you have done the first while loop for top1 then the data pointer has gone past the last row in the returned fields and needs resetting back to zero before running it again try something like this
[code]
<select name="top1">//(First)
<?php do {?>
  <option value="<?php echo $row_package['id_package']?>"><?php echo $row_package['name']?></option><?php
} while ($row_package = mysql_fetch_assoc($package));
?></select>

<?php mysql_data_seek($package,0)?>

<select name="top2">//(Second)
<?php do {?>
  <option value="<?php echo $row_package['id_package']?>"><?php echo $row_package['name']?></option><?php
} while ($row_package = mysql_fetch_assoc($package));
?></select>

<?php mysql_data_seek($package,0)?>

[/code]

and so on
Link to comment
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.