Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 09-12-2004, 03:40 PM   #1 (permalink)
jimmyoctane
Registered User
 
jimmyoctane's Avatar
 
Join Date: Sep 2003
Location: California
Posts: 26
jimmyoctane is on a distinguished road
Send a message via AIM to jimmyoctane
Wink Hello! Please forgive newbie question

I have the following SQL statement
Code:
$result=mysql_query("SELECT long_name, count(*) 
FROM  `userlog` 
GROUP  BY long_name
ORDER  BY long_name");
I can access the browser name with no problem.

Code:
for($i=0;$i<$num;$i++)
{
$thebrowser = mysql_result($result,$i,"long_name");
echo $thebrowser;
echo "&nbsp;&nbsp;&nbsp;&nbsp;";
echo "<br>";
}
how do I define/reference the count(*) field to display????


Thanks
Jimmy
jimmyoctane is offline   Reply With Quote
Old 09-12-2004, 04:44 PM   #2 (permalink)
jimmyoctane
Registered User
 
jimmyoctane's Avatar
 
Join Date: Sep 2003
Location: California
Posts: 26
jimmyoctane is on a distinguished road
Send a message via AIM to jimmyoctane
Okay I did this how wrong was that?????

I ended up doing this within the loop:


Code:
$result2=mysql_query("SELECT * 
FROM  `userlog` where long_name =  '$thebrowser' ");
$num2=mysql_numrows($result2);
What should I have done?

thanks
Jimmy
jimmyoctane is offline   Reply With Quote
Old 09-12-2004, 11:16 PM   #3 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,721
redhead is on a distinguished road
PHP Code:
$result=mysql_query("SELECT long_name, count(*) 
                     FROM  `userlog` 
                     GROUP  BY long_name
                     ORDER  BY long_name"
);
$row mysql_fetch_array($result);
echo 
"Long_name: " $row[0] ."<br>";
echo 
"Count: " $row[1] . "<br>";
mysql_free_result($result); 
But without any error checking.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 09-13-2004, 04:30 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,505
sde is on a distinguished road
alternatively you can rename count(*) in your query:
PHP Code:
$result mysql_query("select long_name,count(*) as count 
      from userlog
      group by long_name
      order by long_name"
); 
now you can use mysql_result($result,$i,"count");

however, as redhead included in his example above, i prefer to use mysql_fetch_array() like so:
PHP Code:
while($row mysql_fetch_array($result)){
  echo 
"browser: ".$row['long_name']." /  count: ".$row['count']."<br>\n";

welcome back mr. octane, .. haven't seen ya in a while.
__________________
Mike
sde is offline   Reply With Quote
Old 09-13-2004, 06:33 AM   #5 (permalink)
jimmyoctane
Registered User
 
jimmyoctane's Avatar
 
Join Date: Sep 2003
Location: California
Posts: 26
jimmyoctane is on a distinguished road
Send a message via AIM to jimmyoctane
Thanks Redhead and SDE

See what happend when you get an old green screen programmer hacking with a PC language.

Like a one legged man in a A$$ kicking contest...


SDE - I will be calling you soon bout that other thing



Great to be back with all my stuff working again



Take care
Jimmy
jimmyoctane is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
DB Design Question Part II sde Program Design and Methods 10 09-02-2008 11:37 AM
Would you mind if there were small flash elements at code newbie? sde Lounge 10 05-29-2004 09:05 PM
Another newbie question. Odoggy5 PHP 26 09-03-2003 02:19 PM
Newbie question. p0etsou1 Standard C, C++ 9 06-24-2003 07:47 AM
Newbie Site ? DesertWolf Java 2 12-05-2002 12:38 PM


All times are GMT -8. The time now is 03:12 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting