garfee Posted February 23, 2009 Share Posted February 23, 2009 Hi there. I am about as new to PHP and SQL and you can get so please go easy on me. If my question looks stupid it is because I have very little experience and am just starting out. Basically, I am building a website that has written articles stored in a database. I really need to echo a list of the article title's on one page and use them as hyper links. When these links are clicked, I need the next page to show the title, article and author. This is info held on the database. However, I only want to drag the raw data from the database tables and print it each time on a single static html page that has some design to it. So basically I want the site information to come from the sql database but only be printed on one page each time. A friend of mine gave me some code which uses a Gid but I cannot seem to get it to work. The article title is displayed as a hyperlink but when I click on it nothing happens. Can somebody help me or point me in the right direction please. Any help will be greatly appreciated. The code that I am using is below. The php page is called selected.php <?PHP $con = mysql_pconnect ("localhost", "username", "password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db ("db_name", $con); if (!$Gid) { $result = mysql_query ("SELECT * FROM table_mysql"); $nRows = mysql_num_rows($result); ?> <h1>Selected Article</h1> <?PHP for ($i=0; $i< $nRows; $i++){ $row = mysql_fetch_array($result); ?> <a href="selected.php?Gid=<?PHP echo $row['id'] ?>"><?PHP echo $row['title']." - <i>".$row['author']."</i>" ?></a><br /> <?PHP } } else { $result = mysql_query ("SELECT * FROM table_mysql WHERE id = ".$Gid.""); $nRows = mysql_num_rows($result); for ($i=0; $i< $nRows; $i++){ $row = mysql_fetch_array($result); $entry = str_replace(chr(10), '<br />', $row['entry']); ?> <h1><?PHP echo $row['title'] ?></h1> <p><?PHP echo $entry ?></p> <p>©<?PHP echo $row['author'] ?></p> <?PHP } } mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/146592-gid-using-one-html-page-for-background-and-printing-raw-data-from-sql-database/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.