[PHP] i need some help with extracting data from mysql

2001-05-10 Thread Sandeep Hundal

hi all,

i've got a simple problem, yet it doesn't work, so i hope someone can
help me out here.

i've got a table with id, group, and name. each group has many names
ofcourse.

now i need to output the data like : 
 group1
   name1
   name2
   name3

group2
   name4
   name5

group3
   name6 
etc

my query is SELECT group, name FROM $tablename WHERE approved='yes'
GROUP BY folder ORDER BY folder;

yet the ouput can't seem to handle more than 1 name per group.

any ideas?? thanks in advance!

/sunny


Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] i need some help with extracting data from mysql

2001-05-10 Thread bill

Sandeep,

Try:

$sql=SELECT group, name FROM $tablename WHERE approved='yes'
ORDER BY group, name;

Don't know what fieldname folder is in your original SQL.  You said that
the table had only id, group,  name.  But I note that you must also have a
fieldname called approved.

In any case, assuming the fieldnames are correct, the above should work.

kind regards,

bill hollett


Sandeep Hundal wrote:

 hi all,

 i've got a simple problem, yet it doesn't work, so i hope someone can
 help me out here.

 i've got a table with id, group, and name. each group has many names
 ofcourse.

 now i need to output the data like :
  group1
name1
name2
name3

 group2
name4
name5

 group3
name6
 etc

 my query is SELECT group, name FROM $tablename WHERE approved='yes'
 GROUP BY folder ORDER BY folder;

 yet the ouput can't seem to handle more than 1 name per group.

 any ideas?? thanks in advance!

 /sunny

 
 Do You Yahoo!?
 Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
 or your free @yahoo.ie address at http://mail.yahoo.ie

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] i need some help with extracting data from mysql desperately!!

2001-05-10 Thread Sandeep Hundal

unfortunately, that doesn't seem to work either. it basically only gives me
on name per group. here's my php:

$query = SELECT * FROM $tablename WHERE approved='yes' GROUP BY group ORDER
BY group, name;
$result2 = mysql_query($query2);
  if ($result2) {
while ($r2 = mysql_fetch_array($result2)) {
extract($r2);
   echo 
 strong$folder/strongbr
 nbsp;nbsp;$name br;
  }
}

all it does is print out one name per group, and if there is more than one
name in a group, it comes up sperately (but the group name goes missing).


basically i need this:
  group1
name1
name2
name3

 group2
name4
name5

thanks for any help, i'm sure this is something really straightforward, but
i can't put my finger to it

tia!

/sunny


-Original Message-
From: bill [mailto:[EMAIL PROTECTED]]
Sent: 10 May 2001 14:58
To: [EMAIL PROTECTED]
Subject: Re: [PHP] i need some help with extracting data from mysql


Sandeep,

Try:

$sql=SELECT group, name FROM $tablename WHERE approved='yes'
ORDER BY group, name;

Don't know what fieldname folder is in your original SQL.  You said that
the table had only id, group,  name.  But I note that you must also have a
fieldname called approved.

In any case, assuming the fieldnames are correct, the above should work.

kind regards,

bill hollett




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] i need some help with extracting data from mysql desperately!!

2001-05-10 Thread Sandeep Hundal

doh! i just realised the difference in $query number, but thats not an issue
in the actual code, i just cleaned that up a bit

/sunny


-Original Message-
From: Sandeep Hundal [mailto:[EMAIL PROTECTED]]
Sent: 10 May 2001 16:49
To: 'bill'; [EMAIL PROTECTED]
Subject: [PHP] i need some help with extracting data from mysql
desperately!!


unfortunately, that doesn't seem to work either. it basically only gives me
on name per group. here's my php:

$query = SELECT * FROM $tablename WHERE approved='yes' GROUP BY group ORDER
BY group, name;
$result2 = mysql_query($query2);
  if ($result2) {
while ($r2 = mysql_fetch_array($result2)) {
extract($r2);
   echo 
 strong$folder/strongbr
 nbsp;nbsp;$name br;
  }
}

all it does is print out one name per group, and if there is more than one
name in a group, it comes up sperately (but the group name goes missing).


basically i need this:
  group1
name1
name2
name3

 group2
