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 5 of 5

Thread: Simple if/else

  1. #1
    New Coder
    Join Date
    Dec 2004
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple if/else

    I'm trying to check the DB for a name and return the error if its not found


    PHP Code:
       if(!$checkname) {
            
    $row1 "$player not found";
          }
          else {
            
    $row1 "Name: $data->playername Rank: $data->rank Score: $data->totalscore MVP: $data->mvp Rank Points: $data->rankpoints";
            
    $row2 "Kills: $data->totalkills Deaths: $data->totaldeaths Games: $data->games GDI: $data->gdi Nod: $data->nod";
          }
       } 
    when the name is found its fine, but when no name is found it does not show the error message

    Full code



    PHP Code:
    <?php

      
    include "config.php";

       
      
    $FontFile="/home/xxx/www/stats_sig/arial.ttf";

      
    $player "$_GET[player]";
      
    $imgurl "$_GET[imgurl]";
      
    $colour "$_GET[colour]";

      if (
    $image == gdi$ImageURL="images/gdi.png";
       elseif (
    $image == nod$ImageURL="images/nod.png";
       elseif (
    $image == users$ImageURL="".$imgurl."";
       else 
    $ImageURL="images/default.png";

       
    $checkname mysql_query("SELECT * FROM ranks where playername = '".$player."'");
          while(
    $data mysql_fetch_object($checkname)) {

     if(!
    $checkname) {
            
    $row1 "$player not found";
          }
          else {
            
    $row1 "Name: $data->playername Rank: $data->rank Score: $data->totalscore MVP: $data->mvp Rank Points: $data->rankpoints";
            
    $row2 "Kills: $data->totalkills Deaths: $data->totaldeaths Games: $data->games GDI: $data->gdi Nod: $data->nod";
          }
       }

       
    $TextX=5;
       
    $TextY=5;
       
    $size ImageTTFBbox (150$FontFile"meh");
       
    $im_x=abs($size[4]-$size[0]);
       
    $im_y=abs($size[5]-$size[1]);

      if (
    substr($ImageURL,strlen($ImageURL)-3,3)=="png") {
       
    Header("Content-type: image/png");
       
    Header("Expires: " gmdate("D, d M Y H:i:s"time() + 900) . " GMT");

       
    $im_size GetImageSize ($ImageURL);
       
    $imageWidth $im_size[0];
       
    $imageHeight $im_size[1];

       
    $im ImageCreateFromPNG($ImageURL);

      if (
    $colour == white$text_color imagecolorclosest ($im255255255);
       elseif (
    $colour == black$text_color imagecolorclosest ($im000);
       else 
    $text_color imagecolorclosest ($im255255255);

      
          if (
    $TextX+$im_x>$imageWidth){$TextX=$imageWidth-$im_x-2;}
          if (
    $TextY>$imageHeight){$TextY=$imageHeight-2;}
          if(
    $row1)imagettftext ($im100$TextX+10$TextY+24$text_color$FontFile$row1);
          if(
    $row2)imagettftext ($im100$TextX+10$TextY+47$text_color$FontFile$row2);

        
    Imagepng ($im);
        
    ImageDestroy ($im);
    }

    ?>
    Last edited by I3arry; 07-03-2007 at 03:41 PM.

  • #2
    Regular Coder
    Join Date
    Jun 2007
    Location
    N. Ireland
    Posts
    351
    Thanks
    16
    Thanked 4 Times in 4 Posts
    How about using:

    PHP Code:
    $checkname='';
    $checkname mysql_query("SELECT * FROM ranks where playername = '".$player."'"); 
    Then:

    PHP Code:
    if($checkname ==''
    D.
    Daemonkin.
    If this was helpful, please add to my reputation
    Thousand Sons - Freelance Web Developer - ninetyonedegrees.com

  • #3
    New Coder
    Join Date
    Dec 2004
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I already tried that way with no luck :/

  • #4
    Regular Coder
    Join Date
    Jun 2007
    Location
    N. Ireland
    Posts
    351
    Thanks
    16
    Thanked 4 Times in 4 Posts
    What about mysql_num_rows. If num_rows is 0 then player does not exist. otherwise get player data?
    Daemonkin.
    If this was helpful, please add to my reputation
    Thousand Sons - Freelance Web Developer - ninetyonedegrees.com

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    PHP Code:
    $checkname mysql_query("SELECT * FROM ranks where playername = '".$player."'");
          while(
    $data mysql_fetch_object($checkname)) {

    $row1 "$player not found";
    $row2 "";
     if(
    strlen($checkname)>0) {
            
    $row1 "Name: $data->playername Rank: $data->rank Score: $data->totalscore MVP: $data->mvp Rank Points: $data->rankpoints";
            
    $row2 "Kills: $data->totalkills Deaths: $data->totaldeaths Games: $data->games GDI: $data->gdi Nod: $data->nod";
          }




    .


  •  

    Posting Permissions

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