Pregunta

Working on this for 2 months and thought I would finally ask a question. I have 2 tables:

table 1:(teacher registration) code teacher 1 Smith 2 Allen

table 2:(student registration) code student stdpassword 1 Jan abc78 2 Cindy jhni 1 Peter e99bd 1 Bobby h2y1e 1 Marsha huhu1

This is what I want the teacher with code 1 to see in the retrieved data on the webpage:

studentname studentpassword Bobby h2y1e Jan abc78 Marsha huhu1 peter e99bd

I would like the teacher to retrieve all their student names and passwords using the code during the teachers session. This is what I have so far. Any help is welcomed.

$query = mysql_query("SELECT * FROM studentregistration WHERE code = $_SESSION[code]"); $query = mysqli_query($dbcon, $query) or die ('error getting data');

while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
    echo "<tr><td>";
    echo $row['stdname'];
    echo "</td><td>";
    echo $row['stdpassword'];
    echo "</td></tr>";
    }

echo "";

¿Fue útil?

Solución

Try this, Remove mysql_query from select query

$sql = "SELECT * FROM studentregistration WHERE code = '".$_SESSION[code]."' " ; 
$query = mysqli_query($dbcon, $sql) or die ('error getting data');

instead of

$query = mysql_query("SELECT * FROM studentregistration WHERE code = $_SESSION[code]"); 
      ......^
$query = mysqli_query($dbcon, $query) or die ('error getting data');
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top