name4
name5

thanks for any help, i'm sure this is something really straightforward, but
i can't put my finger to it

tia!

/sunny


-Original Message-
From: bill [mailto:[EMAIL PROTECTED]]
Sent: 10 May 2001 14:58
To: [EMAIL PROTECTED]
Subject: Re: [PHP] i need some help with extracting data from mysql


Sandeep,

Try:

$sql=SELECT group, name FROM $tablename WHERE approved='yes'
ORDER BY group, name;

Don't know what fieldname folder is in your original SQL.  You said that
the table had only id, group,  name.  But I note that you must also have a
fieldname called approved.

In any case, assuming the fieldnames are correct, the above should work.

kind regards,

bill hollett




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] i need some help with extracting data from mysql

2001-05-10 Thread Steve Werby

Sandeep Hundal [EMAIL PROTECTED] wrote:
 i've got a simple problem, yet it doesn't work, so i hope someone can
 help me out here.

 i've got a table with id, group, and name. each group has many names
 ofcourse.

Are these *all* of the field names?

 now i need to output the data like :
  group1
name1
name2
name3

 group2
name4
name5

 group3
name6
 etc

 my query is SELECT group, name FROM $tablename WHERE approved='yes'
 GROUP BY folder ORDER BY folder;

You lost me.  Where is the field folder?  Can you output the results of
DESCRIBE tablename for the table and a few records?

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] i need some help with extracting data from mysql

2001-05-10 Thread Sandeep Hundal



-Original Message-
From: Steve Werby [mailto:[EMAIL PROTECTED]]
Sent: 10 May 2001 17:04
To: Sandeep Hundal; php
Subject: Re: [PHP] i need some help with extracting data from mysql


Sandeep Hundal [EMAIL PROTECTED] wrote:
 i've got a simple problem, yet it doesn't work, so i hope someone can
 help me out here.

 i've got a table with id, group, and name. each group has many names
 ofcourse.

Are these *all* of the field names?

Sorry, some typo errors, i got confused. The field names are : id, group,
name, approved.

 now i need to output the data like :
  group1
name1
name2
name3

 group2
name4
name5

 group3
name6
 etc

 my query is SELECT group, name FROM $tablename WHERE approved='yes'
 GROUP BY folder ORDER BY folder;

Sorry, substitute folder for Group. I just wrote that by mistake.

Data is such:
1 | friends | name1 | yes
2 | misc| name2 | yes
3 | friends | name3 | yes
4 | work| name4 | no

I want to extract the ones approves, but list them by Group first, and all
the relevant names after. But I dont want to run a query for each GROUP to
output the data underneath it.

TIA


/sunny

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] i need some help with extracting data from mysql

2001-05-10 Thread Steve Werby

Sandeep Hundal [EMAIL PROTECTED] wrote:
  my query is SELECT group, name FROM $tablename WHERE approved='yes'
  GROUP BY folder ORDER BY folder;

 Sorry, substitute folder for Group. I just wrote that by mistake.

 Data is such:
 1 | friends | name1 | yes
 2 | misc| name2 | yes
 3 | friends | name3 | yes
 4 | work| name4 | no

 I want to extract the ones approves, but list them by Group first, and all
 the relevant names after. But I dont want to run a query for each GROUP to
 output the data underneath it.

You don't need to GROUP the records b/c you're not performing any kind of
aggregate operation on them.  Use the following query:

SELECT group, name
FROM tablename
WHERE approved = 'yes'
ORDER BY group

Use PHP to loop through each record like you normally would.  Since you want
the group on a line by itself and then all of the names that are members of
the group one per line below it you should do something like the following
(I assume you're outputting in HTML, if not replace all 'br' tags with
\n):

while ( $row = mysql_fetch_array( $sql ) )
{
$group = $row['group'];
$name = $row['name'];

if ( $group != $group_previous )
{
echo $group . 'br';
}

echo $name . 'br';
$group_previous = $group;
}

By setting $group_previous equal to $group *after* looping through each row
it can be compared to $group so that you only display the group name when it
doesn't match the $group of the previous row.  I think this is what you
wanted.  If I misinterpreted what you were trying to do let me know.

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]