ryanwood4 Posted June 9, 2009 Share Posted June 9, 2009 Hi, I have extremely limited PHP knowledge, so I apologise in advance. I want to create a list of recent articles posted to this site: http://www.f1times.co.uk I have managed to create a list of title, and url's - http://www.f1times.co.uk/titles.php listed in this file, and managed to limit it to 20 results, and order them by DESC, this is where my knowledge ends. What I want to now do, is make it so the titles are links to the articles. Which means somehow making the titles link to the url next to them. However my problem doesn't end their, the URL's are just the titles separated with dashes (-) I need to add a dash between that and the unique id which is the number, then add .html on the end. Example, this is what I have - http://www.f1times.co.uk/titles.php I want to turn that into this: <a href="http://www.f1times.co.uk/fota-seek-advice-on-2010-breakaway-125.html">FOTA Seek Advice On 2010 Breakaway</a> - without the http://www.f1times.co.uk/ part, which I only added for the example. Does this make any sense? The code I have so far: <?php $con = mysql_connect("localhost","private","private"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("f1times_articles", $con); $result = mysql_query("SELECT * FROM n2s_article ORDER BY article_id DESC LIMIT 0,20"); while($row = mysql_fetch_array($result)) { echo $row['article_title'] . " " . $row['article_url'] . " " . $row['article_id']; echo "<br />"; } mysql_close($con); ?> Thanks to anyone who can help. Quote Link to comment https://forums.phpfreaks.com/topic/161591-solved-php-making-results-into-links-help-please/ Share on other sites More sharing options...
dawsba Posted June 9, 2009 Share Posted June 9, 2009 Hope this helps ps not tested <?php $con = mysql_connect("localhost","private","private"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("f1times_articles", $con); $result = mysql_query("SELECT * FROM n2s_article ORDER BY article_id DESC LIMIT 0,20"); while($row = mysql_fetch_array($result)) { $fileurl = $row['article_url']."-".$row['article_id'].".html"; echo "<a href='<?= $fileurl; ?>'>$row['article_title']</a>"; // if(file_exists($fileurl)){echo "<a href='<?= $fileurl; ?>'>$row['article_title']</a>";}else{echo "NO FILE AVAILABLE";} //<- Try this to check to make sure the file exists. echo "<br />"; } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/161591-solved-php-making-results-into-links-help-please/#findComment-852692 Share on other sites More sharing options...
KevinM1 Posted June 9, 2009 Share Posted June 9, 2009 You don't have to use <?= $fileurl; ?> Since you're already within a PHP code block. You also need to encase any array value you want to be parsed within a string (in this case, $row['article_title']) in curly braces. So, with all that said, simply use: $url = $row['article_url'] . "-" . $row['article_id'] . ".html"; echo "<a href='$url'>{$row['article_title']}</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/161591-solved-php-making-results-into-links-help-please/#findComment-852700 Share on other sites More sharing options...
ryanwood4 Posted June 9, 2009 Author Share Posted June 9, 2009 Thanks for the help, I tried both but get an error: Parse error: syntax error, unexpected $end in /home/f1times/public_html/titles.php on line 21 Using this code: <?php $con = mysql_connect("localhost","private","private"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("f1times_articles", $con); $result = mysql_query("SELECT * FROM n2s_article ORDER BY article_id DESC LIMIT 0,20"); while($row = mysql_fetch_array($result)) { $url = $row['article_url'] . "-" . $row['article_id'] . ".html"; echo "<a href='$url'>{$row['article_title']}</a>"; // if(file_exists($fileurl)){echo "<a href='<?= $fileurl; ?>'>$row['article_title']</a>";}else{echo "NO FILE AVAILABLE";} //<- Try this to check to make sure the file exists. echo "<br />"; } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/161591-solved-php-making-results-into-links-help-please/#findComment-852710 Share on other sites More sharing options...
KevinM1 Posted June 9, 2009 Share Posted June 9, 2009 Remove the line starting with // Quote Link to comment https://forums.phpfreaks.com/topic/161591-solved-php-making-results-into-links-help-please/#findComment-852713 Share on other sites More sharing options...
ryanwood4 Posted June 9, 2009 Author Share Posted June 9, 2009 Thanks to everyone, your very generous with your time! Quote Link to comment https://forums.phpfreaks.com/topic/161591-solved-php-making-results-into-links-help-please/#findComment-852719 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.