Want to display link and onclick this link redirect content

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ankit.pandeyc012
Forum Newbie
Posts: 8
Joined: Sun Nov 14, 2010 11:25 pm

Want to display link and onclick this link redirect content

Post by ankit.pandeyc012 »

Code: Select all

<?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>";
$NewsId=$row['NewsId'];
}
?>
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...................
s992
Forum Contributor
Posts: 124
Joined: Wed Oct 27, 2010 3:06 pm

Re: Want to display link and onclick this link redirect cont

Post by s992 »

Well, right now the link doesn't point anywhere. You probably need to determine what sort of URL string each story will have and fill it in there.

For example, your URL might look like http://www.yoursite.com/story.php?id=123 . Assuming you wrote the code to pull and display the content at story.php, you could then just dynamically generate a link to each story:

Code: Select all

echo "<a href='http://www.yoursite.com/story.php?id=$NewsId'>$Title</a><br>";
rolyestemonio
Forum Newbie
Posts: 19
Joined: Fri Jun 18, 2010 10:30 pm
Location: Metro Manila - Paranaque City
Contact:

Re: Want to display link and onclick this link redirect cont

Post by rolyestemonio »

Code: Select all

<?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='news.php?id=".$row['id']. '>$Title</a><br>";
$NewsId=$row['NewsId'];
}
?>
i put the tag <a> with the href and i put ?id=row['id'] so in the next page i will call the data "SELECT ..... WHERE id = '".$_REQUEST['id']."'"; and you just execute that query and it will bring the data for the ID and it will know wat data must call
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Re: Want to display link and onclick this link redirect cont

Post by agriz »

Code: Select all

<?
$id = $row['NewsId'];
?>
<a href="news_page.php?id=$id">Your title</a>
This is will lead you to news_page.php Create a new page in the name and the following code

Code: Select all

<?
require_once('database.php');
$query="select * from news WHERE NewsId = ".$_GET['id'];
$result = mysql_query($query);
$news_result = mysql_fetch_array($result);

echo $news_result['Content'];
?>

Not tested. This is the logic however. Query in the view page is not really good. But testing you can use this code.
Post Reply