0

我有一个包含列的表的数据库,...player1player2player3player12

我需要检查某行中的列player1是否为空。

这是我在join.php中的内容:

<?php
require 'connect.inc.php';
$playername = $_GET['name'];
$tour_name = $_GET['tourname'];

if (isset($playername)&&
    isset($tour_name)) {
$query = "SELECT `tour_name` FROM `tournies` WHERE `tour_name` = '$tour_name'";
$query_run = mysql_query($query);

echo mysql_error();
//mysql_query("UPDATE `tournies` SET player1='".$playername."' WHERE tour_name='".$tour_name."'");
if ($query_run = mysql_query($query)) {
    header('Location: s.php');
    } else {
    echo 'not a win.';
    echo mysql_error();
    }
    } else {
echo 'Invalid username or tournament ID, please return to <a href="index.php">Home</a> and try again. Sorry.';
}
?>
4

3 回答 3

0

在你的 while 循环内

    if($row['player1']==''){
     //your logic
    }
于 2014-03-25T09:08:50.217 回答
0

我建议您使用MySQLi而不是它的前身MySQL。这是可能对您有所帮助的代码:

连接.inc.php

<?php

$connection=mysqli_connect("YourHost","YourUsername","YourPassword","yourDatabase");

if(mysqli_connect_errno()){

echo "Error".mysqli_connect_error();
}

?>

加入.php

<?php

include('connect.inc.php');

if(empty($_GET['name']) || empty($_GET['tourname']){ /* IF THERE'S NOTHING TO GET */
header("LOCATION:OtherPage.php"); /* USER WILL BE REDIRECTED TO OTHER PAGE */
}

else { /* ELSE IF NOT EMPTY */

$playername = $_GET['name'];
$tour_name = $_GET['tourname'];

$query = mysqli_query($connection,"SELECT `tour_name` FROM `tournies` WHERE `tour_name` = '$tour_name'");

while($row=mysqli_fetch_array($query)){

if(empty($row['player1'])){ /* IF EMPTY PLAYER1 COLUMN */
echo "Player 1 is empty";
} /* END OF IF EMPTY PLAYER1 */

else { /* IF NOT EMPTY */

echo "Player 1 is ".$row['player1'];

} /* END OF ELSE */

} /* END OF WHILE LOOP */

?>
于 2014-03-25T09:02:10.813 回答
0

如果您只需要查找一行是否为空,您只需使用 <> '' 之类的语句来仅加载具有值的行或 = '' 来加载空行;前任。tour_nametournies哪里选择tour_name= '';

于 2013-09-04T01:52:19.357 回答