1. First create a new SQL table with the table contents as shown above:
2. Create a new public file conn.php to link to the database:
Header ("Content-type:text/html;charset=utf8");//Declaration Encoding format $conn =mysql_connect ("localhost"," Root "," aaaaaa "ordie (" database connection error ". Mysql_errno ());//Connect SQL Mysql_ select_db ("Phptest", $conn); mysql_query (' Set NAMES UTF8 'ordie (' CharSet set error '?>
The 3.php server is provided to the front-end Ajax data interface, new file Phptoajax. Php
require_once ("conn.php");//import Common file $query =mysql_query ("select * from TXT"ordie (" error prompt: ". Mysql_error ()); $jsonArray =arraywhile ($rows =mysql_fetch_array ($query)) {
Handles automatic content within the database $rows [' content ']=mb_substr (Strip_tags (Htmlspecialchars_decode ($rows [' Content '])), 0,100,"Utf-8"); Add the contents of the database to the new array
Array_push ($jsonArray, $rows);//note here is $rows json_encode ($jsonArray);//Convert to JSON to pass to the front end
4. New phptoajax.html front end receive data, here I use jquery encapsulated Ajax method, after the execution of the page as shown:
HTML><HTML><Headlang="en"> <Metacharset="UTF-8"> <title>
Title> <Scripttype="Text/javascript"src="Jquery-1.8.3.min.js">
Script>
Head><Body><ulid="List">
Ul><Scripttype="Text/javascript"> $ (function() {$.ajax ({type:"POST",//Transfer methodURL:"phptoajax.php",//Data interfaceDataType:"JSON",//Receive format success:function(msg)//If received successfully execute the following {varLi=""; for(varI =0;i
<>
length-1;i++)//Here is a limit of 10 {li+= "
"+msg[i][' title ']+"
"+msg[i][' content ']+" ... +msg[i][' id ']+"' target= ' _blank ' > details
"; } $ ("#list"). html (LI); }, Error:function()//If receive does not successfully perform the following
{ console.log (" link error ")});} );
Script>
body>
html>
5. Click the "detailed" link shown in the previous step to view the corresponding article content and create a new phpartcle.php file
require_once ("conn.php"); $id =$_get[' art '];//receive front-end uploaded data
Querying the database for the corresponding content
$query =mysql_query ("select * FROM txt WHERE id= ' $id '") or Die ("article Error:". Mysql_error ());
Iterating through an array, displaying content
if ($rows =mysql_fetch_array ($query)) { "". $rows [' title ']. "
"; " ". Htmlspecialchars_decode ($rows [' content ']). "";}
-------------------finished-----------------------