Error loading bio for user with no bio

phonydream2 - April 16, 2008 - 19:13
Project:Bio
Version:5.x-1.2
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I have custom code in my page.tpl.php file:

$mybionode = node_load(bio_for_user($user->uid));

Unfortunately, it gives the following errors when a user hasn't already filled out their bio information:

* warning: Invalid argument supplied for foreach() in node.module on line 537.
* warning: implode(): Bad arguments. in node.module on line 541.
* user warning: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 query: node_load SELECT n.nid, n.vid,

I guess you can't load a node if it doesn't exist. Is there a way to check if a node exists before I call node_load? I don't see anything in the API. I could do an SQL check but I'm wary of running too many queries (I suppose the API would have to run a query anyhow).

#1

Allie Micka - April 11, 2009 - 02:25
Status:active» closed

That's correct, you can't load a node that doesn't exist. But you CAN see if it exists before loading it. Try the following code:

if ($nid = bio_for_user($user->uid)) {
$mybionode = node_load($nid);
}

Of course, you'll have to account for an empty $mybionode in the remainder of your code.

Thanks!

 
 

Drupal is a registered trademark of Dries Buytaert.