0

i have two table, member(user_id, username, profile_picture) and testimony(testimony_id, user_id, testimony_date, testimony_text). i want to retrieve data from those to table in testimony.php where it display (testimony_id, profile_picture, testimony_date, testimony_text). but it doesn't work and it display error in below.

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given

let me know what is wrong, thanks.

testimony.php

<head>
    <title>Testimony</title>
</head>

<body>
        <table border="1px">
        <tr>
            <td>id</td>
            <td>Profile Image</td>
            <td>Username</td>
            <td>Testimony Date</td>
            <td>Testimony Text</td>
        </tr>


        <?php


            include 'action/connect.php';

            $query = "SELECT b.user_id,                             
                             a.profile_image,
                             a.username,
                             b.testimony_date,
                             b.testimony_text
                             FROM testimony te
                             JOIN member me
                             ON me.user_id = te.user_id
                             WHERE te.testimony_id = 'testimony_id'";
            $rs = mysql_query($query);
            while($row = mysql_fetch_array($rs)){
        ?>

        <tr>
            <td><?= $row['testimony_id']  ?></td>
            <td> <img src="picture/profile_image/<?=$row['profile_image']?>.jpg" width="150px" height="150px" /> </td>
            <td><?= $row['username']  ?></td>
            <td><?= $row['testimony_date']  ?></td>
            <td><?= $row['testimony_text']  ?></td>
        </tr>

        <?php
            }
        ?>
</table>
</body>

Oggy Cat
  • 3
  • 1

1 Answers1

0

you have to check before mysql_fetch_array

if($rs === FALSE) { 
    die(mysql_error()); 
}

while($row = mysql_fetch_array($rs))
{
    echo $row['username'];
}
wiretext
  • 3,277
  • 13
  • 19