进行php调用后,照片不显示

时间:2013-05-16 18:53:25

标签: php javascript ajax jquery

我正在尝试使用php从数据库中检索一些数据,然后我将json_encode数组中的数据添加到我的其他php文件中,以便内容可以显示在网站上。目前我能够检索包含文本的内容,但是我无法检索图像。例如,不显示伦敦的图像,而是显示文本London..jpg。

这是我的php文件,它选择数据库的数据

         <?php
require_once('conn.inc.php'); 
$stmt = $mysqli->prepare("SELECT CityName,CityID, CityPopulation,CitySkills,CityEmploymentRates,CityjsaClaimants ,Image ,CityWeeklyEarnings FROM citiesdata WHERE CityID = ? ORDER BY CityName");
$stmt->bind_param('i', $_GET['CityID']);
$stmt->execute(); 
$stmt->bind_result($CityName, $CityID,$CityPopulation,$CitySkills,$CityEmploymentRates,$CityjsaClaimants,$Image,$CityWeeklyEarnings); 
$myArray = array();

while ($stmt->fetch()) {
    $myArray[] = $CityName;

    $myArray[] = $CityPopulation;
    $myArray[] = $CitySkills;
    $myArray[] = $CityEmploymentRates;
    $myArray[] = $CityjsaClaimants;
    $myArray[] = $Image;
    $myArray[] = $CityWeeklyEarnings;


}
echo json_encode($myArray);


?>

以下是我用来检索我网站数据的javascript代码,我正在使用CityID检索数据,例如,如果CityID为1,则单击一个单选按钮,值为1,这将匹配CityID为1是伦敦和城市的细节将显示除了图像,因为我有多个图像我使用json_encode我不知道在哪里放置图像src因为我正在与多个城市的多个图像。当用户通过单选按钮选择城市时,在cityName,Cityskills等网站上显示的一切都很好,我该如何制作,以便当用户选择单选按钮时,城市图像将与cityNames,城市技能等一起显示?

$(document).ready(function(){
$('input[name=CityID]').on('click', function(){
var sendVals = $(this).serialize();
        var returnData = "";
        $("#displayResults").html('<li>Please Wait!</li>');
        $.get("phpCalling.php", sendVals, function(myData){

            $.each(myData, function(key, value) {

                returnData += "<p>"
                returnData += value;
                returnData += "</p>";
            })
            $("#displayResults").html(returnData);

        }, "json");

    });

});

1 个答案:

答案 0 :(得分:0)

更改以下代码

while ($stmt->fetch()) {
$myArray[] = $CityName;

$myArray[] = $CityPopulation;
$myArray[] = $CitySkills;
$myArray[] = $CityEmploymentRates;
$myArray[] = $CityjsaClaimants;
$myArray[] = $Image;
$myArray[] = $CityWeeklyEarnings;


}

as

while ($stmt->fetch()) {
$myArray[] = $CityName;

$myArray[] = $CityPopulation;
$myArray[] = $CitySkills;
$myArray[] = $CityEmploymentRates;
$myArray[] = $CityjsaClaimants;
$myArray[] = '<img src="'.$Image.'"/>';
$myArray[] = $CityWeeklyEarnings;

}