Forum Moderators: coopster

Message Too Old, No Replies

Not sure how to start this

suggestions please

         

someone

10:18 pm on Nov 16, 2005 (gmt 0)

10+ Year Member



I have a couple thousand rows of data like this:

Book_num Title Price Category Abstract
b158 PHP 5 101 PHP is cool
b158 PHP 5 203 PHP is cool
b158 PHP 5 309 PHP is cool
c201 C+ 10 102 Learn C+
c201 C+ 10 212 Learn C+
C201 C+ 10 366 Learn C+

the list goes on and on..........

As you can see, the three rows of data for b158 are pretty much identical except for the Category column. Same thing with c201. So what I want to do is to create a script with PHP so that it will automatically delete the extra rows of each Book_num and merge the different Category number together. I want it to be like this:

Book_num Title Price Category Abstract
b158 PHP 5 101,203,309 PHP is cool
c201 C+ 10 102,212,366 Learn C+

I am not sure how to start the coding so any ideas would be appreciated. Thanks.

coopster

5:12 am on Nov 17, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You don't really want to DELETE the rows from the database, do you? You mean that you want the output formatted as specified from the existing rows, leaving the rows intact, correct?

Your best bet would be to loop through the rows and monitor for a change in the primary key, building a new variable or array from the categories. Or, if you are using MySQL, you could give GROUP_CONCAT a whirl. I found a couple of old threads that may be relative:

[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]

dmmh

6:57 am on Nov 17, 2005 (gmt 0)

10+ Year Member



personally I dont see any issues at all with deleting the extra rows?
Most of it is, in it current form, redundant data, especially considering the amount he has it in :)

ofcourse he should be carefull and test this on a test table first, but personally I would chose his way...

coopster

11:57 am on Nov 17, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I didn't mean it that way, dmmh. I was looking for confirmation on terminology used in the post relative to desired result.

Although I'm not entirely certain of the entire layout, size, and purpose of the table, you may have an good basis for your observation.

someone

4:27 pm on Nov 17, 2005 (gmt 0)

10+ Year Member



I want to delete the extra rows. currently i have a table in mysql with thousands of redundant data like what I mentioned. I'll find out what GROUP_CONCAT can do and anymore ideas is very much appreciated.