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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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" = @. |
|
|||
|
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, > > > |