1

标题显示了我需要完成的工作,但随着页面的构建,我得到的是 3 列,每行的结果相同。每一行都是不同的,但每一行的每一列都重复相同的内容,而不是第一列、第二列和第三列的不同内容。

我在下面的代码中遗漏了一些东西来完成这项工作,任何帮助将不胜感激。

谢谢你。

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

}
4

2 回答 2

1

=您在if语句中错误地使用了赋值运算符,而您可能指的是==运算符。

更改以下行:

if ($divtest = 1){
..
if ($divtest = 2){
..
if ($divtest = 3){

对于正确的:

if ($divtest == 1){
..
if ($divtest == 2){
..
if ($divtest == 3){
于 2012-09-24T18:06:04.323 回答
0

因为

$divtest = 2; 
$divtest = 3; 
$divtest = 1;

在每个 if 语句的最后一个,每三个 if 在一个 while 循环中运行。

我认为你应该在 while 中设置 $divtest 值并使用这些更改 if 条件

if ($divtest == 1){}

if ($divtest == 2){}

if ($divtest == 3){}
于 2012-09-25T17:59:32.533 回答