Take the 2-minute tour ×

THANKS FOR THE ANSWERS, I am really glad.. I edited the code and I want to ask, if I edited it well? :-)

  $result = $sql->query("SELECT * FROM `topic` ;");
                    echo"<div id='article'>
                        <a href='reporty.php?page=$id'><div id='article_img'><img src='$photo'/></div></a>
                        <div id='article_text'>
share|improve this question

4 Answers 4

Give proper variable name always. Your $result and $row is holding all most all variable here.

Same memory location will be updated always. So it loses the old values (We learned this in 1st year degree/ PUC first year)

Do it like this,

for example when you are fetching from topic table and you select photo,

use variables like $topicResultForPhto and$topicPhotoRow`. Do this for all.

And one more error,

You already calls like SELECT * and you have all the fields from table. Why should again a call from photo and other fields like select photo from topics where ?

share|improve this answer

I'd suggest to use readable and self-explanatory variable names, like $photo_result and $title_result. This then would also solve your problem since you use the same variable names in your loops.

For the sake of performance and simplicity, why don't you JOIN your tables? Then you'd only have one query with one loop.

share|improve this answer

$result and $row same variable name is used in both loops.

share|improve this answer

You should set the second query as $result1 because the new one is replacing the first one.. That's why you have always just one result

   echo '<div id="article">
            <a href="';
   echo '.php"><div id="article_img"><img src="';
   $result1 = $sql->query("SELECT `photo` FROM `topic` WHERE id='$id' ;");
   while ($row1 = $result->fetch_array()) {
       echo $row1['photo'];
share|improve this answer

Your Answer


