0

I have tried every single expalnation on this but I keep getting errors please help me out guys this might have been answered but its over a week I keep struggleing with it.

I have two Tables

Student and Certificate the two tables have a relationship on student, i have a unique column student reg no and on certificate student reg which are bot the same values.

I am trying to select data from the two table into a table in html but its not working

here is my statement

<?php 
    $sql = "SELECT * s.studentsregno
                     s.fullname
                     s.program
                     c.certificateno AS cert_no
                     c.dateofissue AS date_ofissue
                     c.status AS pick_status
           FROM student s
           JOIN certificate c on c.studentreg = s.studentregno";

   $result = $db->query($sql);
   if ($result->num_rows > 0) {
       // output data of each row
       while($row = $result->fetch_assoc()){

           echo
               '<tr class="odd gradeX">
                    <td>'.$row["studentregno"].'</td>
                    <td>'.$row["fullname"].'</td>
                    <td>'.$row["program"].'</td>
                    <td class="center">'.$row["cert_no"].'</td>
                    <td class="center">'.$row["date_ofissue"].'</td>
                    <td class="center">Picked</td>
                </tr>';
        }
    } 
    $db->close();
?>
Alex Weitz
  • 3,199
  • 4
  • 34
  • 57
  • 1
    "but its not working" , We will need more information than that, whats not working? – sagi Mar 13 '16 at 10:50
  • I am getting this error Notice: Trying to get property of non-object in C:\xampp\htdocs\cis\pages\index.php on line 156 – Sebastian Gentanyi Mar 13 '16 at 10:53
  • Possible duplicate of [How to get mysqli error in different environments?](http://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-in-different-environments) – Your Common Sense Mar 13 '16 at 11:23

1 Answers1

0

Maybe try by adding some coma and not using * the other, something like this :

SELECT s.studentsregno, s.fullname, s.program, c.certificateno AS cert_no, c.dateofissue AS date_ofissue, c.status AS pick_status FROM student s JOIN certificate c on (c.studentreg = s.studentregno);

I'm not a big fan of renaming like this the table too so if it still doesn't work, try by remplacing s and c by the real table name and just use this surname when you really need it (a join beetween two from the same table)

Nicolas Frbezar
  • 497
  • 1
  • 5
  • 24