从mysql数据库中提取数据时,如何在php字符串中使用多个属性?

时间:2022-02-06 19:23:23

I have a website and it uses a lytebox to show some images and other websites on top of a current website. This all works fine, but I have transferred the data into a MYSQL database and now the class of the line does not work.

我有一个网站,它使用lytebox在当前网站上显示一些图像和其他网站。这一切都运行正常,但我已将数据传输到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:-)

哦,对不起,我忘记了 - 我永远不会再这样做了:-)

5 个解决方案

#1


2  

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>

#2


2  

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

#3


1  

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.

您忘记了结束标记,还需要使用连接来从查询结果中回显您的变量。

#4


0  

This should probably work, I don't see any other mistake into your code:

这应该可行,我没有看到你的代码中的任何其他错误:

echo "<a href='" . $titleItem["imageLink01"] . "' title='' class='thickbox'><img src='" . $titleItem["imageSrc01"] . "' alt='" . $titleItem["imageAlt01"]. "' width='150px' height='113px' border='0'/></a>";

#5


0  

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

#1


2  

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>

#2


2  

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

#3


1  

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.

您忘记了结束标记,还需要使用连接来从查询结果中回显您的变量。

#4


0  

This should probably work, I don't see any other mistake into your code:

这应该可行,我没有看到你的代码中的任何其他错误:

echo "<a href='" . $titleItem["imageLink01"] . "' title='' class='thickbox'><img src='" . $titleItem["imageSrc01"] . "' alt='" . $titleItem["imageAlt01"]. "' width='150px' height='113px' border='0'/></a>";

#5


0  

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