PHP - Replace Array In Select Of S3captcha Jquery Plugin
Similar TutorialsThis topic has been moved to Other. http://www.phpfreaks.com/forums/index.php?topic=327155.0 The output of the array1 is looks as below. Code: [Select] Array ( [num_found] => 60 [articles] => Array ( [0] => Array ( [aut] => Array ( [0] => ANI ) [by] => ANI [Id] => 278 [key] => Array ( [0] => trans fats [1] => junk food [2] => food labels [3] => miscarriage [4] => hydrogenated ) [norm] => true [body] => Gorging [cat] => Array ( [0] => food & drink ) [pm] => ANI|P#M#D| [pm] => Beware! [seo] => junk [pmT] => Array ( [0] => trans fats [1] => junk food [2] => food labels [3] => miscarriage [4] => hydrogenated ) [pid] => 72 [Date] => 2011-06-02T00:00:00Z [section] => Health [sd] => 3506926 [ti] => Beware! Junk food can cause miscarriage [ur] => riage [kick] => [subtitle] => [image] => [Tag] => ) [1] => Array ( [aut] => Array ( [0] => URVASHI ASHER ) [by] => URVASHI [Id] => 277 [key] => Array ( [0] => film [1] => design [2] => biography [3] => amitabh bachchan [4] => cinema ) [norm] => true [body] => division. [cat] => Array ( [0] => entertainment ) [pm] => URVASHI ASHER|P#M#D|TNN [pm] => booked [seo] => film [pmT] => Array ( [0] => film [1] => design [2] => biography [3] => amitabh bachchan [4] => cinema ) [pid] => 72 [Date] => 2011-06-02T00:00:00Z [section] => News & Interviews [sd] => 3921796 [ti] => Amitabh booked [uri] => film [kick] => [subtitle] => [image] => [Tag] => ) I have a array2 similar to this. Code: [Select] Array ( [num_found] => 70 [articles] => Array ( [0] => Array ( [aut] => Array ( [0] => ANI ) [by] => RNI [Id] => 643 [key] => Array ( [0] => trans fats [1] => junk food [2] => food labels [3] => miscarriage [4] => hy ) [norm] => true [body] => Test [cat] => Array ( [0] => drink ) [pm] => ANI|P#M#D| [pm] => Beware! [seo] => junk [pmT] => Array ( [0] => trans fats [1] => junk food [2] => food labels [3] => miscarriage [4] => hydrogenated ) [pid] => 73 [Date] => 2011-06-02T00:00:00Z [section] => Health [sd] => 8434 [ti] => Beware [ur] => riage [kick] => [subtitle] => [image] => [Tag] => ) [1] => Array ( [aut] => Array ( [0] => URVASHI ASHER ) [by] => URVASHI [Id] => 345 [key] => Array ( [0] => film [1] => design [2] => biography [3] => bachchan [4] => cinema ) [norm] => true [body] => division. [cat] => Array ( [0] => entertainment ) [pm] => URVASHI|P#M#D|TNN [pm] => booked [seo] => film [pmT] => Array ( [0] => film [1] => design [2] => biography [3] => amitabh bachchan [4] => cinema ) [pid] => 72 [Date] => 2011-06-02T00:00:00Z [section] => News & Interviews [sd] => 43543543 [ti] => booked [uri] => film [kick] => [subtitle] => [image] => [Tag] => ) Please tell me how to add the 1st value from array2 and replace in array1. The output should look like Code: [Select] Array ( [num_found] => 60 [articles] => Array ( [0] => Array ( [aut] => Array ( [0] => ANI ) [by] => RNI [Id] => 643 [key] => Array ( [0] => trans fats [1] => junk food [2] => food labels [3] => miscarriage [4] => hy ) [norm] => true [body] => Test [cat] => Array ( [0] => drink ) [pm] => ANI|P#M#D| [pm] => Beware! [seo] => junk [pmT] => Array ( [0] => trans fats [1] => junk food [2] => food labels [3] => miscarriage [4] => hydrogenated ) [pid] => 73 [Date] => 2011-06-02T00:00:00Z [section] => Health [sd] => 8434 [ti] => Beware [ur] => riage [kick] => [subtitle] => [image] => [Tag] => ) [1] => Array ( [aut] => Array ( [0] => URVASHI ASHER ) [by] => URVASHI [Id] => 277 [key] => Array ( [0] => film [1] => design [2] => biography [3] => amitabh bachchan [4] => cinema ) [norm] => true [body] => division. [cat] => Array ( [0] => entertainment ) [pm] => URVASHI ASHER|P#M#D|TNN [pm] => booked [seo] => film [pmT] => Array ( [0] => film [1] => design [2] => biography [3] => amitabh bachchan [4] => cinema ) [pid] => 72 [Date] => 2011-06-02T00:00:00Z [section] => News & Interviews [sd] => 3921796 [ti] => Amitabh booked [uri] => film [kick] => [subtitle] => [image] => [Tag] => ) where array[0] is the value from array2. Here is my code Code: [Select] if (isset($_GET['hide'])){ $id = intval($_GET['hide']); $explode = explode(",", $_COOKIE['hide']); if (in_array($id, $explode)) { } setcookie('hide', ''.$id.'',time()+32000000); header('Location: index.php'); exit; } My Explanation: If somone clicks ?hide=2 It will add the cookie hide, and the value to 2. Now, if somone clicks ?hide=1, I need it to add 2,1 how is that possible? Then if the in_array is correct, (Means if the value of the cookie is 2 and they clicked ?hide=2) how do I take that number "2" out of the it (Remove it) and make a new array that will be inserted to my $id variable? hi, im trying to replace an arrays key with its value. this is so i can display the html on the pages. eg: index.html <title>{BOARD_TITLE}</title> index.php $template->replace(array( '{BOARD_TITLE}' => $settings['board_name'] )); template.php(template class) function replace($array) { foreach ($array as $key => $val) { echo $key = $val; } return; } however {BOARD_TITLE} does not get replaced with the value. where am i going wrong? Thanks Hello, how could I do a replace using one array? Example: Code: [Select] $changes = array( "{NAME}" => $name, "{CHANGED_PART}" => $desc, "{CHANGE_D}" => date("j"), "{CHANGE_M}" => date("n") ); And then I would want to replace all parts in the left with parts in the right inside a string.Is that possible ? thank you.. 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 ! Hey i hope the title explains it enough. I'm just trying to get into classes. I am making a function to make making mysql querys easier. I pass the class the first string $db->inputstring("INSERT INTO ? (?,?) VALUES ('?','?')"); $db->format('mytable','id','name','1','ben'); Can someone tell me how the format fuction would look? Im not sure how to swap arrays. Hi, If i had the following array: $test = array('key1'=>'test1', 'key2'=>'value2', 'key3'=>array('test','test1','test2')); Is there a way i could change all the values that have the word "test" to "hello"? So basically end up with the following array: $test = array('key1'=>'hello1', 'key2'=>'value2', 'key3'=>array('hello','hello1','hello2')); Is this possible? Thanks hi, I was going through this tutorial: http://www.electrictoolbox.com/json-data-jquery-php-mysql/ here is my HTML Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> <script language="javascript" type="text/javascript"> function populateFruitVariety() { $.getJSON('search-by.php', {fruitName:$('#fruitName').val()}, function(data) { var select = $('#fruitVariety'); var options = select.attr('options'); $('option', select).remove(); $.each(data, function(index, array) { options[options.length] = new Option(array['variety']); }); }); } $(document).ready(function() { populateFruitVariety(); $('#fruitName').change(function() { populateFruitVariety(); }); }); </script> </head> <body> <form> Search by: <select name="name" id="fruitName"> <option>Please Select</option> <option id="Town" value="Town">Town</option> <option id="County" value="County">County</option> </select> Variety: <select name="variety" id="fruitVariety"> </select> </form> </body> </html> here is my PHP Code: [Select] $dbhost = "xxx"; $dbname = "xxx"; $dblogin = "xxx"; $dbpass = "xxx"; function dbConnect() { global $dbhost; global $dbname; global $dblogin; global $dbpass; $db = mysql_connect($dbhost, $dblogin, $dbpass) or die("could not connect to database: ".mysql_error()); mysql_select_db($dbname) or die("could not select database"); return $db; } function dbClose($db) { mysql_close($db); } // basis code ^^ $db = dbConnect(); $rows = array(); if(isset($_GET['Town'])) { $query = "SELECT DISTINCT rsCounties FROM pubs"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo json_encode($rows); } } if(isset($_GET['County'])) { $stmt = $pdo->prepare("SELECT rsCounty FROM pubs"); $stmt->execute(array($_GET['rsCounty'])); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); } echo json_encode($rows); Can someone please help? I have the JQuery working but not the PHP?! here is a link to what I have at the moment: http://www.mypubspace.com/dashnew/index.html thanks Hello, I am a newbie PHP hobbyist. I mess with php strictly for my own amusement. Up until now I have been able to Google my way to a answer to my questions but I'm lost on this one. I'm not really sure what to even search for. I have a few different mysql queries that returns the following arrays. qid15=37,37,37,37,37,37,37,37,37,37,37,38,38,39,39,41 qid17=47,47,47,47,47,48,49,49,49,50,50,50,51,51 qid18=52,52,52,52,52,52,52,52,54,54,55,55,55,56,56,56 qid19=57,57,57,57,58,59,59,61,61 What I would like to do is replace or create a new array for each result with the lowest value as 1 the next lowest as 2 then 3 and 4. My new array would look something like this oldqid15=37,37,37,37,37,37,38,38,39,39,41 newqid15=1,1,1,1,1,1,2,2,3,3,4 I sure would appreciate any ideas on this. I'm thinking there is probably a simple solution and before I waste anymore time I'll stop and ask for directions(as my wife would suggest). hi, i am trying to visualize a table by replacing the fixed values with images. For example, i have a visitor statistics table on mysql. Values on the config_os table are always in three letters. WI7 for Windows7, MAC for Macintosh. I hope I can tell this correctly. I have a display page which retrieves the values from database and displays them website statistics. But in order to make it more cool, i am telling to PHP that When you echo to divtable WI7, replace them with specified Windows7 icon image which has identical name as WI7.gif. Here is the code: Code: [Select] include("conn.php"); $sql="SELECT *, INET_NTOA(location_ip) AS location_ip FROM xx_log_visit AS location_ip ORDER BY idvisit DESC LIMIT 10"; // I am selecting all so you can't see config_os but it is there . I cropped unnecessary code for keeping it easy to read. $result=mysql_query($sql); $numofrows = @mysql_num_rows($result); while($row = mysql_fetch_array($result)) { $system = $row['config_os']; $SysName = array ("AND", "IPH", "LIN", "MAC", "UNK", "W2K", "W95", "W98", "WI7", "WME", "WNT", "WOS", "WS3", "WVI", "WXP"); $SysRename = array ("<img src='images/os/AND.gif'>","<img src='images/os/IPH.gif'>","<img src='images/os/LIN.gif'>","<img src='images/os/MAC.gif'>","<img src='images/os/UNK.gif'>","<img src='images/os/W2K.gif'>","<img src='images/os/W95.gif'>","<img src='images/os/W98.gif'>","<img src='images/os/wi7.gif'>","<img src='images/os/WME.gif'>","<img src='images/os/WNT.gif'>","<img src='images/os/WOS.gif'>","<img src='images/os/WS3.gif'>","<img src='images/os/WVI.gif'>","<img src='images/os/WXP.gif'>"); $showsystem= str_replace($SysName, $SysRename, $system); What I do here is simply use strreplace function. $showsystem = str_replace($SysName, $SysRename, $system); and in the display table, continue from code: Code: [Select] echo (" <div class='sub15'>$showsystem</div> " ); } So for example instead of writing WI7 as visitors os, it shows WI7.gif, cool hmm How can i automate this instead of writing each of them separately? Thanks for any help.. I know you can use str_replace to replace a value with another value, or an array of values with an array of other values. What I'd like to do is replace each instance of a single value with an array of values which get iterated through for each instance found. Think prepared statements that you don't have to call setString or setInt on. Here's a made up example. Code: [Select] $db->query = 'SELECT * FROM users WHERE user_name = ? AND user_role = ?; $db->params = array('hopelessX','admin'); $db->executeQuery(); //this contains a call to a private function that does the replace I have everything else working except this. It works if I specify an array of values to replace and do something like below, but I was hoping to not have to support that method of replace if I didn't need to. Code: [Select] $db->query = 'SELECT * FROM users WHERE user_name = :name AND user_role = :role; $db->replace = array(':name',':role'); $db->params = array('hopelessX','admin'); $db->executeQuery(); //this contains a call to a private function that does the replace I can do it that way if I need to or I could make some overly complicated thing that finds each instance of the question mark, replaces it with a unique value and then adds that unique value to a replace array similarly to the method in code block two but that defeats to the purpose of making this simple database adapter in the first place (although it was mostly just for fun anyway). Anyway, if anyone has any advice and knows of a simple means to achieve this goal that would be much appreciated. Thanks in advance Hi all, hope some can help because this is giving me more grey hairs than I allready have.
I am trying to solve the following: I'm pulling in JSON data, decoding it to a array which I write to a database. However in the array are social security numbers that I don't want to store (privacyregulations). So I need to check if a row has a social security number and if it has one I want to replace it with 'anonymized'. I have got it to work successfully on a local Xampp test environment using the following script (extract off course): //first anonymize the social security number (ssn) if exists $data = json_decode($jsondata, true);
// then fill the tables foreach($data as $row) {
$insertstatement = mysqli_query($link,"INSERT INTO $tablename (personid, type, ssn) VALUES ('".$row["personid"]."', '".$row["type"]."', '".$row["ssn"]."') ON DUPLICATE KEY UPDATE type = VALUES(type), bsn = VALUES(ssn)");
This leads to a filled table where the ssn's are filled with 'anonymized' if they exist in the array and empty if it does not exist for that row. This is exactly what I want ;-).
Personid type ssn
However, when I run the same script on a Lamp production environment (lamp stack on an Azure server) it does not work. Then the scripts results in totally ignoring the whole row that contains a ssn??
Personid type ssn Hope someone can help to get this working on my production environment as well.
Richard
The situation is that I have a large string with some identifiers to say "replace me" with something else. My goal is to replace the values, but if one replacement includes one of the other keys, I don't want to replace it.
For example:
<?php $str = 'some blob ~abc~ followed by ~def~'; $arr_orig = array( '~abc~', '~def~' ); $arr_new = array( 'value~def~', 'blah' ); echo str_replace( $arr_orig, $arr_new, $str ); ?>This will echo: some blob valueblah followed by blah But that's not what I'm trying to accomplish. Basically, I want ~abc~ to be replaced with the literal: value~def~ and for the ~def~ that happens to be part of that string to NOT be replaced. I hope what I'm asking is clear. Basically, preg_replace/str_replace with arrays seems no different than just doing a FOR loop and replacing ~abc~ and then ~def~. But that's not what I need. I'm hoping that if ~abc~ is replaced with text that happens to be another identifier -- ~def~, ~xyz~, whatever -- that this already replaced text is not again replaced. Is there a built-in function to do something like this? If not, should I just parse the whole string and count characters or something? Seems like a pain (and slow!) In witch conditions you need to transfer the data from a select in array and after that to show from array in content of the page ? Is it possible to achieve a similar thing to this... SELECT FROM db WHERE value!=$array My example code is this: $browser_hide = array("1" => "YandexBot 0.0 for unknown"); $query = "SELECT * FROM hitlist_hits WHERE month='$month' AND browser!='$browser_hide' ORDER by id DESC"; Thanks Guys. Hi guyz, please help me I want to get an id from my database, I use a word to search it which is stored as keys of array. But all the keys can't be found in my database, even though it's there. Here some parts of my code Code: [Select] $arrKeys = array_keys($arrResult); foreach($arrKeys as $key) { //if($arrResult[$key]>1) { echo $key/*."=>". $arrResult[$key]*/."<br>"; //$q = mysql_query("select id_katadasar from tb_katadasar where katadasar='".$key."'"); $kon->query("select id_katadasar from tb_katadasar where katadasar='".$key."'"); var_dump($kon->query); //echo "select id_katadasar from tb_katadasar where katadasar='".$key."'"; //$jum = $kon->getJumlah(); //$row = mysql_fetch_array($q, MYSQL_ASSOC) or die(mysql_error() . ''. $q); //echo count($row); if($row = $kon->tampilkan()) //if($row = mysql_fetch_array($q, MYSQL_NUM)) { //$res = $kon->tampilkan(); echo $row[0]; } //else { //echo "tidak ada di db <br><br>"; } } } $kon->query is equal to mysql_query() $kon->tampilkan return $row=mysql_fetch_array(query) Thanks How can I select a value in an array but not its key. nothing gets put into the select list |