Hi, I'm new to this forum, and would appreciate any help on this matter grealty. I have a MYSQL database set up with a table within it called faq. This in turn has the subcatorgaries faq_id which is the Primary Key and faq_title and faq_results which store text segments. I want to read all this data and display it in a list format which is organised by the faq_id, I have almost achieved this with the code that I have written however I have stummbled across a problem which probably due to my incompetence and easy to sort out, however I personally cannot see a way to fix it. The problem is that the PHP I have wirtten will read the MYSQL table, but will not display all the results in the Table only the first or the last result depending on how I order it, can anyone suggest a way I can fix this problem I will enclose the code below; <?php $mysqli = mysqli_connect("localhost", "root", "password", "mydb"); if (mysqli_connect_errno()) { printf("Could not Connect", mysqli_connect_error()); exit(); } else { $sql = "SELECT faq_id, faq_title,faq_reply FROM faq ORDER BY faq_id ASC"; $res = mysqli_query($mysqli, $sql) or die (mysqli_error($mysqli)); if ($res) { $faq_info = mysqli_fetch_array($res); $faq_id = $faq_info['faq_id']; $faq_title = $faq_info['faq_title']; $faq_reply = $faq_info['faq_reply']; $display_block .= "<p>".$faq_id." - ".$faq_title."<br>" .$faq_reply."</p><br>" ; } else { printf("Failed", mysqli_error($mysqli)); } mysqli_close($mysqli); } ?> Code (markup): Any help will be greatly appriciated. Thanks in advance
You basically need to loop through the results to get them all to display. if ($res) { while($faq_info = mysqli_fetch_array($res)){ $faq_id = $faq_info['faq_id']; $faq_title = $faq_info['faq_title']; $faq_reply = $faq_info['faq_reply']; $display_block .= "<p>".$faq_id." - ".$faq_title."<br>" .$faq_reply."</p><br>" ; } } PHP:
Oh, so easy. Doh, thought it needed to loop or something but couldn't thnk of a feasible way to make it work. Thank you soo much, your help is much appreciated the extra bit of code you supllied works beautafully