...

View Full Version : Facing a problem in passing values from dropdown list to query...!!!



swap_ssj
08-27-2009, 08:07 AM
Hello guyes…
I’m new in this PHP world.
I have tried in either ways, but it's not working for me.
I have to play with 3 values selected by user from the dropdown list, i.e. $_POST['plotid_1'],$_POST['year1'],$_POST['year2']. I'm not able to pass these values to query.
Here i'm posting my code :

<?php
session_start();
ob_start();
?>
<form name="form" id="form" method="post" action="index.php?page=report3" onsubmit="return
validateForms('form');">

<table width="60%" align="center" cellpadding="5" cellspacing="1" bgcolor="#CCCC99">
<tr bgcolor="#FFFFFF">
<td class="heading" colspan="2" align="center" bgcolor="#EEEEEE">PlotWise Yield Analysis</td>
</tr>

<tr bgcolor="#FFFFFF">
<td class="graytext" align="right">Season 1 : </td>
<td align="left"><select id="year1" name="year1">
<?php
$q1=mysql_query("select distinct season from seasonmaster");
while($rs1=mysql_fetch_array($q1))
{ if($_REQUEST["yid"]==$rs1[season]){
?>
<option value=" <?php echo $rs1[season];?> " selected="selected"><?php echo $rs1[season];?></option>
<?php } else{
?>
<option value="<?php echo $rs1[season];?>"><?php echo $rs1[season];?></option>
<?php }
} ?>
</select>
<span id="uname" class="rederr"></span>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td class="graytext" align="right">Season 2 : </td>
<td align="left"><select id="year2" name="year2">
<?php
$q1=mysql_query("select distinct season from seasonmaster");
while($rs1=mysql_fetch_array($q1))
{ if($_REQUEST["yid2"]==$rs1[season]){
?>
<option value="<?php echo $rs1[season];?>" selected="selected"><?php echo $rs1[season];?></option>
<?php } else{ ?>
<option value="<?php echo $rs1[season];?>"><?php echo $rs1[season];?></option>
<?php }
}?>
</select><br />
<span id="pass" class="rederr"></span>
</td>
</tr>

<tr bgcolor="#FFFFFF">
<td class="graytext" align="right">Plot No. :</td>
<td align="left"><select name="plotid_1" id="plotid_1">
<option value="0">--Select Plot--</option>

<?php
$Sql=mysql_query("SELECT * FROM plots ");
while($row = mysql_fetch_array($Sql))
{
if($_REQUEST["pid"]==$row[plotno])
echo "<option value=$row[plotno] selected>$row[plotno]</option>"; else
echo "<option value=$row[plotno]>$row[plotno]</option>"; }

if($_POST['plotid_1'])
{
$s1=mysql_query("select 'sid' from 'seasonmaster' where 'season'='".$_POST[year1]."'");
$rss1=mysql_fetch_array($s1);
$sql1=mysql_query("select sum(total)from 'actual_yield' where 'tid' in (SELECT 'tid' FROM 'treemaster' WHERE 'plotid'=(select 'plotid' from 'plots' where 'plotno'='".$_POST[plotid_1]."'))and 'sid'='".$rss1[sid]."'");
$rsAy=mysql_fetch_array($sql1);
session_register("actY1");
$_SESSION["actY1"]=$rsAy['total'];

$s2=mysql_query("select 'sid' from 'seasonmaster' where 'season'='".$_POST[year2]."'");
$rss2=mysql_fetch_array($s2);
$sql2=mysql_query("select sum(total)from 'actual_yield' where 'tid' in (SELECT 'tid' FROM 'treemaster' WHERE 'plotid'=(select 'plotid' from 'plots' where 'plotno'='".$_POST[plotid_1]."'))and 'sid'='".$rss2[sid]."'");
$rsAy1=mysql_fetch_array($sql2);
session_register("actY2");
$_SESSION["actY2"]=$rsAy1['total'];
}

?>
</select><br>
<span id="plotid" class="rederr"></span>
<td>
</tr>

<tr bgcolor="#FFFFFF">
<td class="heading" colspan="2" align="center"><input type="submit" class="button" name="save" id="save" value=" Show "></td>
</tr>
</table>
</form>

-----------------------------------------------------------------------------------------------------------------------------------------------------Here is my code. I have to play with 3 values selected by user from the dropdown list.
I'm doing it in this way, but it's not working.
How can i do this....???

abduraooft
08-27-2009, 08:14 AM
I'm doing it in this way, but it's not working.
How can i do this....??? Please edit your post and add
][/COLOR] tags around your code, to make it easier for reading.

