/    Sign up×
Community /Pin to ProfileBookmark

Navigate Array Records

I have some php that creates an array, within which there are a number of short pieces of text (reviews)
Currently I have it so the whole array/list of reviews is output to the screen.

However my preference would be that only one record from the array is shown at once, and that the user clicks a ‘next’ link to see each record, without the page having to be refreshed.

Is there some javascript around that will do this?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsJul 03.2008 — [CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
</head>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
var Ary=['review 1','review 2','review 3'];

function Review(id,ary){
var obj=document.getElementById(id);
if (!obj.cnt) obj.cnt=0;
obj.innerHTML=ary[obj.cnt];
obj.cnt=++obj.cnt%ary.length;
}


/*]]>*/
</script>
<body>
<div id="tst" ></div>
<input type="button" name="" value="Next" onclick="Review('tst',Ary);" />
</body>

</html>[/CODE]
Copy linkTweet thisAlerts:
@KorJul 03.2008 — show us the HTML generated (some of them, if many) codeof those pieces of code
Copy linkTweet thisAlerts:
@millsy007authorJul 03.2008 — This works great.

However I have created my array in php:

<?php

// include class file

include 'reader.php';

// initialize reader object
$excel = new Spreadsheet_Excel_Reader();

// read spreadsheet data
$excel->read('Book1.xls');

// iterate over spreadsheet cells and print as HTML table
$x=1;
while($x<=$excel->sheets[0]['numRows']) {
echo "t<tr>n";
$y=1;
while($y<=$excel->sheets[0]['numCols']) {
$cell = isset($excel->sheets[0]['cells'][$x][$y]) ? $excel->sheets[0]['cells'][$x][$y] : '';
echo "tt<td>$cell</td>n";
$y++;
}
echo "t</tr>n";
$x++;
}
?>

Is there a way that the javascsript can use this information?
Copy linkTweet thisAlerts:
@FangJul 03.2008 — &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;title&gt;toggle lists&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;

&lt;script type="text/javascript"&gt;
window.onload=function() {
var content=document.getElementById('content');
var dt=content.getElementsByTagName('dt');
var button=document.createElement("button");
button.setAttribute('type', 'button');
button.setAttribute('id', 'next');
button.setAttribute('value', 0);
button.onclick=function(){this.value++;toggle(this);};
button.appendChild(document.createTextNode("next"));
content.parentNode.insertBefore(button, content.nextSibling);

toggle();
}

function toggle() {
var dt=document.getElementsByTagName('dt');
var dd=document.getElementsByTagName('dd');
for(var i=0; i&lt;dt.length; i++) {
dt[i].className=dd[i].className='collapsed';
}
var buttonObj=document.getElementById('next');
var show=buttonObj.value;
if(show&gt;=dt.length) {show=buttonObj.value=0;}
dt[show].className=dd[show].className='expanded';
}
&lt;/script&gt;

&lt;style type="text/css"&gt;
dt {font-weight:bold;}
.expanded {display:block;}
.collapsed {display:none;}
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;dl id="content"&gt;
&lt;dt&gt;review1&lt;/dt&gt;
&lt;dd&gt;text of review1&lt;/dd&gt;
&lt;dt&gt;review2&lt;/dt&gt;
&lt;dd&gt;text of review2&lt;/dd&gt;
&lt;dt&gt;review3&lt;/dt&gt;
&lt;dd&gt;text of review3&lt;/dd&gt;
&lt;/dl&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @millsy007 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...