<?php
require_once('database.php');
$query="select * from news";
$result=mysqli_query($dbc,$query);
while($row=mysqli_fetch_array($result)){
$Title=$row['Title'];
//$Content=$row['Content'];
echo $Title;
echo "<a href=''>$Title</a><br>";
}

?>

Hi friends....
I have a table named news which contain columns such as Title, Content,NewsId and many more.
I want to display titles in form of link and when we click any link we get its corresponding Content.
By above code I display Title as link but don't know how to display its corresponding Contents on click.

Plzzzzzzzzzzzzzzzz
Help me anyone...................

Recommended Answers

All 3 Replies

<?php
require_once('database.php');
$query="select * from news";
$result=mysqli_query($dbc,$query);
while($row=mysqli_fetch_array($result)){
$NewsId=$row['NewsId']
$Title=$row['Title'];
//$Content=$row['Content'];
echo $Title;
echo "<a href=somePage.php?NewsId=$NewsId>$Title</a><br>";
}
?>

In the somePage.php use following

<?php
require_once('database.php');
$NewsId = $_POST['NewsId'];
$query="select * from news where NewsId = '$NewsId'";
$result=mysqli_query($dbc,$query);
while($row=mysqli_fetch_array($result)){
$Content=$row['Content'];
echo $Content;
}
?>

Or you can use that in the same page, then use the following
Add the condition above the news content code

<?php
if($_POST['NewsId'])
{
require_once('database.php');
$NewsId = $_POST['NewsId'];
$query="select * from news where NewsId = '$NewsId'";
$result=mysqli_query($dbc,$query);
while($row=mysqli_fetch_array($result)){
$Content=$row['Content'];
echo $Content;
}
}
?>

Hope this code work for you.
I wrote it directly here.

Thanks for ur code but this code gives an error "Notice: Undefined index: NewsId in C:\wamp\www\NGOProject\somePhp.php on line 3".
It means php not recognise $NewsId.
Help me PLzzzzzzzzzzzzzzz........
Any one???????????

Ok make it as $NewsId = $_REQUEST;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.