jaiffed Posted February 17, 2010 Share Posted February 17, 2010 what's wrong in this script it's not working it's showing only one member detail..... <?php include('connect.php'); $Tb = "issue"; mysql_select_db($Db, $link); $query = "select mem_id from issue WHERE avail='1' order by issue_id"; $result= mysql_query($query,$link); $fel=mysql_num_fields($result); $nro=mysql_num_rows($result); while ($row=mysql_fetch_array($result)) { $mem_id=$row[mem_id]; $query = "select mem_id,mem_name from mem_master WHERE mem_id='$mem_id' order by mem_id"; $result= mysql_query($query,$link); $fel=mysql_num_fields($result); $nro=mysql_num_rows($result); if ($nro>0) { echo "<select name='itemmem'>\n"; echo "<option>-- Select Member ID or Member Name --</option>\n"; while ($row=mysql_fetch_array($result)) { $row[mem_id]; echo "<option value='$row[mem_id]'>$row[mem_id]--$row[mem_name]</option>\n"; } } } mysql_close($link); ?> Link to comment https://forums.phpfreaks.com/topic/192434-problem-in-combo-box-view/ Share on other sites More sharing options...
LeadingWebDev Posted February 17, 2010 Share Posted February 17, 2010 in the second WHILE statement you overwriting $row variable, that actually holds results from first query. rename to $row2 for example hope was helpful Link to comment https://forums.phpfreaks.com/topic/192434-problem-in-combo-box-view/#findComment-1013952 Share on other sites More sharing options...
jaiffed Posted February 17, 2010 Author Share Posted February 17, 2010 i tried rows ,row2 but it doesn't work Link to comment https://forums.phpfreaks.com/topic/192434-problem-in-combo-box-view/#findComment-1013956 Share on other sites More sharing options...
sader Posted February 17, 2010 Share Posted February 17, 2010 I gues becouse u are reseting some variables when u are looping inside loop look here: $query = "select mem_id,mem_name from mem_master WHERE mem_id='$mem_id' order by mem_id"; $result= mysql_query($query,$link); $fel=mysql_num_fields($result); $nro=mysql_num_rows($result); should be changes to something like $query = "select mem_id,mem_name from mem_master WHERE mem_id='$mem_id' order by mem_id"; $result2= mysql_query($query,$link); $fel=mysql_num_fields($result2); //<== do U use this somewhere? $nro=mysql_num_rows($result2); then inner while loop should louok like so while ($row2=mysql_fetch_array($result2)) { //$row[mem_id]; I think u dont need this at all echo "<option value='$row2[mem_id]'>$row2[mem_id]--$row2[mem_name]</option>\n"; } I am not 100% sure this will solve problem, but this is my first gues Link to comment https://forums.phpfreaks.com/topic/192434-problem-in-combo-box-view/#findComment-1013957 Share on other sites More sharing options...
LeadingWebDev Posted February 17, 2010 Share Posted February 17, 2010 also try renaming $query inside loop and $result inside loop. u overide all vars that u need to use inside a loop. <?php include('connect.php'); $Tb = "issue"; mysql_select_db($Db, $link); $query = "select mem_id from issue WHERE avail='1' order by issue_id"; $result= mysql_query($query,$link); $nro=mysql_num_rows($result); while ($row=mysql_fetch_array($result)) { $mem_id=$row['mem_id']; $query2 = "select mem_id,mem_name from mem_master WHERE mem_id='$mem_id' order by mem_id"; $result2=mysql_query($query,$link); $nro=mysql_num_rows($result); if ($nro>0) { echo "<select name='itemmem'>\n"; echo "<option>-- Select Member ID or Member Name --</option>\n"; while ($row2=mysql_fetch_array($result)) { //$row[mem_id]; echo "<option value='$row2[mem_id]'>$row2[mem_id]--$row2[mem_name]</option>\n"; } } } mysql_close($link); ?> should work. ...smoking. Link to comment https://forums.phpfreaks.com/topic/192434-problem-in-combo-box-view/#findComment-1013961 Share on other sites More sharing options...
jaiffed Posted February 17, 2010 Author Share Posted February 17, 2010 somehow it works it makes 8 combo box because rows Link to comment https://forums.phpfreaks.com/topic/192434-problem-in-combo-box-view/#findComment-1013967 Share on other sites More sharing options...
jaiffed Posted February 17, 2010 Author Share Posted February 17, 2010 somehow it works it makes 8 combo box because rows was also 8 Link to comment https://forums.phpfreaks.com/topic/192434-problem-in-combo-box-view/#findComment-1013969 Share on other sites More sharing options...
LeadingWebDev Posted February 17, 2010 Share Posted February 17, 2010 alright, put the <select> before the loops and </select> after loops, inside loops leave just <option value=""> then u will get 1 drop down with 8 rows inside. hope was helpful. Link to comment https://forums.phpfreaks.com/topic/192434-problem-in-combo-box-view/#findComment-1013974 Share on other sites More sharing options...
jaiffed Posted February 17, 2010 Author Share Posted February 17, 2010 sorry i had posted twice and that's for sader)))))))) thanks you very much LeadingWebDev your previous script is working but now this script have a problem it's not picking mem_name value Link to comment https://forums.phpfreaks.com/topic/192434-problem-in-combo-box-view/#findComment-1013983 Share on other sites More sharing options...
sader Posted February 17, 2010 Share Posted February 17, 2010 are u fetching $result2 in inner while loop? Link to comment https://forums.phpfreaks.com/topic/192434-problem-in-combo-box-view/#findComment-1013987 Share on other sites More sharing options...
LeadingWebDev Posted February 17, 2010 Share Posted February 17, 2010 while ($row2=mysql_fetch_array($result2)) { //$row[mem_id]; echo "<option value='$row2[mem_id]'>$row2[mem_id]--$row2[mem_name]</option>\n"; } totally fixed Link to comment https://forums.phpfreaks.com/topic/192434-problem-in-combo-box-view/#findComment-1013990 Share on other sites More sharing options...
jaiffed Posted February 17, 2010 Author Share Posted February 17, 2010 its working perfectly thanks you both of you and sincerely thanks to Leading Web Dev. thankss Link to comment https://forums.phpfreaks.com/topic/192434-problem-in-combo-box-view/#findComment-1014017 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.