xiledweb Posted December 12, 2006 Share Posted December 12, 2006 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 More sharing options...
fert Posted December 12, 2006 Share Posted December 12, 2006 substr will do what you want. Link to comment https://forums.phpfreaks.com/topic/30299-linking-to-article/#findComment-139414 Share on other sites More sharing options...
xiledweb Posted December 12, 2006 Author Share Posted December 12, 2006 [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 More sharing options...
fert Posted December 12, 2006 Share Posted December 12, 2006 [quote author=xiledweb link=topic=118252.msg483074#msg483074 date=1165890923]I'm not familiar with substr...[/quote]then look it up on php.net Link to comment https://forums.phpfreaks.com/topic/30299-linking-to-article/#findComment-139421 Share on other sites More sharing options...
xiledweb Posted December 12, 2006 Author Share Posted December 12, 2006 I am, but I'm not sure I understand how its going to help me with my problem. Link to comment https://forums.phpfreaks.com/topic/30299-linking-to-article/#findComment-139424 Share on other sites More sharing options...
fert Posted December 12, 2006 Share Posted December 12, 2006 [quote]What I want to do is list the first 120 characters (probably more)[/quote]That's what it will help you with. Link to comment https://forums.phpfreaks.com/topic/30299-linking-to-article/#findComment-139449 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.