好的,我想我对MySQL表的设置很差。我确定了其他无关紧要的内容,然后是movielink1,movielink2,movielink3,movielink4,movielink5
我希望每个按钮都出现一个按钮,只有在movielink#存在的情况下。它们中的大多数仅具有movielink1。
我认为我只是以错误的方式看待它。这是我的代码。
<?php
$data2 = mysql_query("SELECT movielink1,movielink2,movielink3,movielink4,movielink5 FROM movies WHERE id=$id");
if (mysql_num_rows($data2) > 0 ) {
while($info2 = mysql_fetch_array($data2)) {
Print '<a href="'.$info['movielink1'];.'?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]" title="'.$info['title'];.'"><img src="http://tipmypicks.com/cssmovie/images/watchmovie.png" class="watchmovie"></a>';
}
} else {
Print 'Error!';
}
?>
感谢您的建议,我刚刚添加了它,但是它仍然不能正常工作,也不是解决它的好方法。
$data1 = mysql_query("SELECT movielink1 FROM movies WHERE id=$id");
if (mysql_num_rows($data1) > 0 ) {
while($info1 = mysql_fetch_array($data1)) {
Print '<a href="'.$info['movielink1'].'?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]" title="'.$info['title'].'"><img src="http://tipmypicks.com/cssmovie/images/watchmovie.png" class="watchmovie"></a>';
}
} else {
}
$data2 = mysql_query("SELECT movielink2 FROM movies WHERE id=$id");
if (mysql_num_rows($data2) > 0 ) {
while($info2 = mysql_fetch_array($data2)) {
Print '<a href="'.$info['movielink2'].'?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]" title="'.$info['title'].'"><img src="http://tipmypicks.com/cssmovie/images/watchmovie.png" class="watchmovie"></a>';
}
} else {
}
$data3 = mysql_query("SELECT movielink3 FROM movies WHERE id=$id");
if (mysql_num_rows($data3) > 0 ) {
while($info3 = mysql_fetch_array($data3)) {
Print '<a href="'.$info['movielink3'].'?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]" title="'.$info['title'].'"><img src="http://tipmypicks.com/cssmovie/images/watchmovie.png" class="watchmovie"></a>';
}
} else {
}
$data4 = mysql_query("SELECT movielink4 FROM movies WHERE id=$id");
if (mysql_num_rows($data4) > 0 ) {
while($info4 = mysql_fetch_array($data4)) {
Print '<a href="'.$info['movielink4'].'?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]" title="'.$info['title'].'"><img src="http://tipmypicks.com/cssmovie/images/watchmovie.png" class="watchmovie"></a>';
}
} else {
}
$data5 = mysql_query("SELECT movielink5 FROM movies WHERE id=$id");
if (mysql_num_rows($data5) > 0 ) {
while($info5 = mysql_fetch_array($data5)) {
Print '<a href="'.$info['movielink5'].'?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]" title="'.$info['title'].'"><img src="http://tipmypicks.com/cssmovie/images/watchmovie.png" class="watchmovie"></a>';
}
} else {
}
最佳答案
您的代码中有许多小问题。例如,您从结果中获取行并将其设置为$info2
,然后调用$info
。
这是固定的代码:
$sqlResults = mysql_query("SELECT * FROM movies WHERE id=$id");
if (mysql_num_rows($sqlResults) > 0 ) {
while($sqlRow = mysql_fetch_array($sqlResults)) {
if (!empty($sqlRow['movielink1'])) {
print '<a href="' . $sqlRow['movielink1'] . '?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]" title="' . $sqlRow['title'] . '"><img src="http://tipmypicks.com/cssmovie/images/watchmovie.png" class="watchmovie"></a>';
}
if (!empty($sqlRow['movielink2'])) {
print '<a href="' . $sqlRow['movielink2'] . '?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]" title="' . $sqlRow['title'] . '"><img src="http://tipmypicks.com/cssmovie/images/watchmovie.png" class="watchmovie"></a>';
}
if (!empty($sqlRow['movielink3'])) {
print '<a href="' . $sqlRow['movielink3'] . '?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]" title="' . $sqlRow['title'] . '"><img src="http://tipmypicks.com/cssmovie/images/watchmovie.png" class="watchmovie"></a>';
}
if (!empty($sqlRow['movielink4'])) {
print '<a href="' . $sqlRow['movielink4'] . '?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]" title="' . $sqlRow['title'] . '"><img src="http://tipmypicks.com/cssmovie/images/watchmovie.png" class="watchmovie"></a>';
}
if (!empty($sqlRow['movielink5'])) {
print '<a href="' . $sqlRow['movielink5'] . '?iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]" title="' . $sqlRow['title'] . '"><img src="http://tipmypicks.com/cssmovie/images/watchmovie.png" class="watchmovie"></a>';
}
}
}
else
{
print 'Error!';
}