*强文本*我不知道标题是否清楚,
但我想要一个 PHP 脚本来告诉 MySQL 列是否有数据,如果它确实打印一行文本,但如果它是NULL,则打印其他内容......
有道理?
这就是我所拥有的,我知道这是完全错误的......
$link = mysql_connect($DBHOST, $DBUSER, $DBPASSWORD);
mysql_select_db($DBNAME);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$result = mysql_query("SELECT * FROM members");
while($row = mysql_fetch_assoc($result))
{
if($row['VIP'] = '1')
{
echo('VIP');
}
else
{
echo('Non-VIP');
}
}
编辑::
这是完整的代码:
<?php
$DBTYPE = 'mysql';
$DBHOST = 'host';
$DBUSER = 'username';
$DBPASSWORD = 'password';
$DBNAME = 'database';
$link = mysql_connect($DBHOST, $DBUSER, $DBPASSWORD);
mysql_select_db($DBNAME);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$member_id= '5'; // get value of the member, assumed that you have post the data into id. change if it is different into your code
$result = mysql_query("SELECT * FROM members where id=$member_id");
while($row = mysql_fetch_assoc($result))
{
if($row['VIP'] == '1')
{
echo "<img src='../images/VIP.png' />";
}
else
{
echo 'Non-VIP';
}
}
?>