Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/144117-strange-page-change/
Share on other sites

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 :P 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 :D

 

 

Let me know if you want to see anything else.

Link to comment
https://forums.phpfreaks.com/topic/144117-strange-page-change/#findComment-756208
Share on other sites

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 ^^

Link to comment
https://forums.phpfreaks.com/topic/144117-strange-page-change/#findComment-756212
Share on other sites

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? :P

Link to comment
https://forums.phpfreaks.com/topic/144117-strange-page-change/#findComment-756244
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/144117-strange-page-change/#findComment-756463
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/144117-strange-page-change/#findComment-756646
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/144117-strange-page-change/#findComment-756920
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/144117-strange-page-change/#findComment-756946
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/144117-strange-page-change/#findComment-757174
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.