Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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#
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;

?>


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 = '
<img style="height: 100px;" src="'+ data[i].image_url +'" alt="Product" />

'+ data[i].chemical_name +'

Molecular Formula :'+ data[i].mol_formula +'

CAS No. ::'+ data[i].cas_number +'

Enquire
';
}
else
{
product_listing = product_listing + '
<img style="height: 100px;" src="'+ data[i].image_url +'" alt="Product" />

'+ data[i].chemical_name +'

Molecular Formula :'+ data[i].mol_formula +'

CAS No. ::'+ data[i].cas_number +'

Enquire
';
}
}

jQuery("#all_products").html(product_listing);
}
});
});
</script>
Posted
Updated 4-Sep-16 16:58pm

Quote:
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.
Split your problem in 2 simpler problems.
- Check that you always get right data from database on localhost and on server.
- check that rendering is done with same data and that in this case, rendering is correct.

the result of this check will tell you where to search.

[Update]
Quote:
I am getting the json response properly in localhost but not in Server. Also the names like Abacavir 5’-β-D-Glucuronide Sodium Salt are coming as null. If I remove the single quote after the letter 5 it is displaying the name.
So you know the problem is in server database or its access.
Now you know the problem is in server database contains or in server database access.
You need to check the contain of the server database with another tool.
 
Share this answer
 
v2
Comments
Janardhanam Julapalli 25-Aug-16 6:43am    
I am getting the json response properly in localhost but not in Server. Also the names like Abacavir 5’-β-D-Glucuronide Sodium Salt are coming as null. If I remove the single quote after the letter 5 it is displaying the name.
Patrice T 25-Aug-16 9:02am    
Use Improve question to update your question.
I have fixed the issue by adding charset UTF8
mysql_set_charset("UTF8");
inside the .php file which gives me the json output.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900