avo Posted July 2, 2006 Share Posted July 2, 2006 Hi AllAny ideas please why i can not get the row count from this if i put a number in <= i can pull the rows up to this number but with this code it allways 0[quote]$result="SELECT units_covered FROM office_1 WHERE customer_name='".$_POST['drp_customers']."' ORDER BY units_covered ASC"; $query=mysql_query ($result) or die (mysql_error());$row_count=mysql_num_rows(query) ;while ($row=mysql_fetch_array ($query)) { for($i=0;$i<=$row_count ;$i++) { $r=$row['units_covered']; $v=explode("'", $r); $units="<option>"; $units.="$v[$i]"; $units.="</option>"; echo $units ; }}[/quote]thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/13491-mysql_num_rows-question/ Share on other sites More sharing options...
karthikeyan_coder Posted July 2, 2006 Share Posted July 2, 2006 [quote]$row_count=mysql_num_rows(query) ;[/quote]replace the above line with [quote]$row_count=mysql_num_rows($query) ;[/quote]Thank you,Karthi Keyan. Quote Link to comment https://forums.phpfreaks.com/topic/13491-mysql_num_rows-question/#findComment-52195 Share on other sites More sharing options...
avo Posted July 2, 2006 Author Share Posted July 2, 2006 HI Thanks Now thats 2 stuppid questions i have asked today i must be doing to much php SLEEPY EYESthanks agian. Quote Link to comment https://forums.phpfreaks.com/topic/13491-mysql_num_rows-question/#findComment-52202 Share on other sites More sharing options...
karthikeyan_coder Posted July 2, 2006 Share Posted July 2, 2006 ok np... refer php.net for syntax... once you have Zend studio then it will show you syntax errors during the time of codingThank you,Karthi Keyan. Quote Link to comment https://forums.phpfreaks.com/topic/13491-mysql_num_rows-question/#findComment-52212 Share on other sites More sharing options...
wildteen88 Posted July 2, 2006 Share Posted July 2, 2006 Also I'd chnage this:[code]while ($row=mysql_fetch_array ($query)){ for($i=0;$i<=$row_count ;$i++) { $r=$row['units_covered']; $v=explode("'", $r); $units="<option>"; $units.="$v[$i]"; $units.="</option>"; echo $units ; }}[/code]to the following:[code]$i = 0;while ($row = mysql_fetch_array ($query)){ $r = $row['units_covered']; $v = explode("'", $r); $units = "<option>"; $units .= $v[$i]; $units .= "</option>"; echo $units; $i++;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13491-mysql_num_rows-question/#findComment-52223 Share on other sites More sharing options...
avo Posted July 2, 2006 Author Share Posted July 2, 2006 HI thanks Would there be a better way to do this as i need to count the explode to echo the resultsas all the values are stores in on coloum in one row [quote]while ($row=mysql_fetch_array ($query)) { for($i=0;$i<=$count ;$i++) { $r=$row['units_covered']; $v=explode("'", $r); $count=count($v); $units="<option>"; $units.="$v[$i]"; $units.="</option>"; echo $units ; }}[/quote]my first post was wrong i did not need to count the rows but the explodethanks Quote Link to comment https://forums.phpfreaks.com/topic/13491-mysql_num_rows-question/#findComment-52226 Share on other sites More sharing options...
wildteen88 Posted July 3, 2006 Share Posted July 3, 2006 That is what the new code provided does:[code]$i = 0;while ($row = mysql_fetch_array ($query)){ $r = $row['units_covered']; $v = explode("'", $r); $units = "<option>"; $units .= $v[$i]; $units .= "</option>"; echo $units; $i++;}[/code]The while loop automatically calculates how many times it needs to loop in order to get all the results. Also the variable $i automatically increases by 1 with [i]$i++[/i], So when $v[$i] is stated when it goes for the first loop it use $v[0] then it use $v[1] for the secound loop, $v[2] for the third loop etc.Bascially the while loop and the for loop was doiing the same thing, but in a different way. You code should still ruin fine. Quote Link to comment https://forums.phpfreaks.com/topic/13491-mysql_num_rows-question/#findComment-52468 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.