Hi
I want to use ajax to connect to database and echo some data in my page, I wrote these two codes that can handle my need:
index.php
-----------------------------------------
[PHP]<?php
//This file is text.php
mysql_connect("localhost", "root", ""); //Connect to the mysql server with your host (most likely localhost), username, and password
mysql_select_db("dictionary"); //Select your database by name
$page = $_GET["page"]; //This is the variable we retrieve through GET to know which row of content to retrieve
$sql = "SELECT * FROM table1 WHERE f1 = '$page'"; //This is the text of the query. We will select the content field from the table ‘pages’ where the page field has the same value as the one we want to retrieve
$query = mysql_query($sql) or die(mysql_error()); //Make the actual query
if( mysql_num_rows($query) == 1 ) //Check to see if we found 1 row with that page name
{
$r=mysql_fetch_assoc($query); //Set a mysql fetching variable for the query
echo $r["f2"]; //Echo out the content of the page we want
}
else
{
echo "Sorry, that page was not found."; //Otherwise, echo out an error message saying the page was not found
}
?>
[/PHP]--------------------------------------------
text.php
---------------------------------------------
[PHP]<?php
//This file is text.php
mysql_connect("localhost", "root", ""); //Connect to the mysql server with your host (most likely localhost), username, and password
mysql_select_db("mydatabse"); //Select your database by name
$page = $_GET["page"]; //This is the variable we retrieve through GET to know which row of content to retrieve
$sql = "SELECT * FROM table1 WHERE f1 = '$page'"; //This is the text of the query. We will select the content field from the table ‘pages’ where the page field has the same value as the one we want to retrieve
$query = mysql_query($sql) or die(mysql_error()); //Make the actual query
if( mysql_num_rows($query) == 1 ) //Check to see if we found 1 row with that page name
{
$r=mysql_fetch_assoc($query); //Set a mysql fetching variable for the query
echo $r["f2"]; //Echo out the content of the page we want
}
else
{
echo "Sorry, that page was not found."; //Otherwise, echo out an error message saying the page was not found
}
?>
[/PHP]------------------------------------------
I works good, when my database is normal, but for utf-8 data it gives me ??? instead of the words retrieved from database, I believe there should be a code that I missed that would show the utf-8 data in JAVA script.
will someone help me, thank/