Displaying SQL Results
am 08.09.2006 20:58:46 von John Martinez
------=_Part_49209_23809691.1157741926890
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hi all,
Can anyone tell me what the syntax would be to display or gather the results
of this SQL?
SELECT MAX(user), COUNT(*) FROM my_table GROUP BY user ASC;
$sql_records = "SELECT MAX(user), email, COUNT(*) FROM my_table GROUP BY
user ;";
if($result = $db->sql_query($sql_records))
{
// fetch associative array
while($row = $db->sql_fetchrow($result))
{
[INSERT CODE HERE, I want to display the 'user' and 'count']
}
$db->sql_freeresult($result);
}
Thanks for any help!
J
------=_Part_49209_23809691.1157741926890--
RE: Displaying SQL Results
am 08.09.2006 21:17:12 von Bastien Koert
try
while($row = $db->sql_fetchrow($result))
{
//[INSERT CODE HERE, I want to display the 'user' and 'count']
$user = $row[0];
$count = $row[1];
}
bastien
>From: JM
>To: php-db@lists.php.net
>Subject: [PHP-DB] Displaying SQL Results
>Date: Fri, 8 Sep 2006 11:58:46 -0700
>
>Hi all,
>Can anyone tell me what the syntax would be to display or gather the
>results
>of this SQL?
>
>SELECT MAX(user), COUNT(*) FROM my_table GROUP BY user ASC;
>
>$sql_records = "SELECT MAX(user), email, COUNT(*) FROM my_table GROUP BY
>user ;";
>
>if($result = $db->sql_query($sql_records))
>{
>// fetch associative array
> while($row = $db->sql_fetchrow($result))
> {
>
> [INSERT CODE HERE, I want to display the 'user' and 'count']
>
> }
> $db->sql_freeresult($result);
>}
>
>
>
>Thanks for any help!
>
>J
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Displaying SQL Results
am 08.09.2006 21:22:38 von John Martinez
------=_Part_49537_19782648.1157743358710
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Thanks for the quick reply. Actually I figured it out by using aliasing:
$sql_records = "SELECT MAX(user) AS user_name, email, COUNT(user) AS
user_count FROM table_1 GROUP BY user DESC LIMIT 10;";
print $row["user_name"] . " - " . $row["user_count"];
This will display the top 10 users in descending order.
On 9/8/06, Bastien Koert wrote:
>
> try
>
> while($row = $db->sql_fetchrow($result))
> {
>
> //[INSERT CODE HERE, I want to display the 'user' and 'count']
> $user = $row[0];
> $count = $row[1];
>
> }
>
> bastien
>
>
> >From: JM
> >To: php-db@lists.php.net
> >Subject: [PHP-DB] Displaying SQL Results
> >Date: Fri, 8 Sep 2006 11:58:46 -0700
> >
> >Hi all,
> >Can anyone tell me what the syntax would be to display or gather the
> >results
> >of this SQL?
> >
> >SELECT MAX(user), COUNT(*) FROM my_table GROUP BY user ASC;
> >
> >$sql_records = "SELECT MAX(user), email, COUNT(*) FROM my_table GROUP BY
> >user ;";
> >
> >if($result = $db->sql_query($sql_records))
> >{
> >// fetch associative array
> > while($row = $db->sql_fetchrow($result))
> > {
> >
> > [INSERT CODE HERE, I want to display the 'user' and
> 'count']
> >
> > }
> > $db->sql_freeresult($result);
> >}
> >
> >
> >
> >Thanks for any help!
> >
> >J
>
>
>
------=_Part_49537_19782648.1157743358710--