Hey there. This is a quite basic thing but I'm struggling as I'm still a PHP newbie. I did a search but couldn't find a satisfying content which clearly explains this on the net. So, here is my question. I created a dynamic PHP page which reads and echoes the data from a MySQL database. What I want is that the page will first list the content in the database as links and when clicked the links, without leaving the page, the new content will be loaded.
This is the database structure on phpmyadmin:
- articles (database name)
- content (holds the content of an article)
- id (article id which automatically increases)
- subj (article subject)
- body (article body)
The articles in this database are shown on a page named 'articles.php'. I did this part and it's working perfectly. Here is the PHP code:
Code:
$connection = mysql_connect("localhost","root","") or mysql_error();
mysql_select_db("articles",$connection) or mysql_error();
$sql = mysql_query("SELECT * FROM content",$connection) or die("Database Error...");
while($list = mysql_fetch_assoc($sql)) {
echo "<ul>";
echo "<li>";
echo "<a href=\"?id={$list['id']}\">";
echo $list['id'];
echo "</a>";
echo "</li>";
echo "</ul>";
}
Output is like:
Now, here is the part I failed to do. Let's say you clicked the link "1" and the address will be like "www.example.com/articles.php?id=1" and the list will vanish as the clicked article loads. What am I supposed to do?
Thanks in advance.