Claite Posted February 6, 2009 Share Posted February 6, 2009 I really hope I can explain this properly. I'll try my best but if you still don't understand, please ask. I'm currently working on a page (using tables), and everything is lined up and working properly. However, when I put more content than the height of the browser window, everything shifts and is mis-aligned. Below you can see pics of what happens from being normal, to exceeding text. I put in a scrollable cell for the news, so that it never goes over the size of the browser, but that limits me on how many links I can put, and scrunches the page. I'd prefer to just fix the formatting problem. (posting links do to size) http://i59.photobucket.com/albums/g287/Claite/PHP%20page/okpage.jpg http://i59.photobucket.com/albums/g287/Claite/PHP%20page/pooppage.jpg Also, so I don't start a new topic for no reason. I wrote my own news script in php that reads from a file. The only problem is that I'm using a for loop. How do I write a "while file still has lines" code? What I have: <?php $myFile = "news.txt"; $news = fopen($myFile, 'r'); for ($i = 1; $i <= 5; $i++){ but I want it to go for just how many news things I have. Also, later I want to put a limit to 5 news articles. But that's a later problem. Thanks for all the help in advance! Claite Quote Link to comment Share on other sites More sharing options...
landavia Posted February 6, 2009 Share Posted February 6, 2009 yap.. this stranget too well.. let me ask something. 1.why you not use DB but used text 2. i want to see what inside your text 3. i want 2 see your full code <?php $myFile = "news.txt"; $news = fopen($myFile, 'r'); for ($i = 1; $i <= 5; $i++){ ....???? Quote Link to comment Share on other sites More sharing options...
Claite Posted February 6, 2009 Author Share Posted February 6, 2009 I used a text file because it's easier for me as a user to edit. I just need to open it up and write what I want, then the code for the site takes it and produces the format. Here is my full code after what I post (including what I posted as well): <!-- ~~~~~~~~~~~~~~~~~~~~~ NEWS ~~~~~~~~~~~~~~~~~~~~~~ --> <?php $myFile = "news.txt"; $news = fopen($myFile, 'r'); for ($i = 1; $i <= 5; $i++){ $title = fgets($news); ?> <font style="font-family:Cambria" size=5><b><?php echo $title ?></b></font> <img src="images/newsbar2point0.png"></img> <br> <img src="images/avatar.png" align="left"></img> <?php $name = fgets($news); ?> <font color="#AAAAAA" size="2">By <?php echo $name ?></font><br> <?php $theData = fgets($news); ?> <p><?php echo $theData ?></p><br><br> <?php $blankline = fgets($news); } fclose($news); ?> and here's my text file: Test of php news Mah Name 2/06/2009 This is a test of my php news program reading from a file. I need to remember to put the new news at the top of the file I really hope this works! New Site up! Mah Name 2/05/2009 Welcome to the new site! This will be for everything and anything about me. I'll be posting my work with various programs such as inventor solidworkd, 3ds max, or programming. You can find all those in the tutorial section. Also, I will eventually be integrating a "in-site" private messaging and forums for input on the content of the site. To be honest, eventually this site will be more for you guys then for me. To register go <a href="register.html">HERE</a> This is a test in the change of code Let me know if you want to see anything else. Quote Link to comment Share on other sites More sharing options...
landavia Posted February 6, 2009 Share Posted February 6, 2009 hmm.. this not good.. my suggestion are like this Test of php news[br] Mah Name 2/06/2009[br] This is a test of my php news program reading from a file. I need to remember to put the new news at the top of the file I really hope this works! [EOF] New Site up! [br] Mah Name 2/05/2009[br] Welcome to the new site! This will be for everything and anything about me. I'll be posting my work with various programs such as inventor solidworkd, 3ds max, or programming. You can find all those in the tutorial section. Also, I will eventually be integrating a "in-site" private messaging and forums for input on the content of the site. To be honest, eventually this site will be more for you guys then for me. To register go <a href="register.html">HERE</a> This is a test in the change of code [EOF] 1. i just explode above with [eof] 2. i explode again with [br] after that.. u will have $aUpdate[1][0] .... then like u said earlier.. u want to view only 5? and just play with the array ^^ Quote Link to comment Share on other sites More sharing options...
Claite Posted February 6, 2009 Author Share Posted February 6, 2009 Explode? I'm sorry, I'm really new to PHP (with only a little experience of html) Is that basically adding it to an array then I just check if the array has contents, then do the print out stuff, if not, stop? And if it is like that, how would I do it in my code? Quote Link to comment Share on other sites More sharing options...
landavia Posted February 7, 2009 Share Posted February 7, 2009 lets try this <?php /*pretended this taken from file.txt*/ $str="landavia[br/]2009-02-01[br/]I live in Jakarta and now work as programer[eof] claite[br/]2009-02-05[br/]Someone help me during my work, i think no body perfect[eof] claite[br/]2009-02-06[br/]My PC Crashed.. hope my data are return[eof] claite[br/]2009-02-06[br/]wew... i have my data back. Now lets bussy and study PHP[eof]"; $ar1=explode("[eof]",$str); //create into array foreach($ar1 as $val) { $ar2=explode("[br/]",$val); $aUpdate[]=$ar2; } echo "<pre>"; print_r($aUpdate); echo "</pre>"; phpinfo(); ?> try above script. btw.. what is your PHP version? Quote Link to comment Share on other sites More sharing options...
haku Posted February 7, 2009 Share Posted February 7, 2009 When you say the alignment is getting thrown off, do you mean that everything is getting shifted to the left a little? I looked at both your images, but I wasn't sure exactly what you were referring to. Quote Link to comment Share on other sites More sharing options...
Claite Posted February 7, 2009 Author Share Posted February 7, 2009 Haku, yes. That's been a bother very much. Since I want it to remain the sizes they are (and the code has definite table size) but they still change. I've tried changing the table values (increasing) to try to push it right... now thinking about it. I think the addition of the scroll bar (since page exceeds browser height) it shoves everything right. How can I prevent this? I'm ok with some of the page being covered by the scroll bar... Landavia, I'll try to use that. Thank you very much. It just seems pretty counter-intuitive to have all those variables and have it re-assigned so many times. Thanks again for all your help! I'm using $myFile = "news.txt"; $news = fopen($myFile, 'r'); while (!feof($news)){ $title = fgets($news); after I get more news, I'll add the for loop to 5. But this will work for the first... few days lol EDIT: Btw, I'm using 5.2.8 Quote Link to comment Share on other sites More sharing options...
landavia Posted February 7, 2009 Share Posted February 7, 2009 i think about the page strange must be ignore for this time.. let's focus on how you take 5 news/update from your filetext Quote Link to comment Share on other sites More sharing options...
Claite Posted February 7, 2009 Author Share Posted February 7, 2009 That part is working though... I need to fix the strange part... I posted how I'm doing the php loop now, and it works just fine Quote Link to comment Share on other sites More sharing options...
landavia Posted February 7, 2009 Share Posted February 7, 2009 is like you need to use <div> but i don't get it either.. well.. hope someone able to solve your problem fyi: i notice pic no 1 are shown image (blank) size about 100? and put before title and pic no 2.. don't have image? is this a image position problem? Quote Link to comment Share on other sites More sharing options...
Claite Posted February 7, 2009 Author Share Posted February 7, 2009 If you're talking about the shift in the title/header, that has to do with the rest of the page moving. The problem is that the scroll bar appears, and that scrunches my page, but I don't understand why. Shouldn't a page remain the same size and have the browser just add a necessary bottom scroll bar? Quote Link to comment Share on other sites More sharing options...
Claite Posted February 7, 2009 Author Share Posted February 7, 2009 Super apologies from the double post, but I want any mod that might have read the message above to also read this one (since edits don't appear as new posts) I fixed the issue. Everything still shifts but I just made the sidebar a little thinner (the login area) so when the page shifts due to the exceeded page size, it doesn't overlap. Thanks for all the help, Claite Quote Link to comment Share on other sites More sharing options...
haku Posted February 8, 2009 Share Posted February 8, 2009 The shift is caused by the appearance of the scroll bar, as you surmised. I just wanted to confirm that that is what you were speaking of. The simplest way to deal with this shift is to force the appearance of scrollbars on all pages. You can do that by adding this to your CSS: html { overflow-y: scroll; } You will of course have to code your page to work with the scroll bars. 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.