Reputation: 13
The title shows what I need to accomplish but what I'm getting as the page builds is 3 columns with the same result on each row. Each row is different but each column on each row has the same thing repeated instead of different things for column one, two, and three.
I'm missing something in the code below to make this work, any help would be greatly appreciated.
Thank you.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$results = mysql_query("SELECT title,link FROM syndicate ORDER BY popularity DESC LIMIT 75");
while ($row = mysql_fetch_array($results)){
$title = $row['title'];
$link = $row['link'];
if ($divtest = 1){
//insert in div col1;
echo '<div class="col1">';
///<!-- Column 1 start -->
echo '<a href="' . $link . '" target="_blank">' . $title . '</a><br><br>'; /// add all links here
///<!-- Column 1 end -->
echo '</div>';
$divtest = 2;
}
if ($divtest = 2){
//insert in div col2;
echo '<div class="col2">';
///<!-- Column 2 start -->
echo '<a href="' . $link . '" target="_blank">' . $title . '</a><br><br>'; /// add all links here
///<!-- Column 2 end -->
echo '</div>';
$divtest = 3;
}
if ($divtest = 3){
//else {
//insert in div col3;
echo '<div class="col3">';
///<!-- Column 3 start -->
echo '<a href="' . $link . '" target="_blank">' . $title . '</a><br><br>'; /// add all links here
///<!-- Column 3 end -->
echo '</div>';
$divtest = 1;
}
}
Upvotes: 1
Views: 172
Reputation: 4215
because of
$divtest = 2;
$divtest = 3;
$divtest = 1;
in last of each if statement every three if run in one cycle of while.
I think you should set $divtest value out of while and change if condition with these
if ($divtest == 1){}
if ($divtest == 2){}
if ($divtest == 3){}
Upvotes: 0
Reputation: 50563
You are wrongly using the assigment operator =
in your if
statements, while you probably meant the ==
operator.
Change your following lines:
if ($divtest = 1){
..
if ($divtest = 2){
..
if ($divtest = 3){
for the correct ones:
if ($divtest == 1){
..
if ($divtest == 2){
..
if ($divtest == 3){
Upvotes: 1