avo Posted June 21, 2006 Share Posted June 21, 2006 Hi AllCan anyone please help me with this puzzlemy code is [code]<?//ASSIGN VARIABLE FOR DROP DOWN BOX IN FOR LOOP$num_rows=$_POST['list_in'];//IF SELECT BUTTON PRESSEDif ($_POST['select_in']){ mysql_connect ($dbhost, $dbuser, $dbpass); mysql_select_db ($dbname) or die ( mysql_error ()); $query ="SELECT * FROM booking_in"; $result =mysql_query ($query) or die (mysql_error()); $count=mysql_num_rows($result);//COUNT ROWS IN DBfor($loop=0;$loop<$num_rows;$loop++){ $row=mysql_fetch_array($result); $counter=$loop+1;//ASSIGN COUNTER VALUE $prt_num=$row['b_prt_number']; $prt_date=$row['b_date']; $prt_qty=$row['b_quantity']; $prt_tam=$row['b_tam'];?>[/code]$num_rows=$_POST['list_in']; this is a drop down box asigning a number to $num_rows$count is the number of rows in my db the above code works when i select a number from the drop down box the html (not visable) under the last code is echoed how evermany times but lets say there is 5 rows in my db and i use the dropdown box and select 6 the last record echoed is blank which i would expect i would like to use the count to limit this if theres only 5 in the db but i select six to only echo 5 how can i achive this please Quote Link to comment https://forums.phpfreaks.com/topic/12591-looping-question/ Share on other sites More sharing options...
trq Posted June 21, 2006 Share Posted June 21, 2006 Change your for() loop to...[code]for($loop = 0; $loop < $num_rows, $loop < $count; $loop++) {[/code]Ive added spacing to make it clearer whats happening, its not really required. Quote Link to comment https://forums.phpfreaks.com/topic/12591-looping-question/#findComment-48261 Share on other sites More sharing options...
avo Posted June 21, 2006 Author Share Posted June 21, 2006 [!--quoteo(post=386624:date=Jun 21 2006, 11:49 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 21 2006, 11:49 PM) [snapback]386624[/snapback][/div][div class=\'quotemain\'][!--quotec--]Change your for() loop to...[code]for($loop = 0; $loop < $num_rows, $loop < $count; $loop++) {[/code]Ive added spacing to make it clearer whats happening, its not really required.[/quote]Hi thanks tryed that but when i enter 1(or upto rows in db) in the drop down box it displayes all in my db utill i go over the amount of rows in my db if this makes senseany ideas thanks. Quote Link to comment https://forums.phpfreaks.com/topic/12591-looping-question/#findComment-48269 Share on other sites More sharing options...
trq Posted June 21, 2006 Share Posted June 21, 2006 Maybe switch the order?[code]for($loop = 0; $loop < $count, $loop < $num_rows; $loop++) {[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12591-looping-question/#findComment-48278 Share on other sites More sharing options...
avo Posted June 22, 2006 Author Share Posted June 22, 2006 [!--quoteo(post=386642:date=Jun 22 2006, 12:44 AM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 22 2006, 12:44 AM) [snapback]386642[/snapback][/div][div class=\'quotemain\'][!--quotec--]Maybe switch the order?[code]for($loop = 0; $loop < $count, $loop < $num_rows; $loop++) {[/code][/quote]Hi Thanks Still had struggled with this for loop been looking at some functions see what can so the job came up with this[code]for($loop=0;$loop<min($count,$num_rows);$loop++){[/code]min(return lowest numeric value)works goodcheers Quote Link to comment https://forums.phpfreaks.com/topic/12591-looping-question/#findComment-48383 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.