Jump to content

php menu problem


melbtrip

Recommended Posts

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
Share on other sites

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
Share on other sites

{

$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.