Hello Guys,

I've written a block to display some content (a list of items that a user is interested in), and one of the things the block does is query the sessions table to look up the session ID from the IP address being used. This is used later in the script for another purpose. The problem I'm having is that on some initial visits to the site, when a session hasn't been set yet, I'm getting an error: user warning: Query was empty query in *path to site*/includes/database.mysql.inc on line 174.

On a reload or visiting another page, the error disappears (due to the session being set) - Is there any way around this in the way I call db_query()? Or is there a way to stop this warning being displayed as it doesn't look very professional to our users when they hit the site for the first time!

Hoping someone would be kind and share their advice here!

~CalonDdraig

Comments

johnhanley’s picture

It seems like a simple condition would do the trick:

if ($sid = db_result(db_query("SELECT sid FROM {sessions} WHERE hostname = '%s'", $ip)) {
  // show block
}

where $ip is the visitor's IP.

CalonDdraig’s picture

Thanks for that Bacteria Man... don't know why I didn't think of that:S Oh well, you're a star anyway!

Many thanks!

~CalonDdraig

johnhanley’s picture

BTW, there should be an extra close parenthesis on the end of the if statement, but I'm sure you figured that out on your own.