Colmuns of information from row of data PHP/MySQL

I need to select four rows of data from on table and then create four columns from those four results. Here’s what I’m trying to accomplish:

MEMBER1 PROFILE | MEMBER2 PROFILE | MEMBER3 PROFILE | MEMBER4 PROFILE


MEMBER1 TABLE2 | MEMBER1 TABLE2 | MEMBER1 TABLE2 | MEMBER1 TABLE2
MEMBER1 TABLE3 | MEMBER1 TABLE3 | MEMBER1 TABLE3 | MEMBER1 TABLE3
MEMBER1 TABLE4 | MEMBER1 TABLE4 | MEMBER1 TABLE4 | MEMBER1 TABLE4

I can get the “profile” row no problem but I can’t think of how to make sure the data in the columns below row one is from the same member as row 1.

What I have is a JOIN that returns the data I need into a row. What I need is to split it into columns so that the data beneath each “header” is all the data from the row but printed as a column.

[php]$query2 = “SELECT videos.proid, videos.code, videos.views, pros.id, videos.qid, questions.question, pros.fname, pros.lname FROM videos INNER JOIN pros ON pros.id = videos.proid INNER JOIN questions ON videos.qid = questions.id”;
$result2 = mysql_query($query2) or die(mysql_error());
while($row = mysql_fetch_array($result2)){
$proid = $row[0];
$code = $row[1];
$views = $row[2];
$id = $row[3];
$qid = $row[4];
$question = $row[5];
$fname = $row[6];
$lname = $row[7];[/php]

I have tried several methods and I see some discussion about it but I’m not finding the solution. Any clues?

Well, I would do separate queries. Pull the members profiles first into one array.
Then, a second query for each member’s profile in the array and display the data as needed.
Or, you could create a more complicated code to check each item, but a second query if faster.
(And, easier!) Just do another query using “WHERE proid=‘some value from first query’” in the
query. Then, display that data and move onto the next one to display. Should be easy to do.

Hope that idea helps…

(also, if you really want to do it thru code, you could sort the array by ‘proid’ and then parse thru
them changing displays when the ‘proid’ changes. A bit harder to code, but, not too complicated…)

Thanks for sharing…! :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service