funbinod Posted March 24, 2014 Share Posted March 24, 2014 i created loop for selecting from all the rows of a table like this--- <?$rows = mysql_num_rows($result);for ($n = 0 ; $n < $rows ; ++$n) { echo '' . mysql_result($result,$n,'item') . '<br />'; }?> and tried to put in dropdown menu like this ---- echo '<form action="#" id="test" name="test">';echo '<select name="item">';echo "<option></option>";echo "<option>";{echo '' . mysql_result($result,$n,'item') . '<br />';}echo "</option>";echo '</select>';echo '</form>'; but returned error "Warning: mysql_result(): Unable to jump to row 2 on MySQL result index 5 in .................................." please guide me.... Link to comment Share on other sites More sharing options...
Ingolme Posted March 24, 2014 Share Posted March 24, 2014 You probably should use mysql_fetch_assoc() instead. Best if you used a more recent database library, such as mysqli or PDO, because mysql is insecure and is being deprecated. Link to comment Share on other sites More sharing options...
funbinod Posted March 24, 2014 Author Share Posted March 24, 2014 You probably should use mysql_fetch_assoc() instead. Best if you used a more recent database library, such as mysqli or PDO, because mysql is insecure and is being deprecated. i think thats not the solution to my problem. my problem IS NOT that i could not extract data from table. my problem IS i coludn't put that data in a DROPDOWN list. or i didn't understand ur sugestion????? Link to comment Share on other sites More sharing options...
Ingolme Posted March 24, 2014 Share Posted March 24, 2014 You're getting a PHP error because you're asking for an index in mysql_result() that doesn't seem to exist. The easiest way to solve the problem is to use mysql_fetch_assoc() rather than mysql_result() to get data from the query. Looking at your second code more carefully, you don't seem to have a while loop and you have a pair of braces { } that aren't representing anything. echo '<form action="#" id="test" name="test">';echo '<select name="item">';echo "<option></option>";echo "<option>";{echo '' . mysql_result($result,$n,'item') . '<br />';}echo "</option>";echo '</select>';echo '</form>'; Somebody already provided working code for your question in this thread: http://w3schools.invisionzone.com/index.php?showtopic=49767 Link to comment Share on other sites More sharing options...
funbinod Posted March 24, 2014 Author Share Posted March 24, 2014 You're getting a PHP error because you're asking for an index in mysql_result() that doesn't seem to exist. The easiest way to solve the problem is to use mysql_fetch_assoc() rather than mysql_result() to get data from the query. Looking at your second code more carefully, you don't seem to have a while loop and you have a pair of braces { } that aren't representing anything. echo '<form action="#" id="test" name="test">';echo '<select name="item">';echo "<option></option>";echo "<option>";{echo '' . mysql_result($result,$n,'item') . '<br />';}echo "</option>";echo '</select>';echo '</form>'; Somebody already provided working code for your question in this thread: http://w3schools.invisionzone.com/index.php?showtopic=49767 thank u! now i understood where i did mistake. actually i had used for loop to get data. but i placed that line elsewhere on the page and expected the result here. finally i completed the code by doing this --- <?$rows = mysql_num_rows($result);for ($n = 0 ; $n < $rows ; ++$n) { echo '' . mysql_result($result,$n,'item') . '<br />'; }echo '<form action="#" id="test" name="test">';echo '<select name="item">';$rows = mysql_num_rows($result);for ($n = 0 ; $n < $rows ; ++$n){ echo "<option>" . mysql_result($result,$n,'item') . "</option>" ;}echo '</select>';echo '</form>'; ?> thank u for guiding me. (sorry! i couldn't understand the solution that was given on that thread. that's why i was continuing here also.) Link to comment Share on other sites More sharing options...
etsted Posted March 26, 2014 Share Posted March 26, 2014 (edited) you should use a while loop instead. while($rows = mysql_num_rows($result)){ $data1 = $rows['data1']; echo "$data1 <br />"; } Edited March 26, 2014 by etsted Link to comment Share on other sites More sharing options...
funbinod Posted March 27, 2014 Author Share Posted March 27, 2014 i dunno what exactly is the different between "for loop" & "while loop".. please guide... Link to comment Share on other sites More sharing options...
etsted Posted March 27, 2014 Share Posted March 27, 2014 you can read it in w3schools.com 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now