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>

Link to comment
Share on other sites

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>";
}

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.