So in my database "project" i have tables courses,courses2,courses and participants,participants2,participants3 and company.
On page company.php i have a print link where he send me on a page named print.php ,where i can see the participants.
Now on print.php i can see only participants from courses and participants ,i want to see from all tables the participants and courses ,so i need a JOIN table or UNION.

The green is participants and red is the course where he joined to participate.
http://b.imagehost.org/0199/Untitled_Document_1289728620419.png

This is my php code from print.php/
PHP CODE:

code:

<? $select_cursuri=mysql_query('select * from cursuri');

      if (isset($id))

      {

         $select_cursuri=mysql_query('select * from cursuri where id_curs = '. $id );

      }

         while ($curs=mysql_fetch_array($select_cursuri)) {

         $id_curs=$curs['id_curs'];

         $select_participanti=mysql_query('select * from participanti where id_firma=' . $id_firma . ' and id_curs=' . $id_curs);

         

         if (mysql_num_rows($select_participanti)!=0) {

         ?>

    <? while ($participant=mysql_fetch_array($select_participanti)) { ?>

      <tr>

        <td>&nbsp;</td>

        <td width="12%" class="style24"><? echo $participant['nume']; ?></td>

        <td width="17%" class="style24"><? echo $participant['prenume']; ?></td>

        <td width="17%" class="style24"><? echo $participant['functie']; ?></td>

        <td width="18%" class="style24"><? echo $participant['mobil']; ?></td>

        <td class="style24"><? echo $participant['hotel']; ?></td>

        <td class="style24"><? echo $participant['plata'] ?></td>



        <td class="style24"><? echo $participant['discount']; ?></td>

        <td>&nbsp;</td>

      </tr>

      <? } } } ?>

Recommended Answers

All 4 Replies

SELECT * FROM table1, table2, tablen WHERE table1.primarykeycolumn=table2.foreignkeycolumn AND table4.primarykeycolumn=table3.foreignkeycolumn AND (follows all relations between columns )

$select_participanti=mysql_query('select * from participanti where id_firma=' . $id_firma . ' and id_curs=' . $id_curs);

will look like

$select_participanti=mysql_query('select * from table1,table2...tablen where table1.id_firma=table2.id_firma and ...);

Thanks worked like a charm.

Dont forget to mark this as solved

You can checkup mysql multiple selct query from mysql website.
1.left join
2. inner join
3.right join

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.