简体   繁体   中英

List records in mysql using php but only one record appear?

<tbody>
    <?php
    $teacher_subject_query = mysql_query("select * from teacher_suject where teacher_id='$session_id'") or die(mysql_error());
    $teacher_row = mysql_fetch_array($teacher_subject_query);
    $subject_id = $teacher_row['subject_id'];

    $query = mysql_query("select * from subject where subject_id = '$subject_id'") or die(mysql_error());
    while ($row = mysql_fetch_array($query)) {
        $id = $row['subject_id'];
        ?>
           <!-- script -->
    <script type="text/javascript">
        $(document).ready(function(){

            $('#d<?php echo $subject_id; ?>').tooltip('show')
            $('#d<?php echo $subject_id; ?>').tooltip('hide')
        });
    </script>
    <!-- end script -->
    <!-- script -->
    <script type="text/javascript">
        $(document).ready(function(){

            $('#e<?php echo $subject_id; ?>').tooltip('show')
            $('#e<?php echo $subject_id; ?>').tooltip('hide')
        });
    </script>
    <!-- end script -->

        <tr class="odd gradeX">

            <td><?php echo $row['subject_code']; ?></td> 
            <td><?php echo $row['subject_title']; ?></td> 

These is the code I use but only one record is showing in the system and I need to show it all! Thanks in advance!

There must be only one record matching your query:

$query = mysql_query("select * from subject where subject_id = '$subject_id'") or die(mysql_error());

You are fetching a specific subject by id.

use

$teacher_subject_query = mysql_query("select * from teacher_suject") or die(mysql_error());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM