driz Posted December 6, 2007 Share Posted December 6, 2007 initial problem fixed, see further down. x Link to comment Share on other sites More sharing options...
justsomeguy Posted December 6, 2007 Share Posted December 6, 2007 I see 4 posts and none of them really look different from the other ones. Link to comment Share on other sites More sharing options...
driz Posted December 6, 2007 Author Share Posted December 6, 2007 okay i dunno why, but the posts are appearing, but we keep getting a random one added as well, which is blank with a / in the date bit, why is a blank one being added? thanks.x Link to comment Share on other sites More sharing options...
justsomeguy Posted December 6, 2007 Share Posted December 6, 2007 You have blank lines in the text file that the PHP script thinks are a separate post. You split up the text file into lines and then treat each line as a post. Either remove the blank lines in the text file or change the script to check if the line is blank before it prints a post. Link to comment Share on other sites More sharing options...
driz Posted December 6, 2007 Author Share Posted December 6, 2007 How do i check for blank posts before printing them?Also how could i add small delete buttons to the posts that i can click to delete.THANKS Link to comment Share on other sites More sharing options...
justsomeguy Posted December 6, 2007 Share Posted December 6, 2007 Instead of this:if(!empty($line))Do this:if (trim($line) != "")Deleting isn't very easy with a text file-based system, at least compared to a database. You'll need to print delete links with a counter where you count each post. So you will need a counter variable that gets incremented whenever you print a post that you can attach to a delete link, something like this:<a href="index.php?mode=delete&post=<?php echo $counter; ?>">delete</a>The PHP script will need to check the $_GET['mode'] variable to see if it equals "delete", get the $_GET['post'] variable to see which post to delete, and then count through the file until you find that post. If you use the file function to read the file into an array, you can just delete that array element and write the array back to the file, or something like that. Link to comment Share on other sites More sharing options...
driz Posted December 8, 2007 Author Share Posted December 8, 2007 ... Link to comment Share on other sites More sharing options...
driz Posted December 9, 2007 Author Share Posted December 9, 2007 any updates? Link to comment Share on other sites More sharing options...
justsomeguy Posted December 10, 2007 Share Posted December 10, 2007 If you want to alternate between two things you can use mod. $nr = 0;while (...){ if ($nr % 2) { // choice 1 } else { // choice 2 } $nr++;} Link to comment Share on other sites More sharing options...
driz Posted December 10, 2007 Author Share Posted December 10, 2007 where abouts in the code does that go? and what goes in the while loop? thanks. x Link to comment Share on other sites More sharing options...
justsomeguy Posted December 10, 2007 Share Posted December 10, 2007 That code doesn't go anywhere, it's an example of how to use the mod operator and a counter to decide between 2 cases. You already have a foreach loop there, you can add a counter and use mod to figure out which case you're in. Link to comment Share on other sites More sharing options...
Synook Posted December 10, 2007 Share Posted December 10, 2007 You could even just flip between true and false for a variable: $nr = true;while (...) { if ($nr) { // choice 1 } else { // choice 2 } $nr = !$nr;} This may be slightly faster than incrementing the variable. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.