newbie question on count()

This is a discussion on newbie question on count() within the PHP Language forums, part of the PHP Programming Forums category; I have been driving myself crazy for hours now on a simple (I thought) little deal. I've given up ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-18-2003
Karzy
 
Posts: n/a
Default newbie question on count()

I have been driving myself crazy for hours now on a simple (I thought)
little deal. I've given up and come for some help. Below is my code
snippet. When the count returns 0 it doesn't print 0, but instead wipes
out everything on my screen. All I want is for it to print 0 when
appropriate.

<connect>
$sql = "select count(print_id) FROM new_table, players WHERE
players.player_id = new_table.player_id and grad_year = '2003-2004' and
contact_coach = '' and eval_rank not in ('0','8','9')";

$result = @mysql_query($sql, $connection) or die(mysql_error());

$count_ua = @mysql_result($result,0,"count(print_id)") or die
(mysql_error());
<disconnect>

<li><a href="unassigned_coach.php">Unassigned People In System:</a> <b>
<?PHP echo "$count_ua"; ?></b></li>

Thanks for any help. I really appreciate it.
Mike

Reply With Quote
  #2 (permalink)  
Old 09-18-2003
Jon Trelfa
 
Posts: n/a
Default Re: newbie question on count()

On Thu, 18 Sep 2003 02:19:53 +0000, Karzy wrote:

> $sql = "select count(print_id) FROM new_table, players WHERE
> players.player_id = new_table.player_id and grad_year = '2003-2004' and
> contact_coach = '' and eval_rank not in ('0','8','9')";
>
> $result = @mysql_query($sql, $connection) or die(mysql_error());
>
> $count_ua = @mysql_result($result,0,"count(print_id)") or die
> (mysql_error());



How about these changes?

<snip>

$sql = "SELECT count(new_table.print_id) FROM new_table, players...

<snip>

$count_ua = mysql_result($result,0);

<snip>


You don't have to specify the column you're requesting because you're
pulling 1 column from your data set. Also, you'll notice that the column
name in your SQL query should be defined by its parent table since you're
pulling from multiple tables (this is a join type of query).

HTH,


--
Jon Trelfa
Registered Linux User #164332
There 10 kinds of people in this world...
Those who understand binary and those who don't
Reply With Quote
  #3 (permalink)  
Old 09-18-2003
Jan Pieter Kunst
 
Posts: n/a
Default Re: newbie question on count()

In article <MPG.19d2d261757060479896c2@netnews.mchsi.com>,
Karzy <mkarr@mchsi.com> wrote:

> $result = @mysql_query($sql, $connection) or die(mysql_error());
>
> $count_ua = @mysql_result($result,0,"count(print_id)") or die
> (mysql_error());


I don't have a solution, but I have a (general) tip: leave out those @
signs before function calls when you are debugging. You are probably
supressing helpful error messages.

JP

--
Sorry, <devnull@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Reply With Quote
  #4 (permalink)  
Old 09-18-2003
Karzy
 
Posts: n/a
Default Re: newbie question on count()

In article <pan.2003.09.18.03.09.57.243000@nobleaccord.com> ,
treefrog@nobleaccord.com says...
> On Thu, 18 Sep 2003 02:19:53 +0000, Karzy wrote:
>
> > $sql = "select count(print_id) FROM new_table, players WHERE
> > players.player_id = new_table.player_id and grad_year = '2003-2004' and
> > contact_coach = '' and eval_rank not in ('0','8','9')";
> >
> > $result = @mysql_query($sql, $connection) or die(mysql_error());
> >
> > $count_ua = @mysql_result($result,0,"count(print_id)") or die
> > (mysql_error());

>
>

Thanks a bunch. Now I can sleep peacefully.

Mike

> How about these changes?
>
> <snip>
>
> $sql = "SELECT count(new_table.print_id) FROM new_table, players...
>
> <snip>
>
> $count_ua = mysql_result($result,0);
>
> <snip>
>
>
> You don't have to specify the column you're requesting because you're
> pulling 1 column from your data set. Also, you'll notice that the column
> name in your SQL query should be defined by its parent table since you're
> pulling from multiple tables (this is a join type of query).
>
> HTH,
>
>
>

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:14 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0