View Full Version : mysql query

08-28-2007, 07:45 PM
I need away to check for mysql_query returning empty results and throw a error if its empty. For the following code

$sql = "SELECT t1.username, t1.email, t2.about, t2.url, t2.aim, t2.u_icon, t2.zone_id,t2.location, t3.geoarea FROM users AS t1 LEFT JOIN u_profile AS t2 ON t1.u_id = t2.u_id_Users LEFT JOIN timezones AS t3 ON t2.zone_id = t3.zone_id WHERE t1.username='$username'";
$results = connect($sql);
// if(empty($results){ echo 'no one here'; }else{
while($usr = mysql_fetch_array($results)){
$username = $usr['username'];
$email = $usr['email'];
$about = $usr['about'];
$url = $usr['url'];
$aim = $usr['aim'];
$u_icon = $usr['u_icon'];
$location = $usr['location'];
$geoTime = $usr['geoarea'];
echo '<div id="panel">
<div id="profileImg"><span class="profileImg"><img src="'.$u_icon.'" alt="" width="95" height="100" /></span></div>
<div id="usrName">username: '.$username.'</div>
<div id="usrEmail">email: Hidden</div>
<div id="usrWww">www: <a href="'.$url.'">'.$url.'</a></div>
<div id="usrAim">aim: '.$aim.'</div>
<div id="usrZone">Timezone: '.$geoTime.'</div>
<div id="usrLoc">Location: '.$location.'</div>
<div id="aboutLabel">About:</div>
<div id="aboutTxt">'.$about.'</div>

is the commented if statement correct for it?

08-28-2007, 07:56 PM
mysql_num_rows()? (http://php.net/mysql_num_rows)

08-28-2007, 08:21 PM
I'm not sure what connect() is a wrapper for but you can return the value of mysql_query() in the connect() function to find out if any rows were returned. If you're using that code already then for the mysql_fetch_array() to work $results has to be a database pointed assigned from mysql_query().