i am fetching user details using date
if(date("d")==1) {
$time = "m";
}
if(date("l")=="Friday") {
$time = "w";
}
$time = "d";
$sql=mysql_query("select user from table_users where $reprt=".$time .");
while($row=mysql_fetch_Array($sql) {
$sql==mysql_query("select * from table_register where $user="$row[0]");
}
here when (date("d")==1)
i want to select statement using both d and m how is that possible.
Let's see if I got this right... you should should be doing this only in one query if I understand properly
select * from table_register where $user in (select user from table_users where $reprt=".$time)
would be a much better query then what you have set up... still not the best but at least it's only 1 query.
to the actual question, you should just change your code to the following
if(date("d")==1)
{
$time = "m";
}
if(date("l")=="Friday")
{
$time = "w";
}
if($time == "m") // this is when you want to also search for d right?
{
//we do what I suggested earlier with a slight change
mysql_query("select * from table_register where $user in (select user from table_users where $reprt=".$time." OR $reprt=d)");
}
else
{
//we do what I suggested earlier
mysql_query("select * from table_register where $user in (select user from table_users where $reprt=".$time.")");
}
Hope this helps.
let's say you have a String. name it S. you also have a string query = "select * from table_register where "
what you have to do is
query = "select * from table_register where "
if(date("d")==1){
s = "$report_frequency = \"m\" OR $report_frequency = \"d\" ";
}
elseif(date("l")=="Friday"){
s = "$report_frequency = \"m\" ";
}
else{
s = "$report_frequency = \"d\" ";
}
query = query.s;
$sql=mysql_query(query);
...
In other word, construct your query string dynamically using Strings
In your code you're using $time = "d";
outside the IFs, so you'll always have $time=d
, so replace the code with this:
if(date("d")==1){
$time = "m or $reprt='d'";
}
if(date("l")=="Friday"){
$time = "w";
}
$sql=mysql_query("select user from table_users where $reprt=".$time);
while($row=mysql_fetch_Array($sql){
$sql=mysql_query("select * from table_register where $user='$row[0]'");
}