melbtrip Posted November 23, 2007 Share Posted November 23, 2007 How do I have The menu and the context information display at the same time? here is an example page www.melbtrip.com/newstan/article2.php here is the mysql database code I am using: CREATE TABLE news( id INT NOT NULL AUTO_INCREMENT, title VARCHAR(50) NOT NULL, content TEXT NOT NULL, PRIMARY KEY(id) ); <?php { $self = $_SERVER['PHP_SELF']; $query = "SELECT id, title FROM news ORDER BY id"; $result = mysql_query($query) or die('Error : ' . mysql_error()); // create the article list $content = '<ol>'; while($row = mysql_fetch_array($result, MYSQL_NUM)) { list($id, $title) = $row; $content .= "<li><a href=\"$self?id=$id\">$title</a></li>\r\n"; } $content .= '</ol>'; $title = 'Available Articles'; } { // get the article info from database $query = "SELECT title, content FROM news WHERE id=".$_GET['id']; $result = mysql_query($query) or die('Error : ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $title = $row['title']; $content = $row['content']; } include 'library/closedb.php'; ?> <html> <head> <title> <?php echo $title;?> </title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- h1 { font-family: Arial, Helvetica, sans-serif; font-size: 18px; color: #006699; font-weight: bold; } .main { padding: 10px; border: 1px solid #006699; position: relative; width: 580px; margin-top: 20px; margin-bottom: 20px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; } --> </style> </head> <body> <table width="600" border="0" align="center" cellpadding="10" cellspacing="1" bgcolor="#336699"> <tr> <td bgcolor="#FFFFFF"> <h1 align="center"><?php echo $title;?></h1> <?php echo $content; // when displaying an article show a link // to see the article list if(isset($_GET['id'])) { ?> <p> </p> <p align="center"><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Article List</a></p> <?php } ?> </td> </tr> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/78615-php-menu-problem/ Share on other sites More sharing options...
revraz Posted November 23, 2007 Share Posted November 23, 2007 What's the point of this? include '.../...'; include '.../....'; Link to comment https://forums.phpfreaks.com/topic/78615-php-menu-problem/#findComment-397795 Share on other sites More sharing options...
melbtrip Posted November 23, 2007 Author Share Posted November 23, 2007 What's the point of this? include '.../...'; include '.../....'; it was my database connection, I know the database works, but something in my PHP is incorrect I think the problem is in this part of code { // get the article info from database $query = "SELECT title, content FROM news WHERE id=".$_GET['id']; $result = mysql_query($query) or die('Error : ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $title = $row['title']; $content = $row['content']; } Link to comment https://forums.phpfreaks.com/topic/78615-php-menu-problem/#findComment-397797 Share on other sites More sharing options...
melbtrip Posted November 24, 2007 Author Share Posted November 24, 2007 { $query = "SELECT id, title, content ". "FROM news ". "WHERE id = '{$_GET['id']}'"; $result = mysql_query($query) or die('Error : ' . mysql_error()); list($id, $title, $content) = mysql_fetch_array($result, MYSQL_NUM); } I think I have work it out, but problems is now I can't get the first id information when the person goes to http://www.melbtrip.com/newstan/article8.php. Link to comment https://forums.phpfreaks.com/topic/78615-php-menu-problem/#findComment-397942 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.