-3

What I want to do is count all my filled rows of specific row name I select, let me give you an example:

Its like I have a table with 6 columns; the very first column is email - and the rest column are slot1, slot2, slot3, slot4, slot5.

Now what I want to have is a function that - when I select a specific email address - it returns how many slots are filled under that email address - just like when we use this command:

$t = select * from tabnlename where email=something 
mysql_fetch_array($t)
echo $t['slot1'] . $t['slot1'] and on and on ...

I want a function that counts how many slots are filled where email = mychoiceemail.

Let me give you some more details take a look at my sql table

supemail           slot1          slot2         slot3           slot4         slot5
opera@gmail.com   somedata       somedata       somedata        somedata       somedata
kaku@gmail.com     somedata                    somedata         somedata
nashu@gmail.com                  somedata

now what i want is when i select opera@gmail.com the function should return 5 as it has all 5 columns filled ! when i select kaku@gmail.com it should return 3 as it has 3 slots filled and when i select nashu@gmail.com it should return 1 only as it has only 1 slot filled !

4

3 回答 3

1

看看mysqli_query,那里有很多例子。

您的查询可能类似于:

select Count(*)
from MyTable
where email = $something
于 2012-09-11T18:47:23.587 回答
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";

?>
于 2012-09-11T18:49:45.653 回答
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
于 2012-09-11T19:20:55.917 回答