tamtam Posted February 27, 2008 Share Posted February 27, 2008 Hi all, I m having a bit of trouble displaying my report. It appears as if it only uses 2 sql statement (i.e. the one stated in blue), while the rest are ignored. I hope someone can point me to my mistake. Below is the if else statement i use:- if ( $request->getRequestMethod() == REQUEST_POST ) { if($request->getParam("table_m")==1) { $table_select="table_A"; } else { $table_select="table_B"; } if ($request->getParam("brand") != NULL && $request->getParam("groups") != NULL && $request->getParam("engine_no") != NULL) { $sql = "SELECT * FROM ".$table_select." WHERE (inv_date <= '" . $request->getParam("inv_date2"). "' AND inv_date >= '" . $request->getParam("inv_date"). "') AND brand='".$request->getParam("brand")."' AND groups='".$request->getParam("groups")."' AND engine_no='".$request->getParam("engine_no")."'"; } elseif ($request->getParam("brand") != NULL && $request->getParam("groups") != NULL) { $sql = "SELECT * FROM ".$table_select." WHERE (inv_date <= '" . $request->getParam("inv_date2"). "' AND inv_date >= '" . $request->getParam("inv_date"). "') AND brand='".$request->getParam("brand")."' AND groups='".$request->getParam("groups")."'"; } elseif ($request->getParam("brand") != NULL) { $sql = "SELECT * FROM ".$table_select." WHERE (inv_date <= '" . $request->getParam("inv_date2"). "' AND inv_date >= '" . $request->getParam("inv_date"). "') AND brand='".$request->getParam("brand")."'"; } elseif ($request->getParam("groups") != NULL) { $sql = "SELECT * FROM ".$table_select." WHERE (inv_date <= '" . $request->getParam("inv_date2"). "' AND inv_date >= '" . $request->getParam("inv_date"). "') AND groups='".$request->getParam("groups")."'"; } else { $sql = "SELECT * FROM ".$table_select." WHERE stat<>'1' AND (inv_date <= '" . $request->getParam("inv_date2"). "' AND inv_date >= '" . $request->getParam("inv_date"). "')"; //$sql = "SELECT * FROM ".$table_select." WHERE (inv_date <= '" . $request->getParam("inv_date2"). "' AND inv_date >= '" . $request->getParam("inv_date"). "') AND brand='".$request->getParam("brand")."'"; } Thank you Quote Link to comment Share on other sites More sharing options...
trq Posted February 27, 2008 Share Posted February 27, 2008 The logic of an if else if statement is quite clear. When the first expression found to be true is reached, the code within that block is executed, no other expressions are then tested. Quote Link to comment Share on other sites More sharing options...
unsider Posted February 27, 2008 Share Posted February 27, 2008 if cond == true { // do this } else { // do this } like thorpe said, simple process, and you can't test an if state inside of another. Quote Link to comment Share on other sites More sharing options...
Lamez Posted February 27, 2008 Share Posted February 27, 2008 lol I feel like adding <?php $var = "1"; if ($var === ("1")){ echo "var is equal to 1"; }else{ echo "var is not equal to 1": } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted February 27, 2008 Share Posted February 27, 2008 and you can't test an if state inside of another. Um, yes you can. Quote Link to comment Share on other sites More sharing options...
unsider Posted February 27, 2008 Share Posted February 27, 2008 Really? I've never tried to do that. I need to do some more reading. :-X Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.