SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Totally Confused - Displaying Incorrect MySQL Result

    Hi Guys,

    Ok this is part of the code i am using:

    PHP Code:
    // CHECK STATUS OF APPLICATION

    mysql_connect(localhost,$username,$password);

    @
    mysql_select_db($database) or die( "Oops theres an error, our highly trained monkeys have been notified.");

    $queryaff "SELECT Status FROM `affprograms` WHERE `AffID` = '$affid' AND `ProID` = '$programid'";

    mysql_query($queryaff);
    $resultaff mysql_query($queryaff);
    mysql_close();

    if(
    $resultaff="Pending"){
        
    $affstatus="Pending";
    } elseif(
    $resultaff="Approved"){
        
    $affstatus="Approved";
    } elseif(
    $resultaff="Declined"){
        
    $affstatus="Declined";
    } else {
        
    //do nothing
    }
    echo 
    "$queryaff <br /> $resultaff <br />";
    echo 
    "TEST OUTPUT - $affstatus";
    // END CHECK STATUS OF APPLICATION 
    Here is the output:

    SELECT Status FROM `affprograms` WHERE `AffID` = '1' AND `ProID` = '2'
    Pending
    TEST OUTPUT - Pending
    Now the problem is the result is not correct, it shouldnt be returning the value Pending and instead it should be returning the value Approved. Now when i run the MySQL Query in PHPMYADMIN i get the correct result:



    So why when i run my script is it returning the incorrect value when im using the same SQL as i have in phpmyadmin?

    Any help would be great.

    Thank you.

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try...

    PHP Code:
    // CHECK STATUS OF APPLICATION 
    mysql_connect(localhost,$username,$password); 
    mysql_select_db($database) or die( "Oops theres an error, our highly trained monkeys have been notified."); 
    $queryaff "SELECT Status FROM affprograms WHERE AffID = '$affid' AND ProID = '$programid'"
    mysql_query($queryaff); 
    $resultaff mysql_query($queryaff); 
    $row mysql_fetch_array($resultaff);
    if(
    $row['Status'] ="Pending"){ 
        
    $affstatus="Pending"
    } elseif(
    $row['Status'] ="Approved"){ 
        
    $affstatus="Approved"
    } elseif(
    $row['Status' ="Declined"){ 
        
    $affstatus="Declined"
    } else { 
        
    //do nothing 

    echo 
    "$queryaff <br />"
    echo 
    "TEST OUTPUT - " $affstatus
    mysql_close(); 
     
    // END CHECK STATUS OF APPLICATION 

  3. #3
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your code contains multiple errors:
    PHP Code:
    mysql_connect(localhost,$username,$password); 
    should be:

    PHP Code:
    mysql_connect('localhost',$username,$password); 
    then in this block:
    PHP Code:
    if($resultaff="Pending"){

        
    $affstatus="Pending";

    } elseif(
    $resultaff="Approved"){

        
    $affstatus="Approved";

    } elseif(
    $resultaff="Declined"){

        
    $affstatus="Declined";

    } else {

        
    //do nothing


    you are using the = operator (which is assignment), when you should be using == (which is for an equality test).

    i.e.:
    PHP Code:
    if($resultaff == "Pending"){

        
    $affstatus="Pending";

    } elseif(
    $resultaff == "Approved"){

        
    $affstatus="Approved";

    } elseif(
    $resultaff == "Declined"){

        
    $affstatus="Declined";

    } else {

        
    //do nothing


    Which is kind of a moot point because your if-else clause doesn't currently do anything useful - you could simply replace the whole thing with:

    PHP Code:
    $affstatus $resultaff

    Also you are running mysql_query() twice for no reason.
    aaron-fisher.com - PHP articles and more

  4. #4
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi aamonkey,

    Thanks for your help, i have done what you suggest and here is the code i am now using:

    PHP Code:
    // CHECK STATUS OF APPLICATION

    mysql_connect('localhost',$username,$password);

    @
    mysql_select_db($database) or die( "Oops theres an error, our highly trained monkeys have been notified.");

    $queryaff "SELECT Status FROM `affprograms` WHERE `AffID` = '$affid' AND `ProID` = '$programid'";

    mysql_query($queryaff);
    $resultaff mysql_query($queryaff);
    $affstatus $resultaff;  
    mysql_close();

    echo 
    "$queryaff <br />";
    echo 
    "TEST OUTPUT - $affstatus";
    // END CHECK STATUS OF APPLICATION 
    How ever i am now getting a
    Resource id #6
    error as the output

    Any help would be great.

    Thanks

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Find this:
    Code:
    $resultaff = mysql_query($queryaff);
    Replace with:
    Code:
    $resultaff = mysql_query($queryaff); 
    while ($row = mysql_fetch_assoc($resultaff)) {
        echo $row['Status'];
    }
    Last edited by Bas!; Mar 22, 2011 at 11:14. Reason: I'm wrong

  6. #6
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Bas! View Post
    You should get rid of this line:
    Code:
    mysql_query($queryaff);
    I've commented it out and now im getting Resource id #5 error

  7. #7
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $link mysql_connect('localhost',$username,$password);
    @
    mysql_select_db($database$link) or die( "Oops theres an error, our highly trained monkeys have been notified.");

    $queryaff "    SELECT Status
                    FROM `affprograms`
                    WHERE `AffID` = '
    $affid'
                    AND `ProID` = '
    $programid'
    "
    ;

    $resultaff mysql_query($queryaff);
    $row mysql_fetch_row($resultaff);
    mysql_close($link);

    $affstatus $row[0];

    echo 
    "$queryaff <br />";

    echo 
    "TEST OUTPUT - $affstatus"
    aaron-fisher.com - PHP articles and more

  8. #8
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by aamonkey View Post
    PHP Code:
    $link mysql_connect('localhost',$username,$password);
    @
    mysql_select_db($database$link) or die( "Oops theres an error, our highly trained monkeys have been notified.");

    $queryaff "    SELECT Status
                    FROM `affprograms`
                    WHERE `AffID` = '
    $affid'
                    AND `ProID` = '
    $programid'
    "
    ;

    $resultaff mysql_query($queryaff);
    $row mysql_fetch_row($resultaff);
    mysql_close($link);

    $affstatus $row[0];

    echo 
    "$queryaff <br />";

    echo 
    "TEST OUTPUT - $affstatus"
    Thank you aaMonkey you have been a big help and resolved this problem. I'd also like to thank everyone else who have offered help in resolving the problem i had. Thank you.

    Now i have another problem

    PHP Code:
    <?
    if($affstatus == "Pending"){
        
    $protext="Your application to run this campaign is under review, please allow 48hrs to review your application.";
    } elseif(
    $affstatus == "Declined"){
        
    $protext="Your application to run this campaign has been Declined. Please speak with your affiliate manager.";
    } elseif(
    $affstatus == "Approved"){
        
    //display banners etc..
        
    $display=eval('echo "'.$string.'";');
        
    $protext="<table width='741' border='0' cellpadding='2' cellspacing='2'>
      <tr>
        <td bgcolor='#FFFFFF'><strong>Banner ID:</strong> <? echo 
    $bannerid; ?><br />
          <img src='<? echo 
    $bannerurl; ?>' /></td>
      </tr>
      <tr>
        <td bgcolor='#FFFFFF'><textarea name='BannerCode' id='BannerCode' cols='60' rows='5'><? echo 
    $display; ?></textarea></td>
      </tr>
    </table>"
    ;
    }
    echo 
    $protext;
    ?>
    The output is fine if $affstatus is Pending. If value is Approved then nothing is displayed and if the value is Declined then it outputs the text but it outputs it 3 times for some reason.

    Again any help on this would be fantastic.

    Thank you very much guys


Bookmarks

Posting Permissions

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