Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
Old 09-15-2009, 07:59 PM   #1 (permalink)
Junior Member
 
Systematic's Avatar
 
Join Date: 08-29-09
Posts: 5
iTrader: 0 / 0%
Latest Blog:
None

Systematic is liked by many
Dynamic Links and Browsing Data from MySQL

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:
Code:
  1. 1
  2. 2
  3. 3
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.

Last edited by Systematic; 09-15-2009 at 08:05 PM..
Systematic is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-20-2009, 11:07 AM   #2 (permalink)
Junior Member
 
Join Date: 09-20-09
Posts: 1
iTrader: 0 / 0%
Latest Blog:
None

lastid is liked by many
If I understand correctly, you need to structure your PHP page in the following way:

Quote:
// Display article list
//...

// If <id> passed as a GET/POST/COOKIE argument, display the corresponding article in the rest of the page
if (isset($_REQUEST['id']))
{
$id=$_REQUEST['id']);
// Fetch article from MySQL
// ....
// Display article
// .....
}
lastid is offline  
Add Post to del.icio.us
Reply With Quote
Old 09-20-2009, 11:56 AM   #3 (permalink)
Junior Member
 
Systematic's Avatar
 
Join Date: 08-29-09
Posts: 5
iTrader: 0 / 0%
Latest Blog:
None

Systematic is liked by many
Well, yeah. I was able to do that by using the following code:

Code:
<?php $connection = mysql_connect("localhost","root","") or mysql_error(); mysql_select_db("articles",$connection) or mysql_error(); if(!isset($_GET['id'])) { $_GET['id'] = NULL; } $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>"; } $id = $_GET['id']; $sql=mysql_query("SELECT * FROM content WHERE id='$id'"); while ($rows=mysql_fetch_assoc($sql)) { echo $rows['body']; } ?>
And when I click the link, the article is shown but also the articles list is shown too. Here is a screenshot of what I mean:



All I want is that the list will be removed and article will be visible, only when a link in the list is cicked.
Systematic is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Asp site database to mysql data conversion simi Web Hosting Forum 3 03-23-2009 08:53 AM
Dynamic PHP problem !! transfer data from one page to another using PHP and mysql 2939195631902 Coding Forum 6 01-22-2009 06:30 AM
Dynamic form, getting the $_POST data iridius Coding Forum 2 06-15-2008 05:29 PM
(PHP/Mysql) Question reguarding tables and sharing data between. MephDaddy Coding Forum 3 08-25-2007 02:09 PM


Sponsor Links
Get exposure! Contextual Links V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 08:49 PM.
© Copyright 2008 V7 Inc
Powered by vBulletin
Copyright © 2000-2009 Jelsoft Enterprises Limited.


Search Engine Optimization by vBSEO 3.3.0 ©2009, Crawlability, Inc.