www.webdeveloper.com
Results 1 to 3 of 3

Thread: switching table content?

  1. #1
    Join Date
    Jul 2007
    Posts
    76

    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);
    ?>

  2. #2
    Join Date
    Apr 2007
    Posts
    1,664
    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.

    HTML Code:
    www.url.com/page.php?showdata=1&showdata2=2&showdata3=3

    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.
    PHP Code:
    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;
        }

    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.
    Last edited by SyCo; 04-15-2008 at 05:10 PM.

  3. #3
    Join Date
    Apr 2007
    Posts
    1,664
    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
    PHP Code:
    <?
    echo '<table>';
    foreach(
    $_GET as $v){
        switch (
    $v) {
        case 
    1:
            
    $data fgetcsv ($fp1000",");
            break;
        case 
    2:
            
    $data fgetcsv ($fp2000",");
            break;
        case 
    3:
            
    $data fgetcsv ($fp3000",");
            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>';

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles