Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing the rest of my record set...

Status
Not open for further replies.

secretsquirrel

Programmer
Mar 22, 2001
202
GB
i'm trying to retrieve a column out of a mysql table.

my problem is how to get past the first row of the result set.

at the moment, if i display the results of the function below i get...


Location: London

Location:

but i want it to look like...

Location: London

Location: Paris

----------------------------------------

function getLocations($username)
{
if(!($conn = db_connect()))
return false;

$result = mysql_query("SELECT location FROM myTable");

if(!$result)
return false;

$num_results = mysql_num_rows($result);

$row = mysql_fetch_array($result);

for($count = 0; $count < $num_results; $count++)
{
print &quot;<p>Location: $row[$count]&quot;;
}
}

----------------------------------------

can anyone point out where i'm going wrong, please?

thanks in advance,

ss...
 
Code:
   $num_results = mysql_num_rows($result);
    for($count = 0; $count < $num_results; $count++)
    {
    $row = mysql_fetch_array($result);
    $location=$row[&quot;location&quot;];
        print &quot;<p>Location: $location&quot;;
    }
}

 
thanks hos2,

i knew it would be something simple. i'm new to php and i'm still getting to grips with how to handle arrays.

ss...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top