Phil Jackson
08-27-2009, 08:37 AM
<?php
session_start();
ob_start();
?>
<form name="form" id="form" method="post" action="index.php?page=report3" onsubmit="return
validateForms('form');">

<table width="60%" align="center" cellpadding="5" cellspacing="1" bgcolor="#CCCC99">
<tr bgcolor="#FFFFFF">
<td class="heading" colspan="2" align="center" bgcolor="#EEEEEE">PlotWise Yield Analysis</td>
</tr>

<tr bgcolor="#FFFFFF">
<td class="graytext" align="right">Season 1 : </td>
<td align="left"><select id="year1" name="year1">

<?php
$q1 = mysql_query("SELECT distinct season FROM `seasonmaster`") or die(mysql_error());
while($rs1 = mysql_fetch_array($q1))
{
if($_REQUEST["yid"]==$rs1[season])
{
echo "<option value=\"".$rs1[season]."\" selected=\"selected\">".$rs1[season]."</option>\n";
}
else
{
echo "<option value=\"".$rs1[season]."\">".$rs1[season]."</option>\n";
}
}
?>

</select>
<span id="uname" class="rederr"></span>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td class="graytext" align="right">Season 2 : </td>
<td align="left">
<select id="year2" name="year2">

<?php
$q1 = mysql_query("SELECT distinct season FROM `seasonmaster`");
while($rs1 = mysql_fetch_array($q1))
{
if($_REQUEST["yid2"]==$rs1[season])
{
echo "<option value=\"".$rs1[season]."\" selected=\"selected\">".$rs1[season]."</option>\n";
}
else
{
echo "<option value=\"".$rs1[season];."\">".$rs1[season]."</option>\n";
}
}
?>
</select><br />
<span id="pass" class="rederr"></span>
</td>
</tr>

<tr bgcolor="#FFFFFF">
<td class="graytext" align="right">Plot No. :</td>
<td align="left"><select name="plotid_1" id="plotid_1">
<option value="0">--Select Plot--</option>

