Jump to content

Printing one field


waynew

Recommended Posts

or

 


$value = mysql_result($resource,$row_num,'col_name');

 

mysql_fetch_assoc and mysql_fetch_array return an [associative] array of the entire row.  If you just want a single value, mysql_result gives it to you.  just replace $row_num with 0 (zero) if only a single row is going to be returned.  If the query only returns a single attribute, then you can leave the 'col_name' off as well.

 

so something like

 

<?php
$query = "SELECT COUNT(`names`) FROM table";
$result = mysql_query($query);
$num_names = mysql_result($result,0);
?>

 

would set $num_names to the COUNT(`names`);

Link to comment
https://forums.phpfreaks.com/topic/113936-printing-one-field/#findComment-585564
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.