I use the following code style in my codes, is this a bad approach ? less effective ? less optimized ? if so what would be the best approach and optimized query for just fetching information from database.. thanks for your time..
Instead of the for loop, use: while($r = mysql_fetch_assoc($q)) { echo "any field or anything you wnt to do with data"; } PHP:
I dont think if that would make any differece, can you please give some reasons ? it wont effect the performace of the query...
By calling mysql_num_rows() you ask MySQL API to check the number of returned rows on every iteration of the loop.
The while loop will automatically step through the result set in $q a row at a time and will close itself when there is no data left so you don't need the row count. Kynlem is right, this is more efficient as you don't make calls to mysql_num_rows() and you are not using the $i counter.