[英]How do I use multiple attributes in a php string when pulling data from a mysql database?
I have a website and it uses a lytebox to show some images and other websites on top of a current website. 我有一个网站,它使用lytebox在当前网站的顶部显示一些图像和其他网站。 This all works fine, but I have transferred the data into a MYSQL database and now the class of the line does not work.
一切正常,但是我已将数据传输到MYSQL数据库中,现在该行的类不起作用。
This is what I had previously and this works: 这是我以前的工作,并且有效:
<div id="photo01">
<a href="images/strayKatts/photo01.JPG" title="" class="thickbox">
<img src="images/strayKatts/photo01.JPG" alt="Stray Katts Creations"
width="150px" height="113px" border="0"/>
</a>
</div>
but because I am getting more and more data in the directory I have transferred my data into a mysql database to maintain a lot easier. 但是由于目录中越来越多的数据,我已将数据传输到mysql数据库中,以便于维护。
I can pull the data and everything, it is just not being displayed probably and I currently have this: 我可以提取数据和所有数据,可能只是不显示它,而我目前有:
<div id="photo01">
<?php
$category_set = mysql_query("SELECT * FROM currentmarkets
WHERE id = '3' AND visible = '1';", $dbconnect);
if (!$category_set) {
die("Database query failed: " . mysql_error());
}
while ($titleItem = mysql_fetch_array($category_set)) {
echo "<a href='{$titleItem["imageLink01"]}' title='' class='thickbox'><img src='{$titleItem["imageSrc01"]}' alt='{$titleItem["imageAlt01"]}' width='150px' height='113px' border='0'/>";}
?></div>
I am sure it has something to do with the way I am using my '' and my "" not sitting right. 我确信这与我使用“”和“”的方式不正确有关。
Any more advice / help? 还有其他建议/帮助吗?
EDIT!! 编辑!!
Sorry maybe I am not doing it right, but I have tried all the answer and none of them change anything even though they seem right - this is confusing:-) 对不起,也许我做的不对,但是我尝试了所有答案,即使它们看起来正确,也没有任何改变-这很令人困惑:-)
oh and sorry I forgot that - I'll never do that again:-) 哦,很抱歉,我忘了-我再也不会这样做了:-)
Try like this, using concatenation. 像这样使用串联。 Also try to just print the array fetched to see if it's a problem of your embedded html in php or to check if the query is not ok.
也可以尝试仅打印获取的数组,以查看这是否是您在php中嵌入的html的问题,或者检查查询是否正常。
<div id="photo01">
<?php
$category_set = mysql_query("SELECT * FROM currentmarkets WHERE id = '3' AND visible = '1';", $dbconnect);
if (!$category_set) {
die("Database query failed: " . mysql_error());
}
while ($titleItem = mysql_fetch_array($category_set)) {
echo "<a href='".$titleItem["imageLink01"]."' title='' class='thickbox'><img src='".$titleItem["imageSrc01"]."' alt='".$titleItem["imageAlt01"]."' width='150px' height='113px' border='0'/>";}
?></div>
change: 更改:
echo "<a href='{$titleItem["imageLink01"]}' title='' class='thickbox'><img src='{$titleItem["imageSrc01"]}' alt='{$titleItem["imageAlt01"]}' width='150px' height='113px' border='0'/>";}
to: 至:
echo "<a href='" . $titleItem["imageLink01"] . "' title='' class='thickbox'><img src='" . $titleItem["imageSrc01"] . "' alt='" . $titleItem["imageAlt01"] . "' width='150px' height='113px' border='0'/></a>";}
In your while
loop: 在您的
while
循环中:
while ($titleItem = mysql_fetch_array($category_set)) {
echo "<a href='".$titleItem["imageLink01"]."' title='' class='thickbox'>";
echo "<img src='".$titleItem["imageSrc01"]."' alt='".$titleItem["imageAlt01"]."'";
echo " width='150px' height='113px' border='0'/></a>";
}
You forgot the </a>
closing tag, and also need to just use concatenation to echo
your vars from the query results. 您忘记了
</a>
结束标记,还需要仅使用串联从查询结果中echo
您的var。
这可能应该可以工作,我看不到您的代码有任何其他错误:
echo "<a href='" . $titleItem["imageLink01"] . "' title='' class='thickbox'><img src='" . $titleItem["imageSrc01"] . "' alt='" . $titleItem["imageAlt01"]. "' width='150px' height='113px' border='0'/></a>";
Uses a heredoc when you've got a long mix of HTML and PHP variables: 当您将HTML和PHP变量混合使用时,请使用Heredoc :
while ($titleItem = mysql_fetch_array($category_set)) {
echo <<<EOL
<a href="{$titleItem['imageLink01']}" title="" class="thickbox">
<img src="{$titleItem['imageSrc01']}" alt="{$titleItem['imageAlt01']}" width="150px" height="113px" border="0" />
</a>
EOL;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.