Hi. Rather than getting ALL of the items everytime and searching the array, create your query with the news_id in it, so you only get the record you need from the database. Here's an example script:
<?php
// Connect to your database, if it fails, die and show the error
if(($db = @mysql_connect("host", "username", "password")) === false) {
die("Could not connect to database!<br />".mysql_error());
}
// Check to see if the news_id is set in the url
if(isset($_GET['news_id'])) {
// create your query that gets the data
$sql = "SELECT * FROM news WHERE news_id='".mysql_escape_string($_GET['news_id'])."'";
// run the query, if it fails, die and show the error
if(($result = @mysql_query($sql, $db)) === false) {
die("Could not execute query!<br />".mysql_error());
}
// Loop through the results of the query, and display subject and body
while($row = mysql_fetch_assoc($result)) {
echo "<div class=\"newsHead\">".$row['subject']."</div>";
echo "<div class=\"newsBody\">".$row['body']."</div>";
}
} else {
// Create the query
$sql = "SELECT news_id, subject FROM news ORDER BY date";
// run the query, if it fails display the error
if(($result = @mysql_query($sql, $db)) === false) {
die("Could not execute query!<br />".mysql_error());
}
// Loop through the results, creating a link using the news_id
while($row = mysql_fetch_assoc($result)) {
echo "<a href=\"".$_SERVER['PHP_SELF']."?news_id=".$row['news_id']."\">".$row['subject']."</a><br />";
}
}
?>