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

<?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='newstest.php'>$Title</a><br>";
$NewsId=$row['NewsId'];
}
//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.
Plzzzzzzzzzzzzzzzz
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:


require_once('database.php'); 
$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.


require_once('database.php'); 
$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:


require_once('database.php'); 
$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…
Thxxxxxxxxxxxxxxxxxx
But can u explain me how this code works, especially mysqli_escape_string()???
plz…

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.