if statement problems

Discussion in 'PHP' started by simstar, Dec 23, 2008.

  1. #1
    I have done this several times before but I really can't understand why the code below doesn't work:

    Any help is welcome, thanks.

     <?
    	$sql = "SELECT SubmittedBy FROM Game WHERE Game.AddressCheatExtreme = '$AddressCheatExtremen'"; 
    	$query = mysql_query($sql); 
    	while($result = mysql_fetch_array($query))
    	$SubmittedBy['test'];
    
    if ( $test == "SimonM" ) {
    	echo "Display this text <br />";
    } 
    ?>
    PHP:
     
    simstar, Dec 23, 2008 IP
  2. planemaniac

    planemaniac Peon

    Messages:
    49
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think I see what you need to do, but I would do it like this (don't worry, it's very similar).

    
    <?php
    
    $sql = "SELECT SubmittedBy FROM Game WHERE Game.AddressCheatExtreme = '$AddressCheatExtremen'"; // Your original SQL statement 
    
    $query = mysql_query($sql) or die (mysql_error()); // execute the query on the database
    
    while($result = mysql_fetch_array($query)) { // The opening of the while loop - notice the { (curly brace)
    
    $sub_by = $result['SubmittedBy']; // This is variable that holds the current result of the query
    
    if($sub_by == "SimonM") { // If the current result == "SimonM", do this
    
    echo "Display this text if SubmittedBy = SimonM"; // Show this if SubmittedBy is equal to SimonM
    
    
    } else { // Remove this else statement if you don't need it, or if there are a lot of results to go through
    echo "SubmittedBy is not SimonM<br />";
    } // The closing of the IF statement
    } // This is the end of the while loop
    
    ?>
    PHP:
    I think the problem was you didn't end your while loop, and you didn't start it with the curly brace.

    I hope that helps
     
    planemaniac, Dec 23, 2008 IP
  3. farad

    farad Peon

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Try to End your WHILE loop .. It may cause a lot of porblems - not only this one !
     
    farad, Dec 23, 2008 IP