wiggst3r Posted June 30, 2008 Share Posted June 30, 2008 Hi I'm trying to write a news archive system, which, on the news page, displays one news article and links to the others in the db. When I click on the link to one of them, I want it to display in another page, and just display that particular article. I'm trying to write a while loop, which loop through the articles, and displays the individual article, based on it's id, but i'm a little stuck. I've written a fucntion to display the news article function get_one_article($id) { $id = mysql_real_escape_string($id); $query = "SELECT * FROM news WHERE id = '$id' LIMIT 1"; $result = @mysql_query ($query); // Run the query. $num = mysql_num_rows($result); $one_row = mysql_fetch_array($result, MYSQL_ASSOC); return $one_row; } I want to put the following code into a while loop and get the news story for it's id echo $one_row = get_one_article($_GET['id']); When i var_dump that code, I can see the articles details, just can't seem to loop through and print it to the screen Thanks Quote Link to comment Share on other sites More sharing options...
interpim Posted June 30, 2008 Share Posted June 30, 2008 you need to assign the data in the tables to variables and echo those variables to the page. All you are doing is returning the row from your table with the code you have shown Quote Link to comment Share on other sites More sharing options...
wiggst3r Posted July 1, 2008 Author Share Posted July 1, 2008 Any idea how I could do that? Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted July 1, 2008 Share Posted July 1, 2008 But if you're getting one news article, why would you need to loop? For that matter, what could possibly be looped through? If you're only grabbing one row, you do the mysql_fetch_array and then you're done. Right? What more is there to do? fake edit: oh I think I see what you're doing. You're going about it the wrong way though. your while loop needs to be like this $query = "SELECT * FROM News WHERE ***insert range of id's desired, such as id > '1' AND id < '10' or something *** "; $result = mysql_query($query); while($row = mysql_fetch_array)) { echo "$row[article_name]<br>\n $row[article_description]<br>\n "; // and so on... variables made up bc I dont know what yours are called } oh, and if you're only trying to get one id(instead of a range of id's) just do the query like you have it, but then use the code I provided. The way I have it setup, it will automatically step through all rows selected, whether it's just one or 10 or however many 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.