开发者

Having a link URL dependent on whether or not a row exists in a MySQL table

开发者 https://www.devze.com 2023-04-03 00:33 出处:网络
I have a MySQL table called blocks with the following fields: blockid blocker开发者_StackOverflowloginid

I have a MySQL table called blocks with the following fields:

blockid

blocker开发者_StackOverflowloginid

blockeeprofile

blockon

time

I would like to show www.url1.com if there is a row in the table that exists where blockerloginid = '$uid' and AND blockeeprofile = '$profile'

If there is not such a row, I would like to show www.url2.com.

How can I do this?


Easy enough SQL statement should sort it for ya

/* Code to connect to the database */

$sql = "SELECT * FROM blocks 
        WHERE blockerloginid = '$uid' AND blockeeprofile = '$profile'";

// Runs the query
$result = mysql_query($sql);

// Checks how many rows where found
$numRows = mysql_num_rows($result);

if($numRows == 1) {
     // 1 row found
    echo "www.url1.com";
} else {
    // No rows found
    echo "www.url2.com";
}

That should look for any rows in the table that have the uid and profile you specified. Assuming there should only be one with both of those values, it will check to see if the number of rows found was 1 or 0 and display the different links accordingly

0

精彩评论

暂无评论...
验证码 换一张
取 消