PHP & SQL Query

From: Date: Mon, 11 Sep 2000 14:26:01 +0000
Subject: PHP & SQL Query
Groups: php.general 
Request: Send a blank email to php-general+get-16182@lists.php.net to get a copy of this message
Hi all I've got a bit of a confusing problem (for me!) that I wondered if anyone could help with. A database that has been set up where I work has a couple of design faults which I'm trying to get round with a bit of clever PHP programming. It has a 'Customer' table with their unique customer number and a 'Customer_details' table that has many records for the same user (address, phone number etc) and these records are linked by that unique 'custnumber' which is not a unique key anymore in this table. I need to extract the town of certain customers which I have successfully got the 'custnumber' for, and group them by the town name (stored in a record called details) with a count('details') next to it. The problem I am having is grouping the results correctly, If I use a normal while loop then it only counts up to 1 before the loop restarts using the next custnumber... Here is the sql code I am using in the loop: $sql = "select count(town),town from cust_details where custnumber = /"$custnumber/" group by town"; I know this is wrong as it will keep running in the loop for each custnumber and therefore the count is completely useless and always 1. Can anyone help? I hope I explained it well enough, it was quite difficult! ;) Thanks Paul

« previous php.general (#16182) next »