SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question IF has an award display if not dont show

    Hi all, Currently I have a table row thats called award which will be populated with either a 1 or 0

    Currently when data is being pulled from the database based on the game_id Im trying to echo out all the game info, but also trying to tell the query to display the award if award='1'

    PHP Code:
    <?php
    $checkaward 
    mysql_query("
    SELECT * FROM "
    .$tablename.
    WHERE game_id="
    .mysql_real_escape_string($_GET['award="1"'])."
    "
    );        
    if(
    mysql_num_rows($checkaward) <1){ 
               
    $row1 "no award";        

    } else {                  
    $data mysql_fetch_object($checkaward);
                 
    $row1 "has award";   }  
    ?>
    Currently this doesnt work and this was going to be a second query I was running just to display the award if ='1'

    The 1st query that pulls the data for the game is:

    PHP Code:
    $game mysql_query('SELECT *, DATE_FORMAT(date,"%D %b %Y") AS realdate FROM '.$tablename.
        WHERE game_id="'
    .mysql_real_escape_string($_GET['game_id']).'" ORDER BY game_id'); 
    Can anyone see where Im going wrong and also would running 2 queries be a bad thing and is best suited to run it all as one query.
    Regards
    Deano

  2. #2
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why do you need to throw $_GET['award'] in there? Can't you just do:
    PHP Code:
    $checkaward mysql_query("SELECT * FROM ".$tablename." WHERE game_id=1"); 
    ??
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  3. #3
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To be hoest, Im not a fully fledged PHP guru and only play at it

    I've totally fell out with the idea of running a query for it, and thought a IF ELSE statement would suffice.

    So back to square one for me

    Ok let me try and start again from scratch.

    Im pulling data related to a game_id and all works just fine.

    What I'm now trying to do is use an IF ELSE statment to to display something if the table row for award is set to 1

    award='1' (has an award)
    award='0' (has no award)


    so far I have:

    PHP Code:
    if ($award == "1") { 
    print(
    "has award"); 
    } else { 
    print(
    "no award"); 

    currently regardless of what the award is set to it displays 'no award' when I know that it does

    Suggestions are greatly appreciated.
    Regards
    Deano

  4. #4
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $checkaward mysql_query("

    SELECT * FROM "
    .$tablename.
    WHERE game_id='" 
    .Game_ID_Goes_Here"'");
    $row mysql_fetch_assoc$checkaward );
            
    if ( 
    $row['award'] ) { 
        
    $row1 "no award";        
    } else {                  
        
    $row1 "has award";

    Execute your query, get the row from the result and check the "checkaward" field.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  5. #5
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Byron, Thanks for the help.

    Ive implamented the code and for the life of me cant understand why nothing appears

    To reflect what Im talking about, on the top right, below 'release date now' the 'has award' or 'no award' should be displayed.

    http://www.flightsimreviews.com/review.php?game_id=1

    Would it make a difference on the table row type ?
    Regards
    Deano

  6. #6
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does your code actually echo these statements back @ some point ?
    Show me the actual code for that division.
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  7. #7
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would it be easier if I sent the review.php page where the code resides ?
    Regards
    Deano

  8. #8
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not quite sure what you mean. Lets see if I can help out a little here.
    The page you sent me to, review.php @ some point you are outputting your html. Whether it comes from static code or php echoed code. When you get to that line you will have a function ( lets call it hasAward() ). the function should use the code snippet from the earlier post in this thread to open the data base and check to see if the game ( pass the game ID in as a parameter ) has an award. If it does return a TRUE if not return a FALSE.

    PHP Code:

    function hasAward$Game_ID ) {
        
    $query "SELECT * FROM " .$tablename" WHERE game_id='" .$Game_ID"'"// Put the actual table name in this query, will it change ?
        // Open your data base here
        
    $results mysql_query$query );
        
    $row mysql_fetch_assoc$results );
            
        if ( 
    $row['award'] ) { 
            return 
    TRUE;        
        } else {                  
            return 
    FALSE;
        }

    Your display code would read something like:
    PHP Code:
    if ( hasAward$Game_ID ) ) {
        echo 
    "Has Award";
    } else {
        echo 
    "No Award";

    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  9. #9
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ive added the above and still nothing will display
    Regards
    Deano

  10. #10
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK made a few adjustments, and the page now displays "No Award"
    Regards
    Deano

  11. #11
    SitePoint Evangelist Deano's Avatar
    Join Date
    Mar 2003
    Location
    Derbyshire, UK
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm every strange, everything seems to be working just fine now.

    Thanks again Byron, without your help I couldnt have got this to work, most appreciated.
    Regards
    Deano


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
  •