"need rotating div display, preferably in PHP"

need a rotating div display, similar to rotating slideshow - preferably in PHP, since will interface with database. see http://www.cshlaw.com/cai/ - upper right is [a] a photo, next to it is a caption, below it is [c] the name of the person associated with the photo [will always be an attorney's photo], [d] a Practice Area associated with that person. Each field ultimately i want to be a record in a table to populate that UPPER RIGHT div area. here's the code of the page around that area [by the way, here's the id of the DIV: <div id="att_named_box">]:

BEGINNING OF CODE, with a extra added for context

<div id="top_nav_line"><a href="contact-us.asp">Contact Us</a> | <a href="subscribe.asp">Subscribe</a> | <a href="search.asp">Search</a> </div> 

{***** CRITICAL code begins after the right bracket *****} 
<div id="att_named_box">
<a href="attorney-detail.asp?pageTitle=AttorneyName&amp;id=94"> 
<img src="images/trishhholland.suprlwyr.jpg" alt="Patricia L. Holland" width="82" height="101" border="0" align="left" /></a>
<p>Attorneys named to North Carolina Super Lawyers List</p><br />
<span class="att_name"> 
<a href="attorney-detail.asp?pageTitle=AttorneyName&amp;id=94">Patricia L. Holland</a></span><br />
<span class="att_spec">Employment &amp; Labor Law</span></div> 
{***** end of CRITICAL code *****} 

<div id="menu_box" style="top: 190px;"> 
<table border=0 cellpadding=0 cellspacing=0>
<tr>

it is within that DIV [<div id="att_named_box">] that i want to be able to display from a table: attyPhoto, attyCaption, attyName, attyPracticeArea. remember, ever 10, 15, x-seconds it needs to read another record, display inside that DIV area.
i notice js and PHP work wierd together; partial cooperation but having trouble putting PHP script into a js loop. HELP?

Recommended Answers

All 4 Replies

you could use ajax.

you can also use an iframe the refreshes every 10 seconds.( i don't like this method, but it works ).

you can use php to fill a js array with the values you need and display them that way.

Hi.

I would do this using JavaScript and AJAX.
Would be a simple matter of either having PHP pre-load the information into a JavaScript array or have AJAX load the new info from your server.

But, if you want this in pure PHP, consider this:

<?php
$arr = array('First', 'Second', 'Third');
($index = @$_GET['index']) or $index = 0;

if($index >= count($arr)) {
  $index = 0;
}

header("Refresh: 3; url=?index=". ($index + 1));
echo $arr[$index];
?>

It's a little simple, but you get where I'm going with this?

Why not do what php (Hypertext Preprocessor) was designed to do and make the php script to generate the javascript code which is then used by the browser. So you would make the php script to dump all the data into a large javascript code as arrays and every 10 seconds, the javascript can switch to the next array line (eg. from array[0] to array[1]) to display. That would be your best solution. So below is an example javascript after the php/Hypertext Preprocessor has generated the javascript:

var spanarray=new Array();
spanarray[0]='<span class="att_name"> 
<a href="attorney-detail.asp?pageTitle=AttorneyName&amp;id=94">Patricia L. Holland</a></span>';
spanarray[1]="second to display";
spanarray[2]="third to display";

var spanarrayb=new Array();
spanarrayb[0]='<span class="att_spec">Employment &amp; Labor Law</span>';
spanarrayb[1]="second to display";
spanarrayb[2]="third to display";

So a php script would have generated the above code and the below script appends the data every 10 seconds but will need a bit more working on.

var row=0;
while (spanarray[row]!=="")
{
document.write(spanarray[row]+"<br />
"+spanarrayb[row]);

row+=1;
setTimeout('',10000);
}

Sorry if the Javascript isn't 100% accurate but it's not often I use Javascript.

That would be your best solution.

That would depend on a lot of things. Most importantly; the amount of data you plan on dumping into the output every time the page is loaded.

Using AJAX would be far better than dumping a lot of data into a huge JavaScript array. Especially if you are including actual HTML in the JavaScript arrays.

It would be far more efficient to fetch only the data you need, rather than fetching everything every time the page loads.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.