问题描述
我在数据库中有几千种化学产品。我需要在网站上动态更新它们,每页15页以及分页。我使用下面的代码从DB获取数据。它在Localhost中运行良好,但在服务器上传时,分子式无法正确呈现。
Ex:
I have few thousand chemical products in database. I need to update them dynamically in the website with 15 per page along with pagination. I am using below code for getting the data from DB. Its working fine in Localhost but when uploaded in server the molecular formula does not render properly.
Ex:
C??H??N?NAO?
<?php
/*** mysql hostname ***/
$hostname = 'localhost';
/*** mysql username ***/
$username = 'admin_bio';
/*** mysql password ***/
$password = 'bio_organics';
$page_number = $_GET['pageNumber'];
$start = $page_number * 15;
$products_per_page = 15;
$dbname = 'bio_organics';
$dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
$response = $dbh->query("SELECT * FROM products LIMIT $start,$products_per_page ")->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($response);
$dbh = null;
?>
我的尝试:
我试图用jQuery ajax在网页中呈现上面的json数据。
< script>
jQuery(document).ready(function()
{
var pageNumber = window.location.href.split(=)[1];
if(pageNumber == undefined)
{
pageNumber = 0;
}
其他
{
pageNumber = pageNumber - 1;
}
jQuery.ajax(
{
类型:GET,
dataType:JSON,
url:products_list.php? pageNumber =+ pageNumber,
成功:功能(数据)
{
var product_listing ='';
for(i = 0; i< jquery(data).length; i ++)>
{
var pageNumbers ='< option value ='+ data [i] .id +'>'+ data [i] .id +'< / o ption>'
if(product_listing =='')
{
product_listing ='
What I have tried:
I tried to render the above json data in Webpage with jQuery ajax.
<script>
jQuery(document).ready(function()
{
var pageNumber = window.location.href.split("=")[1];
if(pageNumber==undefined)
{
pageNumber = 0;
}
else
{
pageNumber = pageNumber - 1;
}
jQuery.ajax(
{
type:"GET",
dataType:"JSON",
url:"products_list.php?pageNumber="+pageNumber,
success:function(data)
{
var product_listing = '';
for(i=0;i<jquery(data).length;i++)>
{
var pageNumbers = '<option value="'+ data[i].id +'">'+ data[i].id +'</option>'
if(product_listing=='')
{
product_listing = '
'+ data [i] .chemical_name +'
分子式:'+ data [i] .mol_formula +'
CAS号:: '+ data [i] .cas_number +'
'+ data[i].chemical_name +'
Molecular Formula :'+ data[i].mol_formula +'
CAS No. ::'+ data[i].cas_number +'
';
}
其他
{
product_listing = product_listing +'
';
}
else
{
product_listing = product_listing + '
'+ data [i] .chemical_name +'
分子式:'+ data [i] .mol_formula +'
CAS号:: '+ data [i] .cas_number +'
'+ data[i].chemical_name +'
Molecular Formula :'+ data[i].mol_formula +'
CAS No. ::'+ data[i].cas_number +'
';
}
}
jQuery(#all_products)。html(product_listing);
}
});
});
< / script>
';
}
}
jQuery("#all_products").html(product_listing);
}
});
});
</script>
推荐答案
这篇关于使用jquery ajax PHP从数据库读取分子式的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!