hello.. i have to need report...and i have to need dynamic select query from differnt table in php... and i have no idea about this..using if condition..but problem is that at time only fire one query... i have totally more that 5 select query how can i do it..? help ...i m suffering so many problem in php.plz give me one demo..n how can i fetch also...
pritaeas 2,194 ¯\_(ツ)_/¯ Moderator Featured Poster
Show your table structures and some data, and explain exactly what you need.
seju 0 Newbie Poster
tabel:
maildetail:
mailid,userid,emailcatid,receiverid,status(approve,decline,sent),datetime
emailcategory:
emailcatid,adminid,emailtype,datetime
receiver:
receiverid,fname,lname,emailaddress.
nw we want to if condition to fetch dyanamic select query. i want to that recever(seju) to sent only welcomemail detail.
2nd thing, i want to startdate n enddate that mail detail display.
out reporting form include emailaddress,mailcategory(welcome,festival,payment)(uding dropdown list),start date,end date.
when i fill up emailadd n mailcategory then click on submit button then display record only that mail and recevieraddress.
when i select emailadd n mailcategory,start dte ,enddate then display only in between date record.to that receiver emailadd n that mail. how can i write it in condition. i try to it but fail..at time only one query fire. join query n multiple table no perfored any result. plz. help me the perfect code..as soon as...
seju 0 Newbie Poster
<html>
<head>
<title>Reports</title>
<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>
<link rel="stylesheet" type="text/css" href="jquery.ajaxcomplete.css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.ajaxcomplete.js"></script>
<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>
<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#emailaddress").autocomplete("receiver_eaddres.php", {
selectFirst: true
});
});
</script>
<script type="text/javascript">
function setTextField(ddl) {
document.getElementById('make_text').value = ddl.options[ddl.selectedIndex].text;
}
</script>
</head>
<body>
<h4>Report</h4>
<?php
session_start();
require_once("cn.php");
if (!$_REQUEST['submit']) {
html_form();
} else
{
select_cd();
}
function html_form()
{
?>
<p>Please enter the fields you would like to run a report on:</p>
<form name="form1" action="report1.php" method="POST">
<table cellspacing="20">
<th colspan="2"> Report</th>
<tr><td> Receipient Email ID:<td><input type="text" name="rname" id="emailaddress"></td></tr>
<tr><td> Select mail:<td><select name="dbType" id="dbType" onChange="setTextField(this)">
<option value="">None</option>
<?php
session_start();
require_once("cn.php");
$qry="select * from email_category";
$res=mysql_query($qry);
while ($row=mysql_fetch_array($res)) {
unset($id, $value);
$id = $row['emailcatid'];
$value = $row['emailtype'];
?>
<option value="<?php echo $row['emailcatid']; ?>"><?php echo $row['emailtype']; ?></option>
<?php
}
?>
</select></td></tr>
<tr><td> Start Date-Time:
<td><input id="demo2" type="text" name="date1" size="25"><a href="javascript:NewCal('demo2','ddmmyyyy',true,24)"><img src="cal.gif" width="20" height="20" border="2" alt="Pick a date"></a></tr>
<tr><td> End Date-Time:
<td><input id="demo3" type="text" name="date2" size="25"><a href="javascript:NewCal('demo3','ddmmyyyy',true,24)"><img src="cal.gif" width="20" height="20" border="2" alt="Pick a date"></a>
</tr>
<tr><td><input type="submit" name="submit" value="Report"></tr>
</table>
</form>
<?php
}
function select_cd()
{
?>
<!--/* Sets the SQL Query */-->
<?php
$userid=$_SESSION['useid'];
$dtime=$_POST['date1'];
$dt1=date('Y-m-d H:i:s', strtotime($dtime));
$dtime2=$_POST['date2'];
$dt2=date('Y-m-d H:i:s', strtotime($dtime2));
$sql = "SELECT * FROM mail_details a, receiver b,email_category c,user d";
$sql .= " WHERE (a.receiverid = b.receiverid AND a.emailcatid=c.emailcatid and b.emailaddress=
'{$_POST['rname']}')";
$sql2 = "SELECT * FROM mail_details a,email_category b,receiver c";
$sql2 .= " WHERE (a.emailcatid=b.emailcatid and a.receiverid=c.receiverid and b.emailcatid=
'{$_POST['dbType']}')";
$sql3 = "SELECT a.mailid,c.receiverid,c.emailaddress,b.emailcatid,b.emailtype FROM mail_details a,email_category b,receiver c";
$sql3 .= " WHERE (a.receiverid=c.receiverid and a.emailcatid=b.emailcatid and c.emailaddress = '{$_POST['rname']}' and b.emailcatid='{$_POST['dbType']}')";
/*$sql4 = "SELECT * FROM mail_details a,email_category b,receiver c";
$sql4 .= " WHERE (a.emailcatid=b.emailcatid and a.receiverid=c.receiverid and c.emailaddress = '{$_POST['rname']}' and b.emailcatid='{$_POST['dbType']}' and a.date_time between '{$dt1}' and '{$dt2}')";
$sql5 = "SELECT * FROM mail_details a,email_category b,receiver c";
$sql5 .= " WHERE (a.emailcatid=b.emailcatid and a.receiverid=c.receiverid and a.date_time between '{$dt1}' and '{$dt2}') order by a.date_time";
$sql6 = "SELECT * FROM mail_details a,email_category b,receiver c";
$sql6 .= " WHERE (a.date_time='{$date}')";
$sql7 = "SELECT * FROM mail_details a,email_category b,receiver c";
$sql7 .= " WHERE (c.receiverid=a.receiverid and b.emailcatid=a.emailcatid and c.emailaddress='{$_POST['rname']}' and a.date_time between '{$dt1}' and '{$dt2}') order by a.date_time";*/
/* Passes a Query to the Active Database , sql*/
$result = mysql_query($sql);
if (!$result)
{
echo("<p>1Error performing query: " . mysql_error() . "</p>");
exit();
}
/* Passes a Query to the Active Database
$result2 = mysql_query($sql2);
if (!$result2)
{
echo("<p>2Error performing query: " . mysql_error() . "</p>");
exit();
}*/
//Passes a Query to the Active Database
$result3 = mysql_query($sql3);
if (!$result3)
{
echo("<p>3Error performing query: " . mysql_error() . "</p>");
exit();
}
/* Passes a Query to the Active Database
$result4 = mysql_query($sql4);
if (!$result4)
{
echo("<p>4Error performing query: " . mysql_error() . "</p>");
exit();
}
//Passes a Query to the Active Database
$result5 = mysql_query($sql5);
if (!$result5)
{
echo("<p>5Error performing query: " . mysql_error() . "</p>");
exit();
}
$result6 = mysql_query($sql6);
if (!$result6)
{
echo("<p>6Error performing query: " . mysql_error() . "</p>");
exit();
}
$result7 = mysql_query($sql7);
if (!$result7)
{
echo("<p>7Error performing query: " . mysql_error() . "</p>");
exit();
}
/* Starts the table and creates headings */
echo "<table border='1'>
<tr>
<th>receiver emailaddress</th>
<th>mail</th>
<th>date</th>
<!--<th> Labor Training</th>
<th>Ethics Training</th>
<th>Work Authorization</th>
<th>Predicted Outcome</th>-->
</tr>";
/* Retrieves the rows from the query result set
and puts them into a HTML table row */
if($result)
{
while($row = mysql_fetch_array($result))
{
echo("<tr>\n<td>" . $row["emailaddress"] . "</td>");
echo("<td>" . $row["emailtype"] . "</td>");
echo("<td>" . $row["5"] . "</td>");
}
}
elseif($result2)
{
while($row = mysql_fetch_array($result2))
{
echo("<tr><td>" . $row["emailaddress"] . "</td>");
echo("<td>" . $row["5"] . "</td>");
//echo("<td>" . $row["emailtype"] . "</td>");
}
}
elseif($result3)
{
while($row = mysql_fetch_array($result3))
{
echo("<tr><td>" . $row["emailaddress"] . "</td>");
echo("<td>" . $row["emailtype"] . "</td>");
echo("<td>" . $row["5"] . "</td>");
}
}
/*if($result4)
{
while($row = mysql_fetch_array($result4))
{
echo("<tr>\n<td>" . $row["emailaddress"] . "</td>");
echo("<td>" . $row["emailtype"] . "</td>");
echo("<td>" . $row['5'] . "</td>");
}
}
if($result5)
{
while($row = mysql_fetch_array($result5))
{
echo("<tr>\n<td>" . $row["emailaddress"] . "</td>");
echo("<td>" . $row["emailtype"] . "</td>");
echo("<td>" . $row["5"] . "</td>");
}
}
if($result6)
{
while($row = mysql_fetch_array($result6))
{
echo("<tr>\n<td>" . $row["emailaddress"] . "</td>");
echo("<td>" . $row["emailtype"] . "</td>");
echo("<td>" . $row["5"] . "</td>");
}
}
if($result7)
{
while($row = mysql_fetch_array($result7))
{
echo("<tr>\n<td>" . $row["emailaddress"] . "</td>");
echo("<td>" . $row["emailtype"] . "</td>");
echo("<td>" . $row["5"] . "</td>");
}
}
*/
}
?>
</body>
</html>
if can do implement this code also.. i hope u get exctly idea about our problem.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.