Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: mysql query

  1. #1
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post

    mysql query

    I need away to check for mysql_query returning empty results and throw a error if its empty. For the following code
    PHP 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>
            </div>'
    ;
            }
         
    //} 
    is the commented if statement correct for it?

  2. Users who have thanked moos3 for this post:

    venkib097 (08-29-2007)

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,042
    Thanks
    19
    Thanked 42 Times in 42 Posts

  • Users who have thanked rafiki for this post:

    venkib097 (08-29-2007)

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    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().


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •