justlukeyou Posted July 2, 2012 Share Posted July 2, 2012 Hi, I have set an article system for my site. However, whenever I select a category it only displays the first article. If I have 3 articles under "football" it only displays the first article. This is the code I have to Get the article category. <?php if (isset($_GET['articlecategory'])) $articlecategory = mysql_real_escape_string($_GET['articlecategory']); $sql = "SELECT * FROM articles WHERE articlecategory = '$articlecategory' ORDER BY ID DESC LIMIT 15"; $res = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($res); // no need to loop since you are retrieving only one row $num_rows = mysql_num_rows($res); // check to see if any results were found, just in case someone puts an ID in the url without clicking on your link ?> This is the code I am using to echo the articles in. Any suggestions please? <div class="articlesborder"> <div class="articlestitleborder"><a href="http://ukhomefurniture.co.uk/articles/article/<?php echo $row['ID']; ?>" class='articleslink' rel="nofollow" ><?php echo $row['title']; ?></a></div> <div class="articlesintroborder"><?php echo $row['intro']; ?></div> <div class="articlesdateborder"><?php echo $row['date']; ?></div> <div class="articlesintroborder"><?php echo $row ['articlecategory']; ?></div> <div class="articlescontentborder"><?php echo $row['articleintro']; ?></div> <div class="articlesimageborder"><a href="http://ukhomefurniture.co.uk/articles/article/<?php echo $row['ID']; ?>" rel="nofollow" ><img src="<?php echo $row['image']; ?>" /></a></div> </div> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 2, 2012 Share Posted July 2, 2012 The answer is there, right in your own comments in the code. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted July 2, 2012 Author Share Posted July 2, 2012 Can you shed a bit more light on it please? Ive confused myself in setting it up. How would I loop it? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 2, 2012 Share Posted July 2, 2012 Since this is true: no need to loop since you are retrieving only one row What do you think you need to do if there is more than one record returned? Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted July 2, 2012 Author Share Posted July 2, 2012 Yes sorry, how would I perform a loop? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted July 2, 2012 Share Posted July 2, 2012 Does this look familiar: while? Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted July 2, 2012 Author Share Posted July 2, 2012 Yeah, the thing is I dont understand the PHP one bit. It doesn't explain anything in a beginners format. I just find theirs not enough examples to follow. But its set me in the direction. Thanks. Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 2, 2012 Share Posted July 2, 2012 The docs on mysql_query has plenty of examples. When you come to a section you don't understand, research the topics within it you don't understand. It's like reading any book - if you don't know a word, look it up. Quote Link to comment 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.