1

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;
}

}

2 Answers 2

1

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){
Sign up to request clarification or add additional context in comments.

2 Comments

you guys are the best - i knew it was something like that - thank you!
one other thing for those who need this help... the second two if's need to be changed to elseif's so that the results are not repeated in each column.
0

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){}

1 Comment

you guys are the best - i knew it was something like that - thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.