I often use:
mysql_num_rows returns the number of rows anyways.Code:$query = "SELECT * FROM table";
$result = mysql_query($query);
$num = mysql_num_rows($result);
for ($i = 0;$i < $num;$i++)
$fields = mysql_result($result,$i,"myfield");
Printable View
I often use:
mysql_num_rows returns the number of rows anyways.Code:$query = "SELECT * FROM table";
$result = mysql_query($query);
$num = mysql_num_rows($result);
for ($i = 0;$i < $num;$i++)
$fields = mysql_result($result,$i,"myfield");
Haha, whoops -- I think it should have beenI didn't really look, just inserted code around what was already there :)Code:for($resultnumber = 1; $iddrow = mysql_fetch_array($iddrs); ++$resultnumber)
So calling the array directly will give you it's length?
twey, is that not the same code you posted before?! :confused:
I didnt know where to put it, so i tried before, then after the while statement.. but both just show 1 as the result..
Like this:Code:<?php
$iddaddress = "localhost";
$iddusername = "xxxx";
$iddpassword = "xxxx";
$idddb = "xxxx";
$iddconn = mysql_connect($iddaddress, $iddusername, $iddpassword);
$iddrs = mysql_select_db($idddb, $iddconn);
$iddsql="SELECT * FROM handset GROUP BY handset";
$iddrs = mysql_query($iddsql, $iddconn);
for($resultnumber = 1; $iddrow = mysql_fetch_array($iddrs); ++$resultnumber) {
$iddmake = $iddrow['make'];
$iddhand = $iddrow['handset'];
$idddetails = $iddrow['details'];
echo("This is result number: $resultnumber");
}
mysql_close();
?>
thanks twey and everyone else!! works great!