Julian Posted October 5, 2006 Share Posted October 5, 2006 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 :-SI 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. Quote Link to comment https://forums.phpfreaks.com/topic/23090-recall-query-several-times/ Share on other sites More sharing options...
paul2463 Posted October 5, 2006 Share Posted October 5, 2006 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 againhope that is what you were after Quote Link to comment https://forums.phpfreaks.com/topic/23090-recall-query-several-times/#findComment-104380 Share on other sites More sharing options...
Julian Posted October 5, 2006 Author Share Posted October 5, 2006 Thanks for the help Paul....But what I'm trying to do is call 5 different popups menus with the info from the DB#1The 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 Quote Link to comment https://forums.phpfreaks.com/topic/23090-recall-query-several-times/#findComment-104384 Share on other sites More sharing options...
paul2463 Posted October 5, 2006 Share Posted October 5, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/23090-recall-query-several-times/#findComment-104390 Share on other sites More sharing options...
.josh Posted October 5, 2006 Share Posted October 5, 2006 except that you could you know, put that in a loop. Quote Link to comment https://forums.phpfreaks.com/topic/23090-recall-query-several-times/#findComment-104393 Share on other sites More sharing options...
Julian Posted October 5, 2006 Author Share Posted October 5, 2006 Awesome....As always you guys got it.Thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/23090-recall-query-several-times/#findComment-104405 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.