我搜索了一些代码,即使我找到了它,但我不知道如何添加他创建的新javascript行。
原始链接是this,我在代码中有一些问题。因为我已将代码"price": "120.00",
更改为"price": "\\using php to call some data",
。
这是原始代码:
{
"product_id": "1",
"store_id": "1",
"price": "120.00",
"sequence": "0",
"id": "1",
"parent_id": "0",
"name": "Store 1",
"email": "store1@store1.com"
}
这就是我写的:
$result1=mysqli_query($conn, "select * from product");
while ($row1=mysqli_fetch_assoc($result1))
{
$pno1 = $row1["no"];
$sql1 = "SELECT * FROM xx where WHERE product_id = '$pno1') ";
$query1 = mysqli_query($conn , $sql1);
$rowcont1 = mysqli_num_rows($query1);
?>
{
"name": "<?php echo $row1["PACKAGE_NAME"]; ?>",
"id": "<?php echo $row1["PACKAGE_NAME"]; ?>",
"cat": "UNIFI",
<?php
if ($rowcont1 == 0)
{
?>
"vas": "<?php echo "No default vas"; ?>"
<?php
}
else
{
?>
"vas": "<?php
while($rowvas1=mysqli_fetch_assoc($query1))
{
echo "$rowvas1[PACKAGE_NAME]\\n\\n"; //This is the line I want to chage (\\n no function for me)
}
?>"
<?php
}
?>
},
<?php
我发现很多问题与我相同,但即使我尝试了所有解决方案,我的代码仍然无效
答案 0 :(得分:3)
请尝试以下方法:
echo "$rowvas1[PACKAGE_NAME]<br>";
而不是\n
只需添加html换行符<br>
。
修改:如果您使用jsfiddle
中提供的JS,请务必更改以下行:
$('#price-store').text(pricestore[$('option:selected', this).index()].price);
到(.text(
到.html(
):
$('#price-store').html(pricestore[$('option:selected', this).index()].price);