Jump to content

Displaying select content from a database


ianco

Recommended Posts

Hi All,

 

I have a list of database entries displayed as a menu i.e.,

 

Info1

Info2

Info3

etc.

 

Each entry contains a news story.

 

The question is:

 

what php code do i need so that when i click on one of these links the related story appears in a page?

 

My code so far for displaying a full list of entries is

$sql="SELECT XMashTitle, XMashContent FROM XMash ORDER BY XMashID DESC";
$result=mysql_query($sql);

$options="";

while ($row=mysql_fetch_array($result)) {

    $XMashTitle=$row["XMashTitle"];
    $XMashContent=$row["XMashContent"];
    $options.='<li class="blog"><b>' . $XMashTitle . "</b><br>" . $XMashContent . "</li>";
}


mysql_close($con);

?>

<ul class="blog">
   <?=$options?>
</ul><br>

Managed to solve it with the following

 


if(isset($_GET['XMashID'])) {
  $id = $_GET['XMashID'];
  $q = mysql_query("SELECT * FROM XMash WHERE XMashID = $id") or die(mysql_error());
  // display your info here for the single person
  $row = mysql_fetch_assoc($q);
  echo "<p><b>" . $row['XMashTitle'] . "</b><br>" . $row['XMashContent']."</p><br>";

}


$q = mysql_query("SELECT * FROM XMash ORDER BY XMashID DESC LIMIT 10") or die(mysql_error());
while($r = mysql_fetch_array($q)) {
  $id = $r['XMashID'];
  $name = $r['XMashTitle'];
  echo "<a href='ScienceMash.php?XMashID=$id'>$name</a><BR>";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.