<?php
$Sql = mysql_query("SELECT * FROM `plots`") or die(mysql_error());
while($row = mysql_fetch_array($Sql))
{
if($_REQUEST["pid"]==$row[plotno])
{
echo "<option value=\"".$row[plotno]."\">".$row[plotno]."</option>\n";
}
else
{
echo "<option value=\"".$row[plotno]."\">".$row[plotno]."</option>";
}
}
if(isset($_POST['year1']))
{
$postYear = $_POST['year1'];
}
else
{
die("you havent got a value set for year1";
}
if(isset($_POST['plotid_1']))
{
$plotID1 = $_POST['plotid_1'];
}
else
{
die("you have not got a val set for plotid_1");
}
$rss1_ = $rss1[sid];
if(isset($_POST['year2']))
{
$postYear2 = $_POST['year2'];
}
else
{
die("you have not got a val set for year2");
}
$rss2_ = $rss2[sid];

if($_POST['plotid_1'])
{
$s1 = mysql_query("SELECT sid FROM `seasonmaster` WHERE season = '$postYear'") or die(mysql_error());
$rss1 = mysql_fetch_array($s1);

$sql1 = mysql_query("SELECT sum(total) FROM `actual_yield` WHERE tid in (SELECT tid FROM `treemaster` WHERE plotid = (SELECT plotid FROM plots WHERE plotno = '$plotID1')) AND sid = '$rss1_'") or die(mysql_error());
$rsAy = mysql_fetch_array($sql1);

session_register("actY1");
$_SESSION["actY1"] = $rsAy['total'];

$s2 = mysql_query("SELECT sid FROM `seasonmaster` WHERE season = '$postYear2'");
$rss2 = mysql_fetch_array($s2);

$sql2 = mysql_query("SELECT sum(total) FROM `actual_yield` WHERE tid in (SELECT tid FROM `treemaster` WHERE plotid = (SELECT plotid FROM `plots` WHERE plotno = '$plotID1]')) AND sid = '$rss2_'") or die(mysql_error());
$rsAy1=mysql_fetch_array($sql2);

session_register("actY2");
$_SESSION["actY2"]=$rsAy1['total'];
}

?>
</select><br>
<span id="plotid" class="rederr"></span>
<td>
</tr>

<tr bgcolor="#FFFFFF">
<td class="heading" colspan="2" align="center"><input type="submit" class="button" name="save" id="save" value=" Show "></td>
</tr>
</table>
</form>

Phil Jackson
08-27-2009, 08:49 AM
the post above has just been updated.

swap_ssj
08-28-2009, 06:23 AM
Thanks for ur precious reply...

I have tried the solution u suggested, but it is not showing my "Show" button, so i'm unable to understand wheather this code is working properly or not. What should do in above code so that i can display "Show" button...???

Phil Jackson
08-28-2009, 07:10 AM
<?php
session_start();
ob_start();
?>
<form name="form" id="form" method="post" action="index.php?page=report3" onsubmit="return
validateForms('form');">

<table width="60%" align="center" cellpadding="5" cellspacing="1" bgcolor="#CCCC99">
<tr bgcolor="#FFFFFF">
<td class="heading" colspan="2" align="center" bgcolor="#EEEEEE">PlotWise Yield Analysis</td>
</tr>

<tr bgcolor="#FFFFFF">
<td class="graytext" align="right">Season 1 : </td>
<td align="left"><select id="year1" name="year1">

<?php
$con = mysql_connect("localhost", "user", "pass");
$db = mysql_select_db("dbname", $con);

$q1 = mysql_query("SELECT distinct season FROM `seasonmaster`") or die(mysql_error());
while($rs1 = mysql_fetch_array($q1))
{
if($_REQUEST["yid"]==$rs1[season])
{
echo "<option value=\"".$rs1[season]."\" selected=\"selected\">".$rs1[season]."</option>\n";
}
else
{
echo "<option value=\"".$rs1[season]."\">".$rs1[season]."</option>\n";
}
}
?>

</select>
<span id="uname" class="rederr"></span>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td class="graytext" align="right">Season 2 : </td>
<td align="left">
<select id="year2" name="year2">

<?php
$q1 = mysql_query("SELECT distinct season FROM `seasonmaster`");
while($rs1 = mysql_fetch_array($q1))
{
if($_REQUEST["yid2"]==$rs1[season])
{
echo "<option value=\"".$rs1[season]."\" selected=\"selected\">".$rs1[season]."</option>\n";
}
else
{
echo "<option value=\"".$rs1[season]."\">".$rs1[season]."</option>\n";
}
}
?>
</select><br />
<span id="pass" class="rederr"></span>
</td>
</tr>

<tr bgcolor="#FFFFFF">
<td class="graytext" align="right">Plot No. :</td>
<td align="left"><select name="plotid_1" id="plotid_1">
<option value="0">--Select Plot--</option>

<?php
$Sql = mysql_query("SELECT * FROM `plots`") or die(mysql_error());
while($row = mysql_fetch_array($Sql))
{
if($_REQUEST["pid"]==$row[plotno])
{
echo "<option value=\"".$row[plotno]."\">".$row[plotno]."</option>\n";
}
else
{
echo "<option value=\"".$row[plotno]."\">".$row[plotno]."</option>";
}
}
if(isset($_POST['year1']))
{
$postYear = $_POST['year1'];
}
else
{
die("you havent got a value set for year1");
}
if(isset($_POST['plotid_1']))
{
$plotID1 = $_POST['plotid_1'];
}
else
{
die("you have not got a val set for plotid_1");
}
$rss1_ = $rss1[sid];
if(isset($_POST['year2']))
{
$postYear2 = $_POST['year2'];
}
else
{
die("you have not got a val set for year2");
}
$rss2_ = $rss2[sid];

if($_POST['plotid_1'])
{
$s1 = mysql_query("SELECT sid FROM `seasonmaster` WHERE season = '$postYear'") or die(mysql_error());
$rss1 = mysql_fetch_array($s1);

$sql1 = mysql_query("SELECT sum(total) FROM `actual_yield` WHERE tid in (SELECT tid FROM `treemaster` WHERE plotid = (SELECT plotid FROM plots WHERE plotno = '$plotID1')) AND sid = '$rss1_'") or die(mysql_error());
$rsAy = mysql_fetch_array($sql1);

session_register("actY1");
$_SESSION["actY1"] = $rsAy['total'];

$s2 = mysql_query("SELECT sid FROM `seasonmaster` WHERE season = '$postYear2'");
$rss2 = mysql_fetch_array($s2);

$sql2 = mysql_query("SELECT sum(total) FROM `actual_yield` WHERE tid in (SELECT tid FROM `treemaster` WHERE plotid = (SELECT plotid FROM `plots` WHERE plotno = '$plotID1]')) AND sid = '$rss2_'") or die(mysql_error());
$rsAy1=mysql_fetch_array($sql2);

session_register("actY2");
$_SESSION["actY2"]=$rsAy1['total'];
}

?>
</select><br>
<span id="plotid" class="rederr"></span>
<td>
</tr>

<tr bgcolor="#FFFFFF">
<td class="heading" colspan="2" align="center"><input type="submit" class="button" name="save" id="save" value=" Show "></td>
</tr>
</table>
</form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum