PHP - Help With Php Conditions
I have created a form in wich a user inputs until 5 ranges of numbers
<tr> <td width='270' align='right'>Εύρος1__Από: </td> <td><input type='text' name='fromNum' size='20' /></td> <td width='270' align='right'>Εως: </td> <td><input type='text' name='toNum' size='20'/></td> </tr> <tr> <td width='270' align='right'>Εύρος2__Από: </td> <td><input type='text' name='fromNum2' size='20' /></td> <td width='270' align='right'>Εως: </td> <td><input type='text' name='toNum2' size='20'/></td> </tr> <tr> the same and for ranges 3,4,5 i put a constraint for the ranges $regExpNum = '/^[0-9]{6}$/'; $regExpNum2 = '/^[0-9]{6}$/'; $regExpNum3 = '/^[0-9]{6}$/'; $regExpNum4 = '/^[0-9]{6}$/'; $regExpNum5 = '/^[0-9]{6}$/'; $validfromNum = preg_match($regExpNum,$_POST['fromNum'],$matchesfrom); $validtoNum = preg_match($regExpNum,$_POST['toNum'],$matchesto); $validfromNum2 = preg_match($regExpNum2,$_POST['fromNum2'],$matchesfrom2); $validtoNum2 = preg_match($regExpNum2,$_POST['toNum2'],$matchesto2); $validfromNum3 = preg_match($regExpNum3,$_POST['fromNum3'],$matchesfrom3); $validtoNum3 = preg_match($regExpNum3,$_POST['toNum3'],$matchesto3); $validfromNum4 = preg_match($regExpNum4,$_POST['fromNum4'],$matchesfrom4); $validtoNum4 = preg_match($regExpNum4,$_POST['toNum4'],$matchesto4); $validfromNum5 = preg_match($regExpNum5,$_POST['fromNum5'],$matchesfrom5); $validtoNum5 = preg_match($regExpNum5,$_POST['toNum5'],$matchesto5); i want to wright a combination of contitions for the five ranges. for one range here is the code, but could you please help me to write a code for all of them? $regExpNum = '/^[0-9]{6}$/'; $validfromNum = reg_match($regExpNum,$_POST['fromNum'],$matchesfrom); $validtoNum = preg_match($regExpNum,$_POST['toNum'],$matchesto); $errorMsg=''; if (!$validfromNum || !$validtoNum) { if (!$_POST['fromNum'] && !$_POST['toNum']) { $errorMsg="μήνυμα"; $htmlData['errorMsg']= $errorMsg; $this->loadPage($htmlData); return false; } else if ($validtoNum && !$_POST['fromNum']) { set_time_limit(240); $data = $this->R100WorkOrder->GetWoRangeData($_POST['toNum'], $_POST['toNum']); } else if ($validfromNum && !$_POST['toNum']) { set_time_limit(240); $data = $this->R100WorkOrder->GetWoRangeData($_POST['fromNum'], $_POST['fromNum']); } else { $errorMsg="μήνυμα"; $htmlData['errorMsg']= $errorMsg; $this->loadPage($htmlData); return false; } } else { ####################################################### Form Validation ################################################# End if ($_POST['fromNum'] > $_POST['toNum']) { $errorMsg="μήνυμα "; $htmlData['errorMsg']= $errorMsg; $this->loadPage($htmlData); return false; } else if ($_POST['toNum'] - $_POST['fromNum'] > 100 ) { $errorMsg="μήνυμα"; $htmlData['errorMsg']= $errorMsg; $this->loadPage($htmlData); return false; } else { set_time_limit(240); $data = $this->R100WorkOrder->GetWoRangeData($_POST['fromNum'], $_POST['toNum']); } } Similar TutorialsI am trying to get 6 usernames and passwords from a local database via a file I created called database_log.inc. note 2 columns and 6 rows How can get each password & username with the current code? here is the code for the log on: <?php function clean($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } $user = clean($_POST['username']); $pass = clean($_POST['password']); include 'database_log.inc'; //info from the database separate file if ($user == "shane" && $pass == "shane") //password and user name not in the database { session_start(); $_SESSION['username'] = $user; $_SESSION['password'] = $pass; $_SESSION['ON']="TRUE"; $lifetime=600; setcookie(session_name(),session_id(),time()+$lifetime); header( 'Location: inner.php' ) ; exit(); } else { header( 'Location: index.php' ); session_destroy(); exit(); } ?> Hey guys, Been playing about here and I'm completely stuck! I've created a button with a form field that the user can put a number into and submit it. This works out a few things and removes "resources" from the users account in the database depending on the unit and the cost of that unit. (I've done this the only way I could work out how). But the next step I need to do an If I think, to find out of the user has enough resources on the account to build X amount, at current it just makes the resources go into the - numbers. One of the units in unit.php: Code: [Select] <?php $result = mysql_query("SELECT * FROM userdb WHERE username='$_SESSION[user]'") or die(mysql_error()); echo "<table border='1' cellpadding='10'>"; echo "<th colspan='6'>Offence</th>"; echo "<tr> <th>Unit Name</th> <th>Number</th> <th>Wood Cost</th> <th>Iron Cost</th> <th>TP Cost</th> <th>Create</th> </tr>"; while($row = mysql_fetch_array( $result )) { echo "<tr>"; echo '<td>Unit 1</td>'; echo '<td>' . $row['ounit1'] . '</td>'; echo '<td>'. $ounit1w . '</td>'; echo '<td>'. $ounit1i . '</td>'; echo '<td>'. $ounit1tp . '</td>'; echo '<td> <form action="create.php" method="post"> <input type="text" name="number" value="" size="5"> <input type="hidden" name="memberid" value="' . $row['memberid'] . '"> <input type="hidden" name="unit" value="ounit1"> <input type="hidden" name="res1cost" value="'. $ounit1w . '"> <input type="hidden" name="res2cost" value="'. $ounit1i . '"> <input type="hidden" name="tpcost" value="'. $ounit1tp . '"> <input type="submit" name="submit" value="Create"> </form> </td>'; echo "</tr>"; continues x12 for offence and defence so wont copy it all here. create.php: Code: [Select] <?php include ('mysql.php'); ?> <?php //unit costs $ounit1w = 1000; $ounit1i = 1000; $ounit1tp = 100; ?> <?php $memberid = mysql_real_escape_string($_POST['memberid']); $number = $_POST['number']; $unit = $_POST['unit']; $unitres1 = $_POST['res1cost']; $unitres2 = $_POST['res2cost']; $unittp = $_POST['tpcost']; $result = mysql_query("SELECT * FROM userdb WHERE memberid='$memberid'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $unitstart = $row[$unit]; $res1 = $row['res1']; $res2 = $row['res2']; $tp = $row['trainpoints']; } $unitnumber = $unitstart + $number; $resneeded1 = $number * $unitres1; $resneeded2 = $number * $unitres2; $tpneeded = $number * $unittp; $newres1 = $res1 - $resneeded1; $newres2 = $res2 - $resneeded2; $newtp = $tp - $tpneeded; if (isset($_POST['memberid'])) { $query=("UPDATE userdb SET $unit = '$unitnumber' WHERE memberid='$memberid'"); $query2= ("UPDATE userdb SET res1 = '$newres1' WHERE memberid='$memberid'"); $query3= ("UPDATE userdb SET res2 = '$newres2' WHERE memberid='$memberid'"); $query4= ("UPDATE userdb SET trainpoints = '$newtp' WHERE memberid='$memberid'"); mysql_query($query); mysql_query($query2); mysql_query($query3); mysql_query($query4); header('Location: ' . $_SERVER['HTTP_REFERER']); } ?> This works, but I've got no idea how to check if $row['res1'] has $resneeded1 and to stop if it doesn't. Could anyone point me in the right direction or show me an example? Thanks I have a rule of conditions for access into an area of my site. The problem is, that when the wrong password is given, its still giving access to the area of the site. It is happening because I am using conditions wrong, and ask if someone could help me out by pointing out the correct way to do it. When I say "conditions", I am referring to things such as && and || if ($row['laybypassword'] == $_POST['lay-bypassword'] && $row['status'] == "A" || $row['status'] == "B" || $row['status'] == "C") So, if the correct password is given, and the row status equals A, B, or C, then do foobar. I am trying to select text to display on condition of the current date. I've set a Unix timestamp for the current date: <?php $todays_date = date("Y-m-d"); $today = strtotime($todays_date); ?> Next I test for the first condition. I want the text to appear for 2 weeks then terminate: <?php $exp_date = "2011-05-09"; $expiration_date = strtotime($exp_date); $start_date = strtotime("-14 days", $expiration_date); if ($start_date < $today && $expiration_date > $today) { echo "<h2>Special Event #1</h2>"; } elseif { At this point, I want to set the exp_date for the next event and test again, but I don't know how to do it. The techniques I've tried appear to evaluate as false and display the default text which follows the final "else": } else { echo "<h2>Default Text</h2>"; } ?> <?php require_once('upper.php'); if(isset($_COOKIE['AdminCookie'])){ if(isset($_POST['submit'])){ require_once('database.php'); $ActivityName =$_POST['ActivityName']; $EventName =$_POST['EventName']; $BloodGroup =$_POST['BloodGroup']; $Location =$_POST['Location']; $Age =$_POST['Age']; //$Sex =$_POST['Sex']; echo $ActivityName; $query="select * from registration WHERE Flag='A' AND BloodGroup= '$BloodGroup' AND Age ='$Age'"; //$query="select * from registration WHERE Flag='A' AND Address like '%$Location%'"; $result=mysqli_query($dbc,$query) or die('Not Connected'); while($row=mysqli_fetch_array($result)) { echo $row['Name']; } /*if(isset($_POST['ActivityName'])) { require_once('database.php'); $Search=$_POST['Search']; $query="select * from registration where Flag='A' AND Activity like '%,$Search,%'"; $result=mysqli_query($dbc,$query) or die('Not Connected'); while($row=mysqli_fetch_array($result)) { echo "<table border='2'><tr><td> Name--".$row['Name']."</td> <td>Contact Number--".$row['ContactNumber']."</td> <td>Email--".$row['Email']."</td> <td>Address--".$row['Address']."</td></tr></table>"; } } elseif(isset($_POST['EventId'])){ require_once('database.php'); $Search=$_POST['Search']; $query="SELECT * FROM registration r JOIN participation p ON r.LoginId = p.LoginId WHERE r.Flag='A' AND p.EventId ='$Search'"; $result=mysqli_query($dbc,$query) or die('Not Connected'); while($row=mysqli_fetch_array($result)){ echo "<table border='2'><tr><td> Name--".$row['Name']."</td> <td>Contact Number--".$row['ContactNumber']."</td> <td>Email--".$row['Email']."</td> <td>Address--".$row['Address']."</td></tr></table>"; }} elseif(isset($_POST['Location'])) { require_once('database.php'); $Search=$_POST['Search']; $query="select * from registration where Flag='A' AND Address like '%$Search%'"; $result=mysqli_query($dbc,$query) or die('Not Connected'); while($row=mysqli_fetch_array($result)) { echo "<table border='2'><tr><td> Name--".$row['Name']."</td> <td>Contact Number--".$row['ContactNumber']."</td> <td>Email--".$row['Email']."</td> <td>Address--".$row['Address']."</td></tr></table>"; } } elseif(isset($_POST['BloodGroup'])) { require_once('database.php'); $Search=$_POST['Search']; $query="select * from registration where Flag='A' AND BloodGroup ='$Search'"; $result=mysqli_query($dbc,$query) or die('Not Connected'); while($row=mysqli_fetch_array($result)) { echo "<table border='2'><tr><td> Name--".$row['Name']."</td> <td>Contact Number--".$row['ContactNumber']."</td> <td>Email--".$row['Email']."</td> <td>Address--".$row['Address']."</td></tr></table>"; }*/ } ?> <html><body><form action='<?php echo $_SERVER['PHP_SELF']?>' method="post"> <?php require_once('database.php'); $result=mysqli_query($dbc,"select * from Activity"); echo "Select Activity    <select name='ActivityName'> <option></option>"; while($row=mysqli_fetch_array($result)){ echo " <option>".$row['Title']."</option>"; } echo "</select><br>"; $result=mysqli_query($dbc,"select * from events"); echo "Select Events    <select name='EventName'> <option></option>"; while($row=mysqli_fetch_array($result)){ echo " <option>".$row[Title]."</option>"; } echo "</select><br>"; $result=mysqli_query($dbc,"select * from registration"); echo "Select Blood Group    <select name='BloodGroup'> <option></option>"; while($row=mysqli_fetch_array($result)){ echo " <option>".$row[BloodGroup]."</option>"; } echo "</select><br>"; echo" Enter Location    <input type='text' name='Location'><br>"; echo"Enter Age    <input type='text' name='Age'><br>"; echo "Enter Sex    <select> <option></option> <option>Male</option> <option>Female</option> </select><br>"; echo "<input type='submit' name='submit' value='Search'><br>"; echo"</form></body></html>"; echo "<a href='log_out.php'>Admin Log out</a><br>"; echo "<a href='AdminHome.php'>Back to Admin Home</a>"; } else{echo 'Restricted Page'."<br><br>".'Access Denied';} require_once('lower.php');?> Hi frds.......... I want to search by "Age" and "Blood Group" first.On combobox when I select both Age and Blood Group it gives the rihgt result but when I select only one field and other remain blank it not works............. I want when I select only one field, query executes for one condition only.... It means when I select only Blood Group and leave Age field blank it displays all Name have required Blood Group without any age condition. I forgot how to write multiple conditions with if(). if (A == B || C == D) {foobar;} I know the above is if any of the conditions is true, then do foobar, but what is it again so they both have to be true? I have forgotten, but I'm guessing either if (A == B && C == D) {foobar;} if (A == B ++ C == D) {foobar;} ? Hello, Im trying to write a select query that has two conditions. First the playername is = username and second shipyard = 1 I keep getting a parse error: Parse error: syntax error, unexpected ',' in C:\wamp\www\SWB\planet1.php on line 85 Heres the code: Code: [Select] $tester = "1"; $colname_Planet1 = "-1"; if (isset($_SESSION['MM_Username'])) { $colname_Planet1 = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']); } mysql_select_db($database_swb, $swb); $query_Planet1 = ("SELECT * FROM planet WHERE ShipYard = %s AND PlayerName = %s", GetSQLValueString($tester, "int"),GetSQLValueString($colname_Planet1, "text")); $Planet1 = mysql_query($query_Planet1, $swb) or die(mysql_error()); $row_Planet1 = mysql_fetch_assoc($Planet1); $totalRows_Planet1 = mysql_num_rows($Planet1); Please help :| Hey all, I would like to some how clean up an if statement to be a little cleaner. Code: [Select] if(condition && condition && (condition && condition) || (condition && condition) || (condition && condition)) How can I do that? Hello everyone! I'm new here on phpfreaks - Here's my problem. I get "1 <br/> 2" echoed, but not the query results. the connect() function connects and selects a table in a mysql database. Here's the code: Code: [Select] <?php connect(); $query = "SELECT `title`, `body`, `date` FROM `tutorials` ORDER BY `date` DESC" or die ("Query Error"); $counter = 0; if ($query_run = mysql_query($query)) { while ($query_row = mysql_fetch_assoc($query_run)) && ($counter <= 2) { $title = $query_row['title']; $body = $query_row['body']; $date = $query_row['date']; $counter ++; echo $counter; echo "<br/>"; echo $title; echo $body; echo $date; } } ?> If anyone has any idea, please help! - I'm been battling this for a few hours now Good afternoon all, I'm looking for some help with joins and dates. Not something I have ever done before so hoping that someone can point me in the right direction. Here is the code I have just now which works absolutely fine in terms of find the person with the oldest date of birth:
$get_oldest_player = mysql_query(" SELECT P.PlayerDOB AS dob, CONCAT(P.PlayerFirstName, ' ', P.PlayerLastName) AS name, P.PlayerID AS id FROM tplss_players P, tplss_appearances A, tplss_matches M WHERE P.PlayerID = A.AppearancePlayerID AND A.AppearanceMatchID = M.MatchID AND M.MatchDateTime = '$matchdate' ORDER BY dob ASC LIMIT 0,1 ",$connection) or die(mysql_error());Problem is, I have two tables I'm wanting to include in this query, and not entirely sure how I combine them in the search. I have ONE table for the people (tplss_players) but TWO tables recorded instances of their involvement in matches (tplss_appearances and tplss_substitutions). Should I use a LEFT JOIN somehow ? Not sure where it sits in the layout of the query? tplss_appearances and tplss_substitutions are the same in their structure. Any help would be greatly appreciated. Niall Do race conditions usually exist when writing OR appending to an existing file? Code: [Select] $f1 = fopen($filename1, 'r+'); $f2 = fopen($filename2, 'a'); flock($f1, LOCK_EX); flock($f2, LOCK_EX); fwrite($f1, 'foo'); fwrite($f2, 'foo'); flock($f1, LOCK_UN); flock($f2, LOCK_UN); fclose($f1); fclose($f2); What would happen if this code ran at the exact same time? Is there a chance that the data could be corrupted in the aforementioned code example? Hello everyone, I'm a newbie with PHP and mySQL and need some assistance with writing a php script that searches a mySQL database using a form. The form has five fields that I want to search from and one is a required field (State). I need to filter or narrow down the search by either two or more fields. The problem I am having is if I used multiple WHERE clauses using the AND condition I have to enter valid information in all five fields and if I use the OR condition then my search does not produce the desired outcome (too many results). I "think" I need to use the AND condition but I need to be able to leave some of the fields blank (except for the State field) and narrow my search with using anywhere from 2-5 search fields. Also, another requirement is to be able to enter partial information in the search field "without" having to enter a wildcard in the search field. Any assistance is very much appreciated and thanks in advance for your help. Form Fields: State SELECT FIELD Lease TEXT FIELD Operator Name TEXT FIELD County or Parish TEXT FIELD Well No TEXT FIELD I have a table called well_permits and it is structure is as follows: date DATE state TEXT county VARCHAR api VARCHAR permit_no VARCHAR operator VARCHAR phone VARCHAR contact VARCHAR lease VARCHAR well_no VARCHAR permit_for VARCHAR welltype VARCHAR wellspot VARCHAR lat FLOAT lon FLOAT depth VARCHAR This is what I have for the connecting to my database and selecting the fields: <?php require_once('../../../Connections/Wldatabase.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $currentPage = $_SERVER["PHP_SELF"]; //Variable to store Unique_ID aka API which will be passed to the well-search-results.php page $var_api_rs_search = $_Get['api']; $maxRows_rs_search = 20; $pageNum_rs_search = 0; if (isset($_GET['pageNum_rs_search'])) { $pageNum_rs_search = $_GET['pageNum_rs_search']; } $startRow_rs_search = $pageNum_rs_search * $maxRows_rs_search; $var_state_rs_search = "%"; if (isset($_GET['state'])) { $var_state_rs_search = $_GET['state']; } $var_lease_rs_search = "%"; if (isset($_GET['lease'])) { $var_lease_rs_search = $_GET['lease']; } $var_well_no_rs_search = "%"; if (isset($_GET['well_no'])) { $var_well_no_rs_search = $_GET['well_no']; } $var_operator_rs_search = "%"; if (isset($_GET['operator'])) { $var_operator_rs_search = $_GET['operator']; } $var_county_rs_search = "%"; if (isset($_GET['County'])) { $var_county_rs_search = $_GET['County']; } mysql_select_db($database_Wldatabase, $Wldatabase); $query_rs_search = sprintf("SELECT DISTINCT * FROM well_permits WHERE (well_permits.`state` LIKE %s AND well_permits.county LIKE %s) OR (well_permits.lease LIKE %s) OR (well_permits.operator LIKE %s) OR (well_permits.well_no LIKE %s) ORDER BY well_permits.county", GetSQLValueString($var_state_rs_search, "text"),GetSQLValueString($var_county_rs_search, "text"),GetSQLValueString($var_lease_rs_search, "text"),GetSQLValueString($var_operator_rs_search, "text"),GetSQLValueString($var_well_no_rs_search, "text")); $query_limit_rs_search = sprintf("%s LIMIT %d, %d", $query_rs_search, $startRow_rs_search, $maxRows_rs_search); $rs_search = mysql_query($query_limit_rs_search, $Wldatabase) or die(mysql_error()); $row_rs_search = mysql_fetch_assoc($rs_search); ?> This is my form: <form action="search.php" method="GET" name="frmsearch" target="_self"> <input name="api" type="hidden" value="" /> <div> <table width="900" border="0" align="center" cellpadding="2" cellspacing="2"> <tr> <td colspan="6"> <p style="text-align:left">Select a State then enter at least one search criteria. State is a required field.</p> * Denotes a required field.<br> </td> </tr> <tr> <td align="right">* State: </td> <td> <select name="state" size="1" dir="ltr" lang="en"> <option value="AL">AL</option> <option value="AR">AR</option> <option value="CA">CA</option> <option value="CO">CO</option> <option value="IL">IL</option> <option value="IN">IN</option> <option value="KS">KS</option> <option value="KY">KY</option> <option value="LA">LA</option> <option value="MI">MI</option> <option value="MS">MS</option> <option value="MT">MT</option> <option value="ND">ND</option> <option value="NE">NE</option> <option value="NM">NM</option> <option value="NY">NY</option> <option value="OH">OH</option> <option value="OK">OK</option> <option value="OS">OS</option> <option value="PA">PA</option> <option value="SD">SD</option> <option value="TX">TX</option> <option value="UT">UT</option> <option value="WV">WV</option> <option value="WY">WY</option> </select> </td> <td align="right">County or Parish: </td> <td align="left"><input name="County" type="text" value="" size="35" maxlength="40" /></td> </tr> <tr> <td width="63" align="right">Lease: </td> <td width="239"><input name="lease" type="text" value="" /></td> <td align="right">Well No: </td> <td><input name="well_no" type="text" value="" /></td> </tr> <tr> <td width="111" align="right">Operator Name: </td> <td width="261"><input name="operator" type="text" value="" /></td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td align="left"><input name="search" type="submit" value="Search" /></td> </tr> </table> </form> My Repeat Region starts here <table width="100%" border="1" align="center" cellpadding="2" cellspacing="2"> <tr> <td align="right"> </td> <th align="center">Operator</th> <th align="center">Lease</th> <th align="center">Well Number</th> <th align="center">County</th> <th align="center">State</th> </tr> <tr> <?php do { ?> <td align="center"><a href="results.php?recordID=<?php echo $row_rs_search['api']; ?>">Select</a></td> <td align="left"><?php echo $row_rs_search['operator']; ?></td> <td align="left"><?php echo $row_rs_search['lease']; ?></td> <td align="center"><?php echo $row_rs_search['well_no']; ?></td> <td align="center"><?php echo $row_rs_search['county']; ?></td> <td align="center"><?php echo $row_rs_search['state']; ?></td> </tr> <?php } while ($row_rs_search = mysql_fetch_assoc($rs_search)); ?> </table> <p align="center">Number of Wells Located: <?php echo ($startRow_rs_search + 1) ?> to <?php echo min($startRow_rs_search + $maxRows_rs_search, $totalRows_rs_search) ?> of <?php echo $totalRows_rs_search ?></p> <table border="0" align="center"> <tr> <td align="center"><?php if ($pageNum_rs_search > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_rs_search=%d%s", $currentPage, 0, $queryString_rs_search); ?>">First</a> <?php } // Show if not first page ?></td> <td align="center"><?php if ($pageNum_rs_search > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_rs_search=%d%s", $currentPage, max(0, $pageNum_rs_search - 1), $queryString_rs_search); ?>">Previous</a> <?php } // Show if not first page ?></td> <td align="center"><?php if ($pageNum_rs_search < $totalPages_rs_search) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_rs_search=%d%s", $currentPage, min($totalPages_rs_search, $pageNum_rs_search + 1), $queryString_rs_search); ?>">Next</a> <?php } // Show if not last page ?></td> <td align="center"><?php if ($pageNum_rs_search < $totalPages_rs_search) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_rs_search=%d%s", $currentPage, $totalPages_rs_search, $queryString_rs_search); ?>">Last</a> <?php } // Show if not last page ?></td> </tr> </table> Hi, I'm using a form which contains many select boxes. The select boxes looks like this: <select name="locatie" id="locatie"> <option value="" selected>-----</option> <?php require_once ('config.php'); $query = "select ID, locatie from locatie"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">'.$locatie.'</option>'; } ?> </select> <select name="prijsVan" id="prijsVan"> <option value="" selected>-----</option> <?php $query = "select ID, prijs from prijs"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">€ '.$prijs.'</option>'; } ?> </select> <select name="prijsTot" id="prijsTot"> <option value="" selected>-----</option> <?php $query = "select ID, prijs from prijs"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">€ '.$prijs.'</option>'; } ?> </select> <select name="ligging" id="ligging"> <option value="" selected>-----</option> <?php $query = "select ID, ligging from ligging"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">'.$ligging.'</option>'; } ?> </select> <select name="oppervlakte" id="oppervlakte"> <option value="" selected>-----</option> <?php $query = "select ID, oppervlakte from oppervlakte"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">'.$oppervlakte.' m²</option>'; } ?> </select> <select name="kamers" id="kamers"> <option value="" selected>-----</option> <?php $query = "select ID, kamers from kamers"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">'.$kamers.'</option>'; } ?> </select> <select name="woning" id="woning"> <option value="" selected>-----</option> <?php $query = "select ID, type from woning"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">'.$type.'</option>'; } ?> </select> <input type="submit" name="submit" value="Zoeken"> To display the result i'm using a PHP processing page which contains the flowing code: <?php ...... ..... $locatie = $_POST['locatie']; $prijsVan = $_POST['prijsVan']; $prijsTot = $_POST['prijsTot']; $ligging = $_POST['ligging']; $oppervlakte = $_POST['oppervlakte']; $kamers = $_POST['kamers']; $woning = $_POST['woning']; $eigenschappen = $_POST['eigenschappen']; // SHOW LOCATIE if($locatie !='' && $prijsVan =='' && $prijsTot =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $woning =='' && $eigenschappen =='') { $query .= " AND locatie.ID = '" . $locatie. "' ORDER BY prijs.ID"; } // SHOW LOCATIE_PRIJSVAN if($prijsVan !='' && $locatie !='' && $prijsTot =='' && $woning =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $eigenschappen =='') { $query .= " AND locatie.ID = '" . $locatie . "' AND prijs.ID >= '" . $prijsVan . "' ORDER BY prijs.ID"; } // SHOW LOCATIE_PRIJSTOT if($prijsTot !='' && $locatie !='' && $prijsVan =='' && $woning =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $eigenschappen =='') { $query .= " AND locatie.ID = '" . $locatie . "' AND prijs.ID <= '" . $prijsTot . "' ORDER BY prijs.ID"; } // SHOW PRIJS VAN if($prijsVan !='' && $locatie =='' && $prijsTot =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $woning =='' && $eigenschappen =='') { $query .= " AND prijs.ID >= '" . $prijsVan . "' ORDER BY prijs.ID"; } // SHOW PRIJS TOT if($prijsTot !='' && $locatie =='' && $prijsVan =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $woning =='' && $eigenschappen =='') { $query .= " AND prijs.ID <= '" . $prijsTot . "' ORDER BY prijs.ID"; } // SHOW PRIJS_VAN_PRIJS_TOT if($prijsVan !='' && $prijsTot !='' && $locatie =='' && $woning =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $eigenschappen =='') { $query .= " AND prijs.ID BETWEEN '" . $prijsVan . "' AND '" . $prijsTot . "' ORDER BY prijs.ID"; } // SHOW LIGGING if($ligging !='' && $prijsVan =='' && $prijsTot =='' && $locatie =='' && $oppervlakte =='' && $kamers =='' && $woning =='' && $eigenschappen =='') { $query .= " AND ligging.ID = '" . $ligging. "' ORDER BY prijs.ID"; } ...................... and so on......... // Error: indien geen keuze gemaakt show deze error if($prijsVan =='' && $prijsTot =='' && $locatie =='' && $woning =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $eigenschappen =='') { ?> <center><font color="#666"> <?php postError(); ?></font></center><?php } else{ //Execute query $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['image_id'] ; echo $row['locatie'] ; echo $row['prijs']; echo $row['type']; echo $row['kamers']; echo $row['oppervlakte'] . ' m²'; echo $row['ligging']; echo $row['eigenschappen']; } } mysql_close($con); ?> As you see i have to use many IF condition to display the result of every select combinations. Is there any way to do it in better way and using less coding? Thanks. I am a novice PHP coder, just started learning. I am trying to display a message on my webpage that should be triggered by a date check. The code is below (I removed all HTML tags for simplicity for now): <?php $m=date("m"); $d=date("d"); $y=date("Y"); $int_d = (int)$d; //Thanksgiving if ($m="11"&&$y="2010"&&$int_d>23&&$int_d<=28) { echo 'Happy Thanksgiving!'; } //Holidays if ($m="12"&&$y="2010"&&$int_d>=18&&$int_d<=31) { echo 'Happy Holidays!'; } ?> I want each statement to be executed during the appropriate dates i.e. "Happy Thanksgiving" from 11/24/2010 to 11/28/2010, and "Happy Holidays" from 12/18/2010 to 12/31/2010. The problem is that both statement are being executed regardless of the date conditions I use? Thoughts? Thanks I have the following code:
$fp = fopen(“path_to_file”, ‘a’); flock($fp, LOCK_EX); fwrite($fp, $string); flock($fp, LOCK_UN); fclose($fp);If I try to lock the file in two different places at the same time, this will cause a race condition. How can I prevent this? I know in Java, for example, it has a concurrent library which contains reentrant lock, which basically tries to get the lock and if can't waits. What can I do in PHP? NOTE - Please read the information first as it contains important information to understand the problem. Rules → • There are 9 Columns(C1,C2,C3,C4,C5,C6,C7,C8,C9) [ Max columns will be 9] • The number of Rows can vary from 3,6,9,12,15,18 (Max). In this case Number of Rows shall be 12 Number of Rows = No of Tickets (Max Allowed 6) x Rows Per Ticket (Max Allowed 3). Thus, Max Rows can be 18 • Each Row is required to have 4 Blank Spaces and 5 Filled with Numbers • All numbers available in the Column Array have to be utilized • This configuration of an shall create a matrix of 9 Columns & 12 Rows (3 x 4 Tickets), which is 108 MATRIX BLOCKS where only a maximum of 60 numbers can be filled out of 108 available blocksrandomly with the above conditions being met 100%. • The numbers in column must be arranged / sorted in ASCENDING ORDER (For coding logic purpose, as soon as the number is assigned to the new MATRIX MAP use array_shift() or unset() the number so as to avoid repetition Example - Row 1 and Column 1 shall generate a MATRIX BLOCK - R1C1 Row 3 and Column 7 shall generate a MATRIX BLOCK - R3C7 Matrix Block can also be termed as Matrix Cell for your ease (if needed) MASTER SET OF ARRAY WITH NUMBERS array( "C1"=> array( 1, 2, 3, 5, 6, 7, 9 ), //7 Numbers "C2"=> array( 13, 14, 15, 17, 18, 19 ), //6 Numbers "C3"=> array( 21, 22, 23, 24, 25, 26, 30 ), //7 Numbers "C4"=> array( 31, 33, 34, 36, 37, 38, 39 ), //7 Numbers "C5"=> array( 41, 42, 46, 47, 48, 49, 50 ), //7 Numbers "C6"=> array( 51, 52, 53, 54, 55, 57, 58 ), //7 Numbers "C7"=> array( 61, 62, 64, 65, 69, 70 ), //6 Numbers "C8"=> array( 71, 74, 75, 76, 77, 78 ), //6 Numbers "C9"=> array( 82, 83, 85, 87, 88, 89, 90 ) //7 Numbers ); The above array has 60 Numbers to be filled out of 108 MATRIX BLOCK / CELL which meets the condition that for a FULL BLOCK containing 4 MINI BLOCKS WITH 3 ROWS (max. allowed) EACH I have been able to generate this without any issue meeting all the conditions of the Columns My Allocation Matrix Array will look like array( "R1"=> array( "C1"=> true, // Means that MATRIX BLOCK R1C1 will be NOT EMPTY "C2"=> false, // Means that MATRIX BLOCK R1C2 will be EMPTY "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> false, "C7"=> true, "C8"=> true, "C9"=> false ), "R2"=> array( "C1"=> false, "C2"=> true, "C3"=> false, "C4"=> true, "C5"=> false, "C6"=> true, "C7"=> true, "C8"=> true, "C9"=> false ), "R3"=> array( "C1"=> true, "C2"=> true, "C3"=> true, "C4"=> true, "C5"=> false, "C6"=> false, "C7"=> false, "C8"=> false, "C9"=> true ), "R4"=> array( "C1"=> true, "C2"=> true, "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> false ), "R5"=> array( "C1"=> false, "C2"=> false, "C3"=> false, "C4"=> false, "C5"=> true, "C6"=> true, "C7"=> true, "C8"=> true, "C9"=> true ), "R6"=> array( "C1"=> true, "C2"=> true, "C3"=> false, "C4"=> true, "C5"=> false, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> true ), "R7"=> array( "C1"=> false, "C2"=> false, "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> false, "C7"=> true, "C8"=> true, "C9"=> true ), "R8"=> array( "C1"=> true, "C2"=> false, "C3"=> false, "C4"=> true, "C5"=> false, "C6"=> false, "C7"=> true, "C8"=> true, "C9"=> true ), "R9"=> array( "C1"=> true, "C2"=> false, "C3"=> true, "C4"=> false, "C5"=> true, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> true ), "R10"=> array( "C1"=> false, "C2"=> true, "C3"=> true, "C4"=> true, "C5"=> true, "C6"=> false, "C7"=> true, "C8"=> false, "C9"=> false ), "R11"=> array( "C1"=> false, "C2"=> true, "C3"=> false, "C4"=> true, "C5"=> true, "C6"=> true, "C7"=> false, "C8"=> true, "C9"=> false ), "R12"=> array( "C1"=> true, "C2"=> false, "C3"=> true, "C4"=> true, "C5"=> false, "C6"=> true, "C7"=> false, "C8"=> false, "C9"=> true ) ); In the above array R stands for Row, C for Column, TRUE/FALSE (Boolean) means that if TRUE a Number can be filled in the resulting MATRIX BLOCK / CELL ( Row[Number]Column[Number] ) else if FALSE the MATRIX BLOCK / CELL shall be EMPTY The result for the above shall be
PROBLEM : I am unable to understand what should possibly be the logic & loop used here for creating a MATRIX ALLOCATION MAP as shown above I have tried while, foreach & for but unable determine the perfect combination which would meet the conditions. (Tried all of the above with Nested Loops also) Edited May 1, 2020 by AlphaMikeTags |