0

I am searching data from multiple tables in an SQL database and displaying in a PHP webpage.

However, I have an error :

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\projets\simple_veto\rdv_liste.php on line 71

Here is the query :

<table class="table table-sm table-dark">
    <tr>
        <th>Client</th>
        <th>Médecin</th>
        <th>Animal</th>
        <th>Cabinet</th>
        <th>Date</th>
        <th>Heure</th>
    </tr>
    <!-- Script de liste -->
<?php
//On recupere les informations
$req = mysql_query('SELECT rdv.client, rdv.medecin, rdv.animal, rdv.cabinet, client.nom, medecin.nom, animal.nom, cabinet.nom, date_rdv, time FROM client, medecin, animal, cabinet WHERE rdv.client=client.id_cli AND rdv.medecin=medecin.id_med AND rdv.animal=animal.id_ani AND rdv.cabinet=cabinet.id_cab');
while($dnn = mysql_fetch_array($req))
{
?>
    <tr>
        <td class="left"><?php echo htmlentities($dnn['client'], ENT_QUOTES, 'UTF-8'); ?></td>
        <td class="left"><?php echo htmlentities($dnn['medecin'], ENT_QUOTES, 'UTF-8'); ?></td>
        <td class="left"><?php echo htmlentities($dnn['animal'], ENT_QUOTES, 'UTF-8'); ?></td>
        <td class="left"><?php echo htmlentities($dnn['cabinet'], ENT_QUOTES, 'UTF-8'); ?></td>
        <td class="left"><?php echo htmlentities($dnn['date_rdv'], ENT_QUOTES, 'UTF-8'); ?></td>
        <td class="left"><?php echo htmlentities($dnn['time'], ENT_QUOTES, 'UTF-8'); ?></td>
    </tr>

<?php
}

For information,

My database is as follows :

Table rdv - containing the following rows : id_rdv,client, medecin, animal, cabinet, date_rdv, time

In this table:

  • client is a foreign key of -> table client
  • medecin is a foreign key of -> table medecin
  • animal is a foreign key of -> table animal
  • cabinet is a foreign key of -> table cabinet

A little help would be greatly appreciated,

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
Massivity
  • 11
  • 2

1 Answers1

0

If you know that all the information is in all the tables, you can use this: (But I dont know what is rdv)

if not all tables have information use LEFT JOIN or RIGHT JOIN instead of INNER JOIN

$query = "SELECT 
            rdv.client
          , rdv.medecin
          , rdv.animal
          , rdv.cabinet
          , client.nom
          , medecin.nom
          , animal.nom
          , cabinet.nom
          , date_rdv
          , time 
          FROM 
              client 
              INNER JOIN  rdv     ON rdv.client=client.id_cli
              INNER JOIN  medecin ON rdv.medecin=medecin.id
              INNER JOIN  animal  ON rdv.animal=animal.id_ani
              INNER JOIN  cabinet ON rdv.cabinet=cabinet.id_cab
          WHERE
              client.id_cli = ". $clientid;


$req = mysql_query($query);
Jjcc
  • 111
  • 3
  • Hello Josme,thank you for your answer, however, i don't understand the INNER JOIN function. I've tried this: ('SELECT rdv.client, rdv.medecin, rdv.animal, rdv.cabinet, client.nom, medecin.nom, animal.nom, cabinet.nom, date_rdv, time FROM rdv, client, medecin, animal, cabinet WHERE rdv.client=client.id_cli AND rdv.medecin=medecin.id_med AND rdv.animal=animal.id_ani AND rdv.cabinet=cabinet.id_cab'); But i still get the ID instead of the names as wanted – Massivity May 06 '18 at 12:46