• I have a table called “myguestbook”
    Using $wpdb, how do I check if “jessy”
    is already in the database under the table of “myguestbook”..

    Here’s what i came up with…….

    $query = "SELECT * FROM myguestbook"; 
    
    // execute query
    $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
    
    // see if any rows were returned
     if (mysql_num_rows($result) > 0) {
        // yes
        // print them one after another
        echo "<table cellpadding=10 border=1>";
        while($row = mysql_fetch_row($result)) {
            echo "<tr>";
            echo "<td>"."<center>".$row[0]."</center>"."</td>";
            echo "<td>" . $row."</td>";
            echo "<td>".$row."</td>";
            echo "</tr>";
        } 
    
    }
    else {
        // no
        // print status message
        echo "No rows found!";
    }

    That displays the names inside of the table.. Now the question is.. How can I get the results a IF statement..
    Example

    <?php if ($row(0) = $current_user->logged_in) {
    //do something...
    } ?>

    In other words, im trying to check the current user who is logged in if they are in the database, If they are NOT in the database then //do something.. I know this is pretty simple.. atleast I would asume it is..

    [ Please do not bump, it’s not permitted here. ]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Check if there is data in table. Is my code Correct?’ is closed to new replies.