phpmysqlzend-db-select

Get just the name from mysql_query resource


$agent_query=mysql_query("
                            SELECT name FROM users WHERE id='$agent_id'
                        ");
$get_agent_name=mysql_fetch_assoc($agent_query);            
$this->session->agent=$get_agent_name['name'];

I know the mysql_fetch_assoc() expects parameter 1 to be resource, but is there a way I can get just the name without running any loop in Zend?


Solution

  • The php function mysql_result can be used to return a single field for a query by specifying the row and column you want returned. As there is only 1 row and column for your query (I assume), they will always be 0 and 0.

    $name = mysql_result($agent_query, 0, 0);