Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking from teaser to full story 3

Status
Not open for further replies.

kupe

Technical User
Sep 23, 2002
376
This (abbreviated) code brings up a list of current stories.

$result = @mysql_query("SELECT CONCAT(Headline, Byline, Newsdate, '<br>') AS Tale FROM StudentNews");
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
while ($row = mysql_fetch_array($result)) {
echo $row['Tale'];
}

I could use a hyperlink to go to a page with similar code that produces the full story.

But, Experts, is there a simpler php-way to do this, please?
 
The hyperlink to the full story seems the most common solution .
Simpler? Probably not - at least not with PHP.
With some client side scripting, hidden <div> tags that reveal the entire story, you could do something - however, it will depend on the visitor if their browser is capable of performing the actions. You'd have to load all stories into the page and then reveal the one clicked on.
I don't think that's a good idea, it uses up bandwith, since everyone getting to the page gets all the content.
I'd stick with a link to another page.
 
Thanks, DRJ478
What I have is a homepage with what's on offer, and then a page carrying most of the current stories. (Your 'bad' idea, I think.)

I gave all stories their own <a name="something"></a> tag in the db. So when you click on the appropriate field, you're taken to the desired story in that page.

Won't work though. (Perhaps there's too much for php to do in the one manouevre.)

Of course, ideally, as you're saying, it's best for only the requested story to arrive on the page.

Thanks very much for your reasoning. Much appreciated.
 
How about:
Code:
<a name="something">[COLOR=red]Click Here for Rest of Story[/color]</a>

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Q: How are your stories stored? In a database?
A: Yes

So, there you go.
I am sure you have a unique ID number for each record in the table - if not, add it to the table and make it autoincrement.
When you retrieve the teaser also get the unique ID.
Write out a link to the full story serving script that passes the sory ID as a GET variable.
Code:
echo '<a href="show_full.php?stid='.$row['id'].'>'.$row['Tale'].'</a>';

The show_full.php then just queries the database for the full story bit selecting the record where the id = $_GET{'stid'].
 
Why not just retrieve the entire story, but then do a substr or something, unless $action == "read".

eg.
if ($action == "read") {
$story = $row['story'];
}
else {
$story = $row['preface'];
}

The preface might also just be:
$story = substr($row['story'], 0, 50) . "...&nbsp;[<a href="?id={$id}&amp;action=read" title="Read Story">Read</a>]";

Olav Alexander Mjelde
Admin & Webmaster
 
DRJ478, traingamer, DaButcher

Thanks very much for the ideas. There's plenty for me to think about the weekend with these. Very grateful.

The coding I used for the <a names=""> tag, by the way, was

... '<br> <a href=\"newspages.php', Hash, '\">', 'Full story here', '</a>', ...

wherein Hash is the field that has the unique names for the tag. Unfortunately, something won't marry the teasers with the matching stories.

Many thanks for these ideas, gentlemen. Cheers
 
When you echo out the teasers, you have the teaser_id
put the teaser_field with the story, as then they have the same id!

Or, you can make a field "teaser_story_story_id", which you make a natural join with, to get the story too!

Olav Alexander Mjelde
Admin & Webmaster
 
Hi DaButcher

Yes, I am using the id now instead of a separate word (for use in name tags) and that works well.

I'm new to this and while I understand mysql much better now, php isn't straight forward for me. (But I'll get it in time.)

I find it amazing that so little php and mysql coding is necessary to manipulate web sites.

Many thanks for your help.
 
no problem!

Just remember to secure variables that go in your mysql query.

You can look up functions like:
trim()
strip_tags()
mysql_real_escape_string()

on php.net (search for them without the braces)

When validating input, I think it's better to simply tell the user "404 - not found", than telling "are you hacking my script??!?".

Dont tell them what they dont need to know :p

You could also run patternchecking to see that it's only integers, but it shouldnt really be needed, if you secure with the escape string.

Olav Alexander Mjelde
Admin & Webmaster
 
All noted, DaButcher. Thanks very much for the advice. Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top