I want to display columns as link and then onclick this link redirect to its content

$query="select * from news";
echo $Title;
echo "<a href='newstest.php'>$Title</a><br>";
//echo "<a href='upload.html'>Upload</a>";

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.
Help me anyone…

Hi Ankit!

Welcome to Sitepoint Forums!!!

You just need to create another page where you can pass the news id (supposed to be unique id/primary key) and with the help of that id you can query the news details:

$query = "SELECT * FROM news"; 
$result = mysqli_query($dbc, $query); 
while($row = mysqli_fetch_array($result)){ 
    echo '<a href="newsdetails.php?NewsId=' . $row['NewsId'] . '">' . $row['Title'] . '</a><br>'; 

Now in newsdetails.php file, grab the news id and query database for the selected news.

$query = "SELECT * FROM news WHERE NewsId=" . mysqli_escape_string($_GET['NewsId']);
$result = mysqli_query($dbc, $query); 
$row = mysqli_fetch_array($result);
echo $row['Content']; 

Hope this helps to move ahead.

Thx for your fast reply friend
but I got this error with ur code.
[B]Warning: mysqli_escape_string() expects exactly 2 parameters, 1 given in C:\wamp\www\NGOProject\danidis.php on line 3

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\NGOProject\danidis.php on line 5[/B]

Now what should I do???/
Anybody Tell me???/:frowning:

Check out what the PHP manual says about [fphp]mysqli_escape_string[/fphp] and what parameters it expects :slight_smile:

Oh… do like this:

$query = "SELECT * FROM news WHERE NewsId=" . mysqli_escape_string($dbc, $_GET['NewsId']);
$result = mysqli_query($dbc, $query); 
$row = mysqli_fetch_array($result);
echo $row['Content'];

Friend It works…
But can u explain me how this code works, especially mysqli_escape_string()???

Check out [fphp]mysqli_real_escape_string/fphp. :slight_smile:

As Anthorny already said, try to dig into the manual with that function.

FYI, always try to read the manual at http://www.php.net/function_name if you see any of the PHP function.