some help building and displaying an array from mySQL content?

Started by Kindred, February 26, 2016, 04:01:33 PM

Previous topic - Next topic

Kindred

mySQL table: ID, name, rank, position, ship, crew
JOINED to crew table which lists the TEXT version of the crew-type identified as an integer in the first table (based on ID).


$sql = "SELECT c.name AS charname, c.rank, c.position, c.crew, c.ship, c.notes, c.classified, u.name AS crewname FROM chars AS c INNER JOIN crews as u ON c.crew=u.ID WHERE c.ship=1";


that works great. I put it all into an array... no problem.

but then, I want to GROUP the individuals by their identified crew
sam - flight crew (ID=1)
joe - flight crew (ID=1)
bob - science staff (ID=2)
tom - passenger (ID=4)
tim - passenger (ID=4)

I want this displayed as
Flight Crew
-------------
sam
joe

Science Staff
----------------
bob

Passenger
-------------
tom
tim


I figured I would use a foreach...  but that's not quite working (at all)



any ideas?
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

margarett

Why not just perform a different select for each crew type?
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Kindred

but how would I do that?

I don't know how many crew types will be on each ship.
Some might have just flight crew, while others may have flight crew and marines...  or passengers, etc
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

live627

don't need to modify the query.. Use a multidimensional array--keys are crew names and values are array of peoples.

Kindred

hmmm....  ok, that makes sense and matches what I originally thought...

but how do I load the SQL results into a multidimensional array?

I looked through some of the online stuff and didn't see anything that jumped out at me as an explanation/code snip which I could crib

As I have previously commented, a bunch of times...   once I SEE code, I usually can understand it and hack it to do what I want -- but my code writing is really really really rusty   :(   I'm not a developer... lol
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."


Advertisement: