我想要做的是计算我选择的所有特定行名称的行,让我举个例子:
就像我有一个有6列的桌子;第一列是电子邮件 - 其余列是slot1,slot2,slot3,slot4,slot5。
现在我想要的是一个功能 - 当我选择一个特定的电子邮件地址时 - 它会返回在该电子邮件地址下填充的插槽数 - 就像我们使用此命令时一样:
$t = select * from tabnlename where email=something
mysql_fetch_array($t)
echo $t['slot1'] . $t['slot1'] and on and on ...
我想要一个计算email = mychoiceemail
填充了多少个广告位的函数。
让我再详细介绍一下我的sql表
supemail slot1 slot2 slot3 slot4 slot5
opera@gmail.com somedata somedata somedata somedata somedata
kaku@gmail.com somedata somedata somedata
nashu@gmail.com somedata
现在我想要的是当我选择opera@gmail.com时,该函数应该返回5,因为它已经填充了所有5列!当我选择kaku@gmail.com它应该返回3,因为它有3个插槽填充,当我选择nashu@gmail.com它应该返回1只因为它只有1个插槽填充!
答案 0 :(得分:1)
答案 1 :(得分:0)
http://php.net/manual/en/function.mysql-num-rows.php
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);
$result = mysql_query("SELECT * FROM table1 where email='stuff@email.com'", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows Rows\n";
?>
答案 2 :(得分:0)
如果我理解得好,也许你会找那样的东西 sql将是你的,并尝试下面的代码
if ($t['slot1'] == "" ) {$s1 = $t['slot1'] ;}
else {$s1notnull =$t['slot1'] ; }
if ($t['slot2'] == "" ) {$s2 = $t['slot2'] ;}
else {$s2notnull =$t['slot2'] ; }
if ($t['slot3'] == "" ) {$s3 = $t['slot3'] ;}
else {$s3notnull =$t['slot3'] ; }
if ($t['slot4'] == "" ) {$s4 = $t['slot4'] ;}
else {$s4notnull =$t['slot4'] ; }
if ($t['slot5'] == "" ) {$s5 = $t['slot5'] ;}
else {$s5notnull =$t['slot5'] ; }
$array_empty = array($s1, $s2, $s3, $s4, $s5);
$how_is_empty = count($array_empty);
希望它有所帮助
编辑。
select email,slot1 as s1, slot2 as s2, slot3 as s3, slot4 as s4, slot5 as s5, (count(s1+s2+s3+s4+s5)) from tabnlename where email=something