It's not working because you are re-using $row
Code:
<?php
$query = mysql_query("SELECT * FROM follow JOIN users WHERE user_id = " . ($row['id']) . " ORDER BY follow_user_id ASC LIMIT 10"); // use initial value of $row
while($row = mysql_fetch_array($query)) { // new value for $row
<?php
<div class="followimage">
<a href="/test/profileinserttest.php?ID=<?php echo $row['follow_user_id']; ?>"><img src="/test/images/<?php echo $row['logo']; ?>" alt="<?php echo $row['company']; ?>" /></a>
</div>
<?php
}
?>
</div>
<div class="followbuttonimagearea">
<?php
$query = mysql_query("SELECT * FROM follow JOIN users WHERE user_id = " . ($row['id']) . " ORDER BY follow_user_id ASC LIMIT 10"); // value for $row is not the same as it was on line 1
while($row = mysql_fetch_array($query)) {
?>
<div class="followimage">
<a href="/test/profileinserttest.php?ID=<?php echo $row['follow_user_id']; ?>"><img src="/test/images/<?php echo $row['logo']; ?>" alt="<?php echo $row['company']; ?>" /></a>
</div>
<?php
}
?>
</div>
So in the second loop $row doesn't have the same value it had in the first loop so the query fails and you get an error. Easiest way to fix are to either to store the ID you need in a separate variable, or to use a different variable name in the inner loop.
PHP Code:
<?php
$id = $row['id'];
$query = mysql_query("SELECT * FROM follow JOIN users WHERE user_id = " . $id . " ORDER BY follow_user_id ASC LIMIT 10");
while($row = mysql_fetch_array($query)) {
<?php
<div class="followimage">
<a href="/test/profileinserttest.php?ID=<?php echo $row['follow_user_id']; ?>"><img src="/test/images/<?php echo $row['logo']; ?>" alt="<?php echo $row['company']; ?>" /></a>
</div>
<?php
}
?>
</div>
<div class="followbuttonimagearea">
<?php
$query = mysql_query("SELECT * FROM follow JOIN users WHERE user_id = " . $id . " ORDER BY follow_user_id ASC LIMIT 10");
while($row = mysql_fetch_array($query)) {
?>
<div class="followimage">
<a href="/test/profileinserttest.php?ID=<?php echo $row['follow_user_id']; ?>"><img src="/test/images/<?php echo $row['logo']; ?>" alt="<?php echo $row['company']; ?>" /></a>
</div>
<?php
}
?>
</div>
even better would be to use mysql_data_seek to rewind the query result and start over so you don't have to do the same query twice:
PHP Code:
<?php
$id = $row['id'];
$query = mysql_query("SELECT * FROM follow JOIN users WHERE user_id = " . $id . " ORDER BY follow_user_id ASC LIMIT 10");
while($row = mysql_fetch_array($query)) {
<?php
<div class="followimage">
<a href="/test/profileinserttest.php?ID=<?php echo $row['follow_user_id']; ?>"><img src="/test/images/<?php echo $row['logo']; ?>" alt="<?php echo $row['company']; ?>" /></a>
</div>
<?php
}
?>
</div>
<div class="followbuttonimagearea">
<?php
mysql_data_seek($query, 0);
while($row = mysql_fetch_array($query)) {
?>
<div class="followimage">
<a href="/test/profileinserttest.php?ID=<?php echo $row['follow_user_id']; ?>"><img src="/test/images/<?php echo $row['logo']; ?>" alt="<?php echo $row['company']; ?>" /></a>
</div>
<?php
}
?>
</div>
Bookmarks