Results 1 to 7 of 7

Thread: Capture Complex Dynamic Display Data

  1. #1
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Capture Complex Dynamic Display Data

    Hi..guys.I have a form below which consists of movie name as label and its screening time as radio button.What I intend to do when user selected a particular radio button,the corresponding movie name will be captured and dispalyed in next page.

    PHP Code:
    <?
    if (isset($_SESSION['gmemberid'])) {

        
    $tbl_name "movie";
        
    $result mysql_query(sprintf('SELECT name,classification,screeningTime FROM %s
                 LIMIT 7'
    $tbl_name)) or die('Cannot execute query.');


        
    //$numrow = mysql_num_rows($result);


        
    while ($rows mysql_fetch_assoc($result)) {
            echo 
    '<table width="100%" border="0"><tr><td height="68">
                      <table width="100%" height="47" border="0">
                       ---------------------------------------------------------------------------------------------------------<br>'
    ;

            echo 
    '<strong>' $rows['name'] . ' (' $rows['classification'] . ')
                     <br></strong>'
    ;
            foreach (
    explode(','$rows['screeningTime']) as $time) { ?>
                <label>
                <input type="radio"  name="time[<?php echo $rows['name']; ?>]"
                  title ="screening time" value="<?php echo $time?>"
                  onClick ="GoToNextPage(this.value)">
                  
                <?php echo $time?>&nbsp;&nbsp;&nbsp;
                </label>
                <?php ?>
    <?
        
    }

    }
    ?>

    The screening time can be captured by onclick attribute in javascript
    Code:
     function GoToNextPage(value){
            if(value != ""){
           document.location = 'reservation3.php?selected_time=' +value;
      }
    }
    And displayed it in next page
    Code:
    <tr><td><label>Showtime&nbsp;&nbsp;&nbsp;<?= $_GET['selected_time']; ?></label></td></tr>
    However,how can I perform same action to movie name?Thanks for generious help

  2. #2
    Join Date
    May 2006
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Can i ask why your sending the data with javascript and not just posting the form?

    example:

    PHP Code:
    <?php

    if (isset($_SESSION['gmemberid']))
    // if logged in


    if (isset(
    $_GET['form_done']))
    // If form has been submitted
    {

    $time $_GET['time'];
    $name $_GET['name'];

    // more stuff here such as database query?

    }

    else
    // If form hasn't been submitted show the form
    ?>

    <form method="get" action="reservation3.php">

    <input type="radio" name="time" title="Screening Time" value="<?php echo $time ?>" />
    <input type="radio" name="name" title="Movie Name" value="<?php echo $name ?>" />
    <input type="submit" value="Submit" name="form_done" />

    </form>

    <?php
    }
    }
    ?>
    I don't know exactly what you want to do, but hopefully it shows you how to send data using $_GET through a form and not javascript.

  3. #3
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok.I have deleted all javascript.However how can use $_GET to capture name and screening time which are dynamic?

    PHP Code:
    <?
    if (isset($_SESSION['gmemberid'])) {

        
    $tbl_name "movie";
        
    $result mysql_query(sprintf('SELECT name,classification,screeningTime FROM %s
                 LIMIT 7'
    $tbl_name)) or die('Cannot execute query.');


        
    //$numrow = mysql_num_rows($result);


        
    while ($rows mysql_fetch_assoc($result)) {
            echo 
    '<table width="100%" border="0"><tr><td height="68">
                      <table width="100%" height="47" border="0">
                       ---------------------------------------------------------------------------------------------------------<br>'
    ;

            echo 
    '<strong>' $rows['name'] . ' (' $rows['classification'] . ')
                     <br></strong>'
    ;
            foreach (
    explode(','$rows['screeningTime']) as $time) { ?>
                <label>
                <input type="radio"  name="time[<?php echo $rows['name']; ?>]"
                  title ="screening time" value="<?php echo $time?>">
                  
                <?php echo $time?>&nbsp;&nbsp;&nbsp;
                </label>
                <?php ?>
    <?
        
    }

    }
    ?>
    When come to next page,how can I display 'name' and 'screening time'?
    I am not idea how to code it?Something went wrong in my $_GET
    Thanks for your generious help...

    Code:
    <td><label>Showtime&nbsp;&nbsp;&nbsp;<?= $_GET[$time]; ?>
    </label></td>
    <td><label>Movie&nbsp;&nbsp;&nbsp;<?= $_GET[$rows['name']];?>
    </label></td>

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Code:
    <td><label>Showtime&nbsp;&nbsp;&nbsp;<?= echo $_GET[$time]; ?>
    </label></td>
    <td><label>Movie&nbsp;&nbsp;&nbsp;<?= echo $_GET[$rows['name']];?>
    </label></td>
    also there is no benefit to using the label tag as you have it. it is just extra code. if you wanted to highlight just the ShowTime / Movie you could encapsulate the label around that, but wrapping the whole string is not serving any purpose, and is just adding 1-2kb bandwidth transfer per output occurance

  5. #5
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks,

    Code:
    <td>Showtime&nbsp;&nbsp;&nbsp;<?= echo $_GET[$rows['name']];?></td>
    This line is having syntax error of unexpected T_ECHO

    When the above line is deleted,the following line,
    Code:
    <td><label>Movie&nbsp;&nbsp;&nbsp;<?= echo $_GET[$time];?></label></td>
    also having syntax error of unexpected T_ECHO

    These echoes are actually executed in the next page maybe it can't resolved symbol of $rows['name'],$time which are used in previous page.How can I modified for them?
    Last edited by devil_vin; 09-26-2007 at 02:05 PM.

  6. #6
    Join Date
    May 2006
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The echo's are unexpected because <?= means <?php echo.... so your using echo inside echo.

    In PHP you should use <?php instead of short open tags (<?) because some servers are not configured to allow them and they can also conflict with XML's open tag.

  7. #7
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks.now no error occured however values are not displayed yet.
    I can see that values being joined up in URL,I am using GET method,but why didn't display in the next page?
    Last edited by devil_vin; 09-26-2007 at 02:40 PM.

Bookmarks

Posting Permissions

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