Page 1 of 1
Want to display link and onclick this link redirect content
Posted: Sun Nov 14, 2010 11:34 pm
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...................
Re: Want to display link and onclick this link redirect cont
Posted: Sun Nov 14, 2010 11:41 pm
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>";
Re: Want to display link and onclick this link redirect cont
Posted: Mon Nov 15, 2010 12:54 am
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
Re: Want to display link and onclick this link redirect cont
Posted: Mon Nov 15, 2010 1:17 am
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.