Falren Posted June 20, 2010 Share Posted June 20, 2010 hello all, I am working on a news script using flat file database. and I have it limited to 5 posts but for some reason say i have 2 posts it still shows 3 extra tables.. and not sure why.. here is my script i have right now.. it works fine except its showing extra tables that shouldn't be there while the posts are less then 5 <?php $arr_username = array(); $arr_title = array(); $arr_date = array(); $arr_message = array(); $lines = file('news/news.ass'); foreach($lines as $line){ $explode = explode("||",$line); $arr_username[] = $explode[0]; $arr_title[] = $explode[1]; $arr_date[] = $explode[2]; $arr_message[] = $explode[3]; } array_multisort($arr_date,SORT_DESC,$arr_username,$arr_title,$arr_message); $i = 0; $lines3 = count($lines); if($lines3 == 0) { echo "No news have been posted"; }else{ foreach($explode as $key=>$ray){ ?> <table id="Table_01" width="488" border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="5"> <img src="images/news_01.gif" width="488" height="10" alt=""></td> </tr> <tr> <td> <img src="images/news_02.gif" width="11" height="21" alt=""></td> <td background="images/news_03.gif" width="198" height="21"> <?php echo "" . $arr_title[$key] . ""; ?></td> <td colspan="2"> <img src="images/news_04.gif" width="267" height="21" alt=""></td> <td> <img src="images/news_05.gif" width="12" height="21" alt=""></td> </tr> <tr> <td> <img src="images/news_06.gif" width="11" height="7" alt=""></td> <td colspan="3"> <img src="images/news_07.gif" width="465" height="7" alt=""></td> <td> <img src="images/news_08.gif" width="12" height="7" alt=""></td> </tr> <tr> <td background="images/news_09.gif" width="11"> </td> <td colspan="3" background="images/news_10.gif" width="465"> <?php echo "" . $arr_message[$key] . ""; ?></td> <td background="images/news_11.gif" width="12"> </td> </tr> <tr> <td> <img src="images/news_12.gif" width="11" height="7" alt=""></td> <td colspan="3"> <img src="images/news_13.gif" width="465" height="7" alt=""></td> <td> <img src="images/news_14.gif" width="12" height="7" alt=""></td> </tr> <tr> <td> <img src="images/news_15.gif" width="11" height="23" alt=""></td> <td colspan="2"> <img src="images/news_16.gif" width="236" height="23" alt=""></td> <td background="images/news_17.gif" width="229"> Posted by <?php echo "" . $arr_username[$key] . ""; ?> on <?php echo $arr_date[$key]; ?></td> <td> <img src="images/news_18.gif" width="12" height="23" alt=""></td> </tr> <tr> <td colspan="5"> <img src="images/news_19.gif" width="488" height="12" alt=""></td> </tr> <tr> <td> <img src="images/spacer.gif" width="11" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="198" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="38" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="229" height="1" alt=""></td> <td> <img src="images/spacer.gif" width="12" height="1" alt=""></td> </tr> </table> <?php } if(++$i > 4) break; } ?> Link to comment https://forums.phpfreaks.com/topic/205297-news-script-limit-posts/ Share on other sites More sharing options...
jonnypixel Posted June 20, 2010 Share Posted June 20, 2010 Hi, I'm only a noob. But your HTML Table is like static? You need to Create a Fetch Array - and limit the number of rows to 5 ( $rows = mysql_num_rows($result); ) You obviously need a correct qeury script based on variablesand field names from your table but below is how a Dynamic table is generated. <?php // Make a MySQL Connection // Get all the data from the "example" table $result = mysql_query("SELECT * FROM example") or die(mysql_error()); Somewhere here you would check the $rows count and display accordingly. echo "<table border='1'>"; echo "<tr> <th>Name</th> <th>Age</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['name']; echo "</td><td>"; echo $row['age']; echo "</td></tr>"; } echo "</table>"; ?> I'm not sure you could hide the other tables because they are not dynamically made. They are hand coded. Hope that helps, Try googling TIZAG and start at the MYSQL tutorials. Good Luck Link to comment https://forums.phpfreaks.com/topic/205297-news-script-limit-posts/#findComment-1074564 Share on other sites More sharing options...
Falren Posted June 20, 2010 Author Share Posted June 20, 2010 hey jonnypixel, I am using flat file database not MySQL, flat file databases you call from a text file. Link to comment https://forums.phpfreaks.com/topic/205297-news-script-limit-posts/#findComment-1074599 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.