/    Sign up×
Community /Pin to ProfileBookmark

switching table content?

Hi Guys,

i am currently putting together a php site, but i have got a little stuck and wondered whether someone could help. I have 3 HTML links when clicked on i would like to change the php content within my HTML it is held. My code is underneath, the three links i refer to would be “now showing”, “coming soon” and “arts council” they are without the link tagging below. The 4 small tables below complete the “now showing” section. When clicked on the coming soon link i would like to change the content of these tables.

Though the other sections might have to hold more than just the 4 tables. I was thinking is it possible to use the php include tag somehow? Have each section in a different page and included on page when link is clicked.

Thanks

<?php
//open data file
$fp = fopen (“films.csv”, “r”);
//this uses the fgetcsv function to store the info in the array $data
$dataA = fgetcsv ($fp, 1000, “,”);
$dataB = fgetcsv ($fp, 2000, “,”);
$dataC = fgetcsv ($fp, 3000, “,”);
$dataD = fgetcsv ($fp, 4000, “,”);
?>
<!– use $data[n] for fields –>

<table width=”300″ border=”0″ cellpadding=”3″ cellspacing=”0″>
<tr>
<td><h1>Now Showing</h1></td>
<td><h1>Coming Soon</h1></td>
<td><h1>Arts Council</h1></td>
</tr>
</table>
<table width=”460″ border=”0″ cellpadding=”3″>
<tr>
<td style=”vertical-align: top” width=”108″ rowspan=”2″><img src=”blood.jpg”></td>
<td><span id=”h1″><?php echo $dataA[1] ?></span>&nbsp;&nbsp;<span id=”h4″><?php echo $dataA[2] ?></span></td>
</tr>
<tr>
<td style=”vertical-align: top”><span id=”b1″>Showing from <b><?php echo $dataA[3] ?></b> &nbsp;&nbsp;Nightly at <b><?php echo $dataA[5] ?></b><br>
<b>Directed by:</b> <?php echo $dataA[6] ?><br>
<b>Starring:</b> <?php echo $dataA[7] ?> &nbsp;&nbsp;<b>Time:</b> <?php echo $dataA[9] ?><br>
<b>Notes:</b> <?php echo $dataA[8] ?><br>
<b>Synopsis:</b> <?php echo $dataA[10] ?></span></td>
</tr>
</table>
<table width=”460″ border=”0″ cellpadding=”3″>
<tr>
<td style=”vertical-align: top” width=”108″ rowspan=”2″><img src=”awake.jpg”></td>
<td><span id=”h1″><?php echo $dataB[1] ?></span>&nbsp;&nbsp;<span id=”h4″><?php echo $dataB[2] ?></span></td>
</tr>
<tr>
<td style=”vertical-align: top”><span id=”b1″>Showing from <b><?php echo $dataB[3] ?></b> &nbsp;&nbsp;Nightly at <b><?php echo $dataB[4] ?></b><br>
<b>Directed by:</b> <?php echo $dataB[5] ?><br>
<b>Starring:</b> <?php echo $dataB[6] ?> &nbsp;&nbsp;<b>Time:</b> <?php echo $dataB[8] ?><br>
<b>Notes:</b> <?php echo $dataB[7] ?><br>
<b>Synopsis:</b> <?php echo $dataB[9] ?><br></span></td>
</tr>
</table>
<table width=”460″ border=”0″ cellpadding=”3″>
<tr>
<td style=”vertical-align: top” width=”108″ rowspan=”2″><img src=”spiderwick.jpg”></td>
<td><span id=”h1″><?php echo $dataC[1] ?></span>&nbsp;&nbsp;<span id=”h4″><?php echo $dataC[2] ?></span></td>
</tr>
<tr>
<td style=”vertical-align: top”><span id=”b1″>Matinees until <b><?php echo $dataC[3] ?></b> &nbsp;&nbsp;Sat & Sun at <b><?php echo $dataC[4] ?></b><br>
<b>Directed by:</b> <?php echo $dataC[5] ?><br>
<b>Starring:</b> <?php echo $dataC[6] ?> &nbsp;&nbsp;<b>Time:</b> <?php echo $dataC[8] ?><br>
<b>Notes:</b> <?php echo $dataC[7] ?><br>
<b>Synopsis:</b> <?php echo $dataC[9] ?><br></span></td>
</tr>
</table>
<table width=”460″ border=”0″ cellpadding=”3″>
<tr>
<td style=”vertical-align: top” width=”108″ rowspan=”2″><img src=”horton.jpg”></td>
<td><span id=”h1″><?php echo $dataD[1] ?></span>&nbsp;&nbsp;<span id=”h4″><?php echo $dataD[2] ?></span></td>
</tr>
<tr>
<td style=”vertical-align: top”><span id=”b1″>Matinees until <b><?php echo $dataD[3] ?></b> &nbsp;&nbsp;Sat & Sun at <b><?php echo $dataD[4] ?></b><br>
<b>Directed by:</b> <?php echo $dataD[5] ?><br>
<b>Starring:</b> <?php echo $dataD[6] ?><br>
<b>Notes:</b> <?php echo $dataD[7] ?> &nbsp;&nbsp;<b>Time:</b> <?php echo $dataD[8] ?><br>
<b>Synopsis:</b> <?php echo $dataD[9] ?><br></span></td>
</tr>
</table>
<?php
//close the filehandle $fp
fclose ($fp);
?>

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@SyCoApr 15.2008 — yea you could use a switch to call the correct section of data to include. You can pass the values of which data sets to include in a lot of different ways but here one using the URL.

First you would want to see if there are multiple sections to display and you have the $_GET array with all the values.

[code=html]www.url.com/page.php?showdata=1&showdata2=2&showdata3=3
[/code]



When you have your values you can use a switch but you need to loop through the array containing your showdata values, so put the switch inside a foreach. You can order the array to order the output either now or when you build it.
[code=php]
foreach($_GET as $v){
switch ($v) {
case 1:
echo "data set one";
break;
case 2:
echo "data set two";
break;
case 3:
echo "data set three";
break;
}
}
[/code]

edit: remember that page.php?showdata=1&showdata=2 will only write one value to the GET array and overwrite the first one with the second.

You could generate a neater URL like this

www.url.com/page.php?showdata=1_2_3

and explode the GET['showdata'] value on the underscore to generate the array to loop through.


GET strings are easy to tamper with so, if that matters, secure it wth an MD5 hash and a secret key.
Copy linkTweet thisAlerts:
@SyCoApr 15.2008 — Actually your data sets are identical so you only need to choose which one to display in the switch then display it before ending the loop
[code=php]<?
echo '<table>';
foreach($_GET as $v){
switch ($v) {
case 1:
$data = fgetcsv ($fp, 1000, ",");
break;
case 2:
$data = fgetcsv ($fp, 2000, ",");
break;
case 3:
$data = fgetcsv ($fp, 3000, ",");
break;
}
?>
<tr>
<td style="vertical-align: top"><span id="b1">Showing from <b><?php echo $data[3] ?></b> &nbsp;&nbsp;Nightly at <b><?php echo $data[5] ?></b><br>
<b>Directed by:</b> <?php echo $data[6] ?><br>
<b>Starring:</b> <?php echo $data[7] ?> &nbsp;&nbsp;<b>Time:</b> <?php echo $data[9] ?><br>
<b>Notes:</b> <?php echo $data[8] ?><br>
<b>Synopsis:</b> <?php echo $data[10] ?></span></td>
</tr>
<?

}//close loop
echo '</table>';[/code]
×

Success!

Help @rbrown 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.16,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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