-1

$block 没有被退回。问题似乎出现在 while 语句期间。我以前使用过这个脚本,只是略有不同,所以我知道这是相当小的东西。任何帮助将不胜感激,在此先感谢。

<?php
if (isset($_GET['filter_tag'])) {
    $filter_tag = $_GET['filter_tag'];
}

    if (@mysql_connect('xxxxxxxxx','xxxxxxxxxx','xxxxxxxxxx')) {
        if (mysql_select_db('xxxxx')) {
                $query = " SELECT blocks . CNO, blocks . CName, blocks . URL, images . Ipath FROM blocks LEFT JOIN images ON blocks . INO = images . INO WHERE CNO LIKE 'mysql_real_escape_string($filter_tag)' ";
        $query_run = mysql_query($query);
        } while ($query_row = mysql_fetch_assoc($query_run)) {      
            echo $block =   '<li id="'.$query_row['CNO'].'" class="block" data-toggle="modal" data-target="#blocklModal" >
        <a href="'.$query_row['URL'].'" target="_blank">
        <img class="b" src="'.$query_row["Ipath"].'" alt="" data-controls-modal="block-modal" data-backdrop="static">
        </a>
        <p class="c-title">'.$query_row['Name'].'</p>
        </li>';
        }
    }
?>
4

1 回答 1

0

这可能有效(只要您的查询是正确的)。只要知道 mysql_* 正在贬值,您应该真正使用 PDO 或 MySQLi 来运行您的查询。这个答案在不久的将来将毫无用处:

if (isset($_GET['filter_tag'])) {
    $filter_tag = $_GET['filter_tag'];

    if (mysql_connect('xxxxxxxxx','xxxxxxxxxx','xxxxxxxxxx')) {
        if (mysql_select_db('xxxxx')) {
            $filter_tag = mysql_real_escape_string($filter_tag);
            $query = " SELECT blocks . CNO, blocks . CName, blocks . URL, images . Ipath FROM blocks LEFT JOIN images ON blocks . INO = images . INO WHERE CNO LIKE '$filter_tag'";
            $query_run = mysql_query($query);
            while ($query_row = mysql_fetch_assoc($query_run)) {
                $block =  '<li id="' . $query_row['CNO'] . '" class="block" data-toggle="modal" data-target="#blocklModal">';
                $block .= '<a href="' . $query_row['URL'] . '" target="_blank">';
                $block .= '<img class="b" src="' . $query_row["Ipath"] . '" alt="" data-controls-modal="block-modal" data-backdrop="static">';
                $block .= '</a><p class="c-title">' . $query_row['Name'] . '</p></li>';
                echo $block;
            }
        }
    }
} else {
    echo 'No filter tag provided';
}

尝试查看此链接以了解有关 PDO/MySQLi 的更多信息:PDO 与 MySQLi - 您应该使用哪个

于 2012-11-06T14:12:04.280 回答