Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another DIV positioning problem 2

Status
Not open for further replies.

vb6novice

Programmer
Sep 23, 2002
288
US
Please forgive me for asking another 'How do I position my <div>' question.[sad]

My page is a .php file that creates a monthly calendar (7 days across, 5 or 6 rows down) on the fly by pulling records from a mySQL database, and creating the table rows and cells and filling the cell with the appropriate day number and any events for that day as it goes. The database includes a value for event duration. Single day events have a duration of 1 or 0 and just put text in the cell, but if the duration of the event is greater than 1 (e.g. 7 means a weeklong event), I want the event to cover the number of days equal to its duration (like a multiple day event does in Microsoft Outlook).

I want to use a div for the multi-day events. I tried having the php create the div when it encountered a multi-day event,but the div never shows up on the screen, regarless of whether I use absolute or relative positioning.

I also tried creating a string of text to create the div, storing that text to a variable, and then calling that variable in php code after the </table> tag of the calendar, but it just shows up at the bottom of the page and without any of the formatting I tried to give it.

I appreciate all suggestions.

 
Thanks Chris,

Your solution looks good and seems quite simple. This probably would have been easier if I were more adept at using CSS. I will do a trial implementation of that.

The reason I couldn't get the js to work for the php created <td> was that I was trying to run the js to get the offsetParent before the </td> tag, but I guess it can't do that while the creation of the cell is still in progress. Once I got that resolved, I was able to get the coordinates I needed with the js.

Then the challenge was to find a way to pass the value of the js variable to the php, which I determined was not worth the effort, so I decided to keep track of the multi-day divs and their parent positions with an array. After all the php is done running and the divs are created, I loop through the array and move any multi-day divs.

I think my problem is resolved. Several of you deserve a star for sticking with this one.

Thanks to all who contributed.
 
Then the challenge was to find a way to pass the value of the js variable to the php
That's an (almost) impossible challenge, since the php will be done and dusted long before the js comes in to play.

People new to web programming (especially if they start with Javascript) sometimes lose sight of this - php/asp/coldfusion/etc. run on the server, js runs on the client (i.e. browser). You might think that because you write one file with php and javascript commands in it, the two should be able to interact, but that's not how it works.

When the page is requested from the server, it parses through the php commands and turns them into html. By the time it reaches the browser, there's no way it can tell which bits of html were hardcoded and which were php-generated (nor would the browser care anyway). That composite html file can include bits of javascript that would then be executed by the browser.

So your php code could generate whatever html objects were required, and also generate calls to some javascript to position them as required. It's not so straightforward the other way (you're in the realm of "Ajax" programming, which is a good deal more tricky).

Fortunately, as I've demonstrated, you can do it with some CSS and no javascript calls at all.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top