Pregunta

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

$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?

¿Fue útil?

Solución

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);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top