0

我将如何在 php.ini 中处理这个 Ajax。我想要做的是将数据发送到 process.php,如果 mode=loadlinks 它将执行 mysql 查询

function PresentLinks(div_id){

        $("#loading-status").fadeIn(900,0);
        $("#loading-status").html("<img src='img/bigLoader.gif' />");           

$.ajax({

            type: "POST",
            url: "process.php",
            data: "mode=loadlinks",

            success: function(msg){

                $("#loading-status").fadeOut(900,0);
                $("#"+div_id).html(msg);


            }

        });}

我要处理的是

if($_POST['mode'] == loadlinks){  // this is what i want to ask
$query = "SELECT * FROM site ORDER BY link_id DESC";
$result = MYSQL_QUERY($query) or die (mysql_error());
while($data = mysql_fetch_row($result)){
echo ("$data[1]");
}}
else {
}
4

2 回答 2

2

您需要在 PHP 中引用字符串。否则,它们将被假定为常数。您还应该使用PDO

if($_POST['mode'] == 'loadlinks'){
    $pdo = new PDO('mysql:host=HOST;dbname=DATABASE'), 'username', 'password');
    $stmt = $pdo->execute('SELECT * FROM site ORDER BY link_id DESC');

    $sites = $stmt->fetchAll();
    foreach($sites as $site) {
        echo "<div>" . $site['name'] . "</div>"; // Or whatever info you want to output
    }
}

为了提高性能,您应该指定要检索的表列名称,而不是使用*.

于 2012-06-17T02:02:21.903 回答
1

你需要引用字符串值

  if($_POST['mode'] == 'loadlinks'){.....
于 2012-06-17T02:01:00.797 回答