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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.