Log in

View Full Version : Capture Complex Dynamic Display Data



devil_vin
09-25-2007, 04:38 PM
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.



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


function GoToNextPage(value){
if(value != ""){
document.location = 'reservation3.php?selected_time=' +value;
}
}


And displayed it in next page


<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

jonnyynnoj
09-25-2007, 05:51 PM
Can i ask why your sending the data with javascript and not just posting the form?

example:


<?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.

devil_vin
09-26-2007, 01:28 PM
Ok.I have deleted all javascript.However how can use $_GET to capture name and screening time which are dynamic?



<?
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...



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

boogyman
09-26-2007, 01:35 PM
<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

devil_vin
09-26-2007, 01:56 PM
Thanks,



<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,


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

jonnyynnoj
09-26-2007, 02:25 PM
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.

devil_vin
09-26-2007, 02:34 PM
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?