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); ?> Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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.