Jump to content

Linking to Article


xiledweb

Recommended Posts

Ok guys, hope I can get some help with this. I'm running a site which has different categories for users to post articles about. On my main page I will have a list of all the recent articles submitted. On my nav bar are links to the different categories which will display the most recent articles about only the news items in that category.

What I want to do is list the first 120 characters (probably more) from the article and use the articletext to link to the full article. Here's what I have so far:

[code]$sql = 'SELECT id,LEFT(articletext, 120) 
        FROM article INNER JOIN articlecategory 
        ON article.id=articlecategory.articleid
        WHERE articlecategory.categoryid=4';
if(!result){
die("sql error: ".mysql_error());
}
while ($article = mysql_fetch_array($result)) {
  $id = $article['id'];
  echo '<p>' . $article['LEFT(articletext, 120)'] . '</p>'; [/code]

Could someone point me in the right direction?  ???



Link to comment
https://forums.phpfreaks.com/topic/30299-linking-to-article/
Share on other sites

[quote author=fert link=topic=118252.msg483072#msg483072 date=1165890413]
substr will do what you want.
[/quote]

I'm not familiar with substr...

I did however try adding [code]echo "<td><a href=\"article.php?id=$id\">$articletext</a></td>\n";[/code] but it returned the error [i]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource[/i].
Link to comment
https://forums.phpfreaks.com/topic/30299-linking-to-article/#findComment-139416
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.