Jump to content


Photo

count help pleasse cheers.


  • Please log in to reply
10 replies to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 10 June 2006 - 01:58 PM

count not working how cheers.

$qu="select * from count(member_messages) as r where id='$id'";
$re=mysql_query($qu);

echo "<table width='200'border='4' bordercolor='black'><td align='center'><b>Messages: 

<font color='red'>$r</b></font></td></table><br><br>";

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 10 June 2006 - 02:21 PM

I am only 50 percent sure but I think that in sql
select and from should be all caps.
and member_messages doesn't have the variable symbol in front of it.
Just some suggestions but I could be wrong.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 10 June 2006 - 02:36 PM

Your SQL query is wrong. You are using count on the table name and not the table row. Your query should be this:
$qu="SELLECT COUNT(*) FROM member_messages WHERE id='$id'";
If you want to use count on specific row do this:
$qu="SELECT *, COUNT(field_name) AS num FROM member_messages WHERE id='$id'";
change where it says field_name with the actuall field name in your table.

Businessman
SQL is forgiving if you use uppercase or lowercase for SQL keywords. I prefer to use uppercase with keywords in SQL queries.

#4 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 10 June 2006 - 02:39 PM

Ok so atleast hopefully he got the help he needed.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#5 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 10 June 2006 - 03:55 PM

[!--quoteo(post=382230:date=Jun 10 2006, 07:36 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 10 2006, 07:36 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$qu="SELECT *, COUNT(field_name) AS num FROM member_messages WHERE id='$id'";
change where it says field_name with the actuall field name in your table.

Businessman
SQL is forgiving if you use uppercase or lowercase for SQL keywords. I prefer to use uppercase with keywords in SQL queries.
[/quote]
Won't that throw an error like:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]#1140 - Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause [/quote]

But something like this should do:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] *, COUNT(field_name) AS num FROM member_messages WHERE id='$id'" GROUP BY field; [!--sql2--][/div][!--sql3--]

I prefer to use uppercase for keywords, but it's just "aesthetic". Kinda like indentation, you don't need it, but if you use it it makes the code more organized.
~ D Kuang

#6 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 10 June 2006 - 07:04 PM

also businessman, column and table names do not use $ in front of them, if you are using their name. for example, it would be
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--]$sql = "[span style=\'color:blue;font-weight:bold\']select * from tablename where name='[/span]blah'"; [!--sql2--][/div][!--sql3--]
not
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--]$sql = "[span style=\'color:blue;font-weight:bold\']select * from $tablename where $name='[/span]blah'"; [!--sql2--][/div][!--sql3--]
... unless you were like, working with multiple tables, and your script was going to query a specific table, or maybe your script would query a column dependant on something or whatever:

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--]$columnname = 'name';
$tablename= 'tablename';
$sql = "[span style=\'color:blue;font-weight:bold\']select * from $tablename where $columnname='[/span]blah'";
[!--sql2--][/div][!--sql3--]
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#7 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 10 June 2006 - 07:10 PM

[!--quoteo(post=382230:date=Jun 10 2006, 03:36 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 10 2006, 03:36 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Your SQL query is wrong. You are using count on the table name and not the table row. Your query should be this:
$qu="SELLECT COUNT(*) FROM member_messages WHERE id='$id'";
If you want to use count on specific row do this:
$qu="SELECT *, COUNT(field_name) AS num FROM member_messages WHERE id='$id'";
change where it says field_name with the actuall field name in your table.

Businessman
SQL is forgiving if you use uppercase or lowercase for SQL keywords. I prefer to use uppercase with keywords in SQL queries.
[/quote]
If you needed the row number of a general query would it not be better to

$sql = "SELECT * FROM `table` WHERE `field` = '$value'";
$result = mysql_query ($sql) or die (mysql_error ());
$rows = mysql_num_rows ($result);

I suppose a count is marginally better.

(this is of course if you want the row data and not just the number of rows)

In any case u have to take the $count_query result and do
$num_rows = mysql_result ($count_query, 0);
z..z..z..z..z..z..z..z..

#8 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 10 June 2006 - 07:12 PM

well, why make php do it when you can have sql do it? php specializes in manipulating the data. sql specializes in keeping track of it. so it is better for sql to tell you how many than php. and if you notice in the query, it is selecting the data also, not just getting the count.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#9 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 11 June 2006 - 12:37 PM

thanks every one but how do i get the num out cherrs

$qu="SELECT *, COUNT(messages) AS num FROM member_messages WHERE id='$id'";
$re=mysql_query($qu);


echo "<table width='200'border='4' bordercolor='black'><td align='center'><b>Messages: 

<font color='red'>$num</b></font></td></table><br><br>";


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#10 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 11 June 2006 - 12:48 PM

$qu="SELECT *, COUNT(messages) AS num FROM member_messages WHERE id='$id'";
$re=mysql_result (mysql_query ($qu), 0);
z..z..z..z..z..z..z..z..

#11 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 11 June 2006 - 01:03 PM

[!--quoteo(post=382480:date=Jun 11 2006, 12:48 PM:name=joquius)--][div class=\'quotetop\']QUOTE(joquius @ Jun 11 2006, 12:48 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$qu="SELECT *, COUNT(messages) AS num FROM member_messages WHERE id='$id'";
$re=mysql_result (mysql_query ($qu), 0);
[/quote]

solved cheers.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users