PHP - Check String For Multiple Values
Hi all, i've got a string ($currentcatid) which contains one number which changes dependant on which page the visitor is on.. ie it may be perhaps "23" or "17" .
I need to do a check against this string to see if it contains any of the following values .. 31,32, 1, 24 . I cant remember how i did it before but i think it was with pipes.. something along the lines of if ($currentcatid =="31"||"32"||"1"||"24") { action } can anyone help? Thanks Similar Tutorials
Table Issue - Multiple Location Values For User Pushes Values Out Of Row Instead Of Wrapping In Cell
Hi, How can i check if a string is a multiple of 0.1 without anything being left over? like 1.6 = true, 1.46 = false I have displayed check box values(ugroup field) from ugroups table.now what i want to do is,when user select multiple check boxes and submit it should be insert into relavent feild in table.now it's insert check boxes values.but not in relevant field.this is my code.Please help me.
//select ugroup's from group table. <?php $result = "SELECT id,ugroup FROM group"; $res_result = db::getInstance()->query($result); ?> <form action="db_sql/db_add_page.php" method="get"> Tittle :<input type="text" size="100" name="tittle" /> Description :<textarea cols="80" id="editor1" name="description" rows="10"></textarea> //Display ugroups in textboxes and checkboxes <?php while( $line=$res_result->fetch(PDO::FETCH_ASSOC)) { echo '<input type="checkbox" name="group[]" value=" '. $line['ugroup'] .'" />'; echo'<input type="text" name="ugroup" disabled="disabled" value=" '. $line['ugroup'] .'" size="7" "/>'; echo ' '; } ?><input type="submit" value="Submit"> </form>db_add_page.php if(isset($_POST)) { $tittle = $_POST['tittle']; $description = $_POST['description']; $ugroup = $_POST['group']; $acc_status = "INSERT INTO add_services (id,tittle,description,g1,g2,g3,g4,g5,g6,g7,g8) VALUES(NULL,'".$tittle."','".$description."','".$ugroup[0]."','".$ugroup[1]."','".$ugroup[2]."',' ".$ugroup[3]."','".$ugroup[4]."','".$ugroup[5]."','".$ugroup[6]."','".$ugroup[7]."')"; $rate = db::getInstance()->exec($acc_status); if(!$rate){ echo '<script type="text/javascript">alert("Update Error !");</script>'; }else{ header('Location:../add_page.php'); echo '<script type="text/javascript">alert("Successfuly Updated User Group !");</script>'; } }Attached Files group.jpg 22.14KB 0 downloads add_services.jpg 21.36KB 0 downloads I have this form
<form action="" method="get" name="size"> Størrelse <hr><label><input type="radio" value="9" name="size" onchange="this.form.submit()">92 (2år)</label> <label><input type="checkbox" value="147" name="size" onchange="this.form.submit()">68 (6-9 mdr.) </label><label><input type="checkbox" value="150" name="size" onchange="this.form.submit()">86 (18-24 mdr.)</label> <input type="checkbox" value="149" name="size" onchange="this.form.submit()">80 (12-18 mdr.)</label> <label><input type="checkbox" value="148" name="size" onchange="this.form.submit()">74 (9-12 mdr.)</label> </form>I want to make it so that when the user clicks one checkbox for example size 68 and then checks size 80 I want both sizes to be in the URL query string. But every time the user clicks a new checkbox, the query string changes accordingly. Maybe with a separator like ?size=4:23 and then I will handle it with the DB stuff. Please tell me how to add multiple elements in the query string with this form, thank you! Edited by Stefany93, 21 May 2014 - 08:03 AM. I am trying to make it echo if a string doesn't equal any of the values.
I have tried:
if(!preg_match("/none|Blue|Brown|Green|Grey)/i", $eyecolor)){ echo "Not an eye color"; } Hi, My company has 240+ locations and as such some users (general managers) cover multiple sites. When I run a query to pull user information, when the user has multiple sites to his or her name, its adds the second / third sites to the next columns, rather than wrapping it inside the same table cell. It also works the opposite way, if a piece of data is missing in the database and is blank, its pull the following columns in. Both cases mess up the table and formatting. I'm extremely new to any kind of programming and maybe this isn't the forum for this question but figured I'd give it a chance since I'm stuck. The HTML/PHP code is below: <table id="datatables-column-search-select-inputs" class="table table-striped" style="width:100%"> <thead> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> <th>Actions</th> </tr> </thead> <tbody> <?php //QUERY TO SELECT ALL USERS FROM DATABASE $query = "SELECT * FROM users"; $select_users = mysqli_query($connection,$query);
// SET VARIABLE TO ARRAY FROM QUERY while($row = mysqli_fetch_assoc($select_users)) { $user_id = $row['user_id']; $user_firstname = $row['user_firstname']; $user_lastname = $row['user_lastname']; $username = $row['username']; $user_phone = $row['user_phone']; $user_image = $row['user_image']; $user_title_id = $row['user_title_id']; $user_role_id = $row['user_role_id'];
// POPULATES DATA INTO THE TABLE echo "<tr>"; echo "<td>{$user_id}</td>"; echo "<td>{$user_firstname}</td>"; echo "<td>{$user_lastname}</td>"; echo "<td>{$username}</td>"; echo "<td>{$user_phone}</td>";
//PULL SITE STATUS BASED ON SITE STATUS ID $query = "SELECT * FROM sites WHERE site_manager_id = {$user_id} "; $select_site = mysqli_query($connection, $query); while($row = mysqli_fetch_assoc($select_site)) { $site_name = $row['site_name']; echo "<td>{$site_name}</td>"; } echo "<td>{$user_title_id}</td>"; echo "<td>{$user_role_id}</td>"; echo "<td class='table-action'> <a href='#'><i class='align-middle' data-feather='edit-2'></i></a> <a href='#'><i class='align-middle' data-feather='trash'></i></a> </td>"; //echo "<td><a href='users.php?source=edit_user&p_id={$user_id}'>Edit</a></td>"; echo "</tr>"; } ?>
<tr> <td>ID</td> <td>FirstName</td> <td>LastName</td> <td>Username</td> <td>Phone #</td> <td>Location</td> <td>Title</td> <td>Role</td> <td class="table-action"> <a href="#"><i class="align-middle" data-feather="edit-2"></i></a> <a href="#"><i class="align-middle" data-feather="trash"></i></a> </td> </tr> </tbody> <tfoot> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> </tr> </tfoot> </table>
How do you find out how many character within a String ?? for example: $temp = "apple"; I want to return "5" for $temp as it has 5 characters. Thanks! How can i check if a string is URL encoded or not using PHP Hey, I have an if statement that requires to check a $_POST to make sure its an integer not a string but cant remember how to do this. Anyone able to assits Thanks Hello, I'm working on an error form, and I want to check if the user inserted a number into the name field, and if so return an error. I thought this might of worked, but it doesn't: Code: [Select] if(is_int($_POST['name'])){ $arrErrors['name'] = 'Invalid name, remove numbers.'; } Many thanks Is there any simple way to check if all values in an array are same with an simple if condition Something like if( ...some code...) { //yes, all values are same } else { //nope, all are not same } my PHP Version is 5.2.9-2 Any help would be appreciated. Basically, i want to check if values in an array are equals to 1. Hey. I been using a function to check if a string contains only letters which is: ctype_alpha But i would like to change it to allow numbers 0 to 9 and the letters is there a function to do that in PHP i can't find it. I want to allow Alphabetical strings, Numeric strings, and Alphanumeric strings. For example "Bob", "1234", "bob1234" are all valid. I want to check if the string has invalid characters, return true if it does (or false, which ever method works). How can I do it? I want to check if a string has any of words listed in array; Code: [Select] $array=array('word1', 'word2', 'word3'); $string="This is a sentence containing word2"; Now I want to make an 'if else' to check if the string contains any of the words listed in the array. Thanks I have an array of $fl By using values of this array, i want to create a new string. I need string size will be maximum 200 characters. When i try below code snipped, $f value is added to string two times. How can i add $f to array only one time, with checking size of string. Thank you Code: [Select] $fl=getsomelist(); // gives an array $userList=''; foreach ($fl as $f) { if ( strlen($userList .= $f) <= (200) ) { $userList .= $f; } else { break; } } Hello guys, I have a form where you can select a score between 0 and 10(only integers).
I want to check if the value that I recive, is integer.
Im using this code(exemple):
$integer = intval($_POST["p1"]); if(is_int($integer)){ echo 'INT'; } else { echo 'NO INT'; }My problem is that if it recive letters, the conversion converts it to 0, and it says that it is integer. So with this method I should discard the 0. You guys know a method to avoid that? Thank you guys I was wondering if anyone knows a good way to check for an even number of each character in a string. For example if the string is "abbacc" then it will return true as there are two of each character. However if the string is "ababc" it will return false as there is only 1 c. Thanks for any help hi people can vote 3 times with 3 select menus but i want them not to be able to choose 3x the same select option the options in the select menus come out of the database this is how i let them vote Code: [Select] <?php include("./includes/egl_inc.php"); $secure = new secure(); $secure->secureGlobals(); session_start(); if (isset ($_GET['match'])) { $matchid = (int)$_GET['match']; $_SESSION['matchid'] = $matchid; $matchmaps = mysql_fetch_array(mysql_query("SELECT maps,game FROM ffa_matches WHERE id=$matchid")); $matchmapschecker = $matchmaps[maps]; $matchgamechecker = $matchmaps[game]; $maps=mysql_query("SELECT id,map FROM ffa_maplists where gameid = $matchgamechecker"); while(list($id,$map)=mysql_fetch_row($maps)) { $maplist.="<option value='$id'>$map</option>\n"; } $out[body].="<table width='98%' border='0' cellspacing='0' cellpadding='0' style='border:1px solid black'> <tr style='color:#cccccc; background-color:black;'> <td valign='middle' background='$config[bg2]' align='center' colspan='10'> <br/>Choose Maps<br/> </td> </tr></table><table width='98%' border='0' cellspacing='0' cellpadding='0' style='border:1px solid black'> <tr style='background-color:black;'> <td> <form action='ffainsertmapvote.php' method='post'> <select name='map1'>$maplist</select> <select name='map2'>$maplist</select> <select name='map3'>$maplist</select> <input type='hidden' name='match' value='$matchid' /> <input type='submit' value='Vote' /> </form> </td> </tr></table>"; } include("$config[html]"); ?> do i need jquery to fix this? i dont want the user to be able to go to a next screen without having max 2 the same options selected thanks in advance ! After doing a mysql_query and pulling data into an array like: Code: [Select] $polquery = mysql_query("SELECT * FROM disclosures WHERE transid = '$transid'"); while($something = mysql_fetch_array($polquery){ $status = $something['complete']; } I need to cycle through the array $status to see if all values = "accept", I'm not sure how to do this... or just forgot. Maybe just do a while($status == "accept")? I have a while loop of check box's with the SQL record id's set as there values. I want to be able to pass all the checked records to another page in single var's with the correct ID value in order to list the selected items on the on the next page. any idea's guys? |