Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

PHP/MySQL

Name: Anonymous 2009-09-09 12:15

Hi guys, I hope someone can help me out here.
I'm trying to count how many records there are in my "voc" table where the "kan" cell is not empty.

When I execute my code I get "Query was empty"

$sql = "SELECT COUNT(nl) FROM voc WHERE kan IS NOT NULL";
  $result = mysql_query($query) or die(mysql_error());

        while($obj = mysql_fetch_object($result)) {
        echo "<h1>" . $obj['COUNT(nl)'] ."</h1>";
        }

Name: Anonymous 2009-09-09 12:22

"!=" instead of "IS NOT", I think...

Name: Anonymous 2009-09-09 12:26

use perl/postgres instead.

Name: OP 2009-09-09 12:36

Allright, someone on IRC helped me, I used $query but defined $sql
the problem is now that it doesn't seem to care about
WHERE kan IS NOT NULL
it's returning everything, including the ones that are empty

Name: Anonymous 2009-09-09 13:56

>>4
Learn the difference between NULL and "", and then stop programming forever.

Name: Anonymous 2009-09-09 14:59

>>3
Seconded.

Name: Anonymous 2009-09-09 15:07

Use Python/SQLite instead.

Name: Anonymous 2009-09-09 16:09

Use C/SQLite instead

Name: Anonymous 2009-09-09 17:43

Just need the LA part now.

Name: Anonymous 2009-09-09 17:46

Sorry, I'm part of the NoSQL movement.

Name: Anonymous 2009-09-09 18:35

I use Perl/Flat-file+Tie::File.

Name: Anonymous 2009-09-09 18:47

>>4
OP, if you have cases where kan = '', then your query will still retrieve those.  use

WHERE kan IS NOT NULL
AND kan != ''

to exclude both cases

Name: Anonymous 2009-09-09 19:19

Use Expat/XML instead.

Name: Anonymous 2009-09-09 20:47

>>3,11
The only difference between Perl and PHP is fundamentalist Christianity.

Name: Anonymous 2009-09-09 20:54

>>14
The only difference between Perl and PHP is PHP was written in Perl.

Name: Anonymous 2009-09-09 22:42

>>15
PHP is written in C. I know this because whenever I doubt my capabilities as a programmer, I look at the PHP source to remind myself that I could be much, much worse.

Name: Anonymous 2009-09-09 22:50

gotta love those zvals

Name: Anonymous 2009-09-09 23:16

>>16
What's wrong with PHP's source?

Name: Anonymous 2009-09-10 0:02

>>15
was
Please read attentively.

Don't change these.
Name: Email:
Entire Thread Thread List