jquery/php/mysql でアプリを作成しようとしています。最初にデータベース内のすべての店舗を一覧表示することになっていますが、これは正常に機能します。ただし、いずれかをクリックすると、その特定の店舗に関する詳細情報が表示されます。そして、そこから問題が始まります。
基本的に、データベースからすべての行をフェッチしたい場合は、すべて正常に機能します。しかし、クエリ文字列を使用して特定の行を選択しようとすると、機能しません。私は多くのことを試しましたが、jquery関数を壊して何も出力しないのはphpファイルの$ _GETであることがわかりました。GET でのみエコーを実行しても、それは壊れます。そして、私はその理由を理解できません。たとえば、「select * where id = 2」だけでもうまくいきます。ただし、たとえば GET を使用して 2 のクエリ文字列を取得する場合はそうではありません。
(また、現在これは単なる JSON ですが、後でもちろん jsonp のクロスドメインが必要になります)
これは私のphpコードです:
<?php
// Settings for accessing the DB.
$host = "localhost";
$db = "mappdb";
$username ="db-username";
$password ="******";
// Connect and query the DB and get the data for all attractions
$connect = mysql_pconnect($host, $username, $password) or die("Could not connect to the database");
mysql_select_db($db) or die("Could not select the database");
$arr = array();
$idnumber = $_GET["pid"];
$result = mysql_query("select * from attractions where id = $idnumber");
while($object = mysql_fetch_object($result)) {
    $arr[] = $object;
}
echo '{"attractions":'.json_encode($arr).'}';
?>
そして、ここに私のjqueryがあります:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" href="jquery.mobile-1.3.1.min.css" />
<script src="jquery-1.9.1.min.js"></script>
<script src="jquery.mobile-1.3.1.min.js"></script>
        <title>Store Finder</title>
    </head>
    <body>
        <div data-role="page" id="page">
            <div data-role="header" data-position="fixed">  
            <a href="index.html" data-icon="back">Back</a>
            <h6>Search</h6>
            </div>
            <div data-role="content">
                <ul data-role="listview" data-filter="true" id="listed" data-filter-placeholder="Filter cities or stores..." data-inset="true">
                    <script type="text/javascript">
                        $(document).ready(function(){
                            var url="http://localhost/mapp/json.php?pid=2";
                            $.getJSON(url,function(json){
                                // loop through the stores here
                                $.each(json.attractions,function(i,dat){
                                    $("#listed").append(
                                    '<li><a href="viewstore.html?id='+dat.id+'">'+dat.id+' '+dat.name+'</a></li>'
                                    ).listview('refresh');
                                });
                            });
                        });
                    </script>
                </ul>
            </div>
            <div id="msg"> </div>
            <div data-role="footer" data-position="fixed">
            <h6>Footer</h6>
            </div>
        </div>
    </body>
</html>
一日中これに座っていて、私の人生ではそれを理解することはできません. 助けていただければ幸いです。ありがとう!