hi all,
i am new to php and i would like to know how to get the value from a query set to a variable.
eg is.
my query is
select max(columnname) from table_name;
i want to get this value retrieved from the query to a variable.
regards,
sreejith
how to fetch the value from a query to a variable
Moderator: General Moderators
-
imsreejith2478
- Forum Newbie
- Posts: 1
- Joined: Thu Apr 24, 2008 5:34 am
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: how to fetch the value from a query to a variable
Here's the code - simplistic version:
if you want to output multiple tables rows then you will need to loop the result array:
Code: Select all
$query="select max(columnname) from table_name"; //SETUP QUERY
$result=mysql_query($query); //EXECUTE QUERY
$row=mysql_fetch_array($result); //FETCH QUERY RESULTS AS AN ARRAY
Code: Select all
while($row=mysql_fetch_array($result))
{
echo $row['field_name'];
}