Search Results

Search found 15059 results on 603 pages for 'associative array'.

Page 45/603 | < Previous Page | 41 42 43 44 45 46 47 48 49 50 51 52  | Next Page >

  • How to insert array into mysql using PDO and bindParam?

    - by moomoochoo
    I'm using the following code. The code works, but I want to change it so that it uses bindparam try { $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password); $stqid=array(); for ($i=0; $i<$array_count; $i++){ $stqid[$i][0]=$lastInsertValue; $stqid[$i][1]=$qid[$i][0]; $stqid[$i][2]=$qid[$i][1]; } $values = array(); foreach ($stqid as $rowValues) { foreach ($rowValues as $key => $rowValue) { $rowValues[$key] = $rowValues[$key]; } $values[] = "(" . implode(', ', $rowValues) . ")"; } $count = $dbh->exec("INSERT INTO qresults(instance, qid, result) VALUES ".implode (', ', $values)); $dbh = null; } catch(PDOException $e){ echo $e->getMessage(); } I replaced the following $count = $dbh->exec("INSERT INTO qresults(instance, qid, result) VALUES ".implode (', ', $values)); with $sql = "INSERT INTO qresults (instance, qid, result) VALUES (:an_array)"; $stmt = $dbh->prepare($sql); $stmt->bindParam(':an_array', implode(',', $values),PDO::PARAM_STR); $stmt->execute(); but the insert doesn't work anymore (I didn't get any error messages though). QUESTION: What am I doing wrong? How can I rewrite the code to use bindParam?

    Read the article

  • How to loop 3 dimension array using foreach PHP

    - by vzhen
    Below is foreach and the 3 dimension arrays, no problem with the looping but i cannot sepcify which array to echo, they must me the whole arrays like echo $subvalue, any better solutions with looping 3 dimension array? i actually feel weird with this looping. Thanks in adv foreach ($stories as $key => $story){ //echo "<br />"; foreach($story as $subkey => $subvalue){ echo $subvalue."<br />"; foreach($subvalue as $key => $subsubvalue){ echo $subsubvalue."<br />"; } } } Array ( [270] => Array ( [uid] => 36 [user_email] => [email protected] [sid] => 270 [story_name] => Story C [photo_url] => Array ( [0] => story_photos/2012/0322/361332381418153311.jpg [1] => story_photos/2012/0322/361332393792911587.jpg ) [photo_added_date] => Array ( [0] => 1332381418 [1] => 1332393792 ) ) [269] => Array ( [uid] => 36 [user_email] => [email protected] [sid] => 269 [story_name] => Story B [photo_url] => Array ( [0] => story_photos/2012/0322/361332381406580761.jpg ) [photo_added_date] => Array ( [0] => 1332381406 ) ) [268] => Array ( [uid] => 36 [user_email] => [email protected] [sid] => 268 [story_name] => Story A [photo_url] => Array ( [0] => story_photos/2012/0322/361332381393552719.jpg ) [photo_added_date] => Array ( [0] => 1332381393 ) ) )

    Read the article

  • PHP Array problems....if anyone can assist!

    - by Homer_J
    First off, the code which brings back my data into an array: function fetch_questions($page) { global $link; $proc = mysqli_prepare($link, "SELECT * FROM tques WHERE page = $page"); mysqli_stmt_bind_param($proc, "i", $page); mysqli_stmt_execute($proc); $rowq = array(); stmt_bind_assoc($proc, $rowq); // loop through all result rows while ($proc->fetch()) { // print_r($rowq); } mysqli_stmt_close($proc); mysqli_clean_connection($link); return($rowq); } Now, when I `print_r($rowq);' I get the following, which is all good: Array ( [questions] => q1 [qnum] => 1 [qtext] => I find my job meaningful [page] => 1 ) Array ( [questions] => q2 [qnum] => 2 [qtext] => I find my job interesting [page] => 1 ) Array ( [questions] => q3 [qnum] => 3 [qtext] => My work supports ABC's objective [page] => 1 ) Array ( [questions] => q4 [qnum] => 4 [qtext] => I am able to balance my work and home life [page] => 1 ) Array ( [questions] => q5 [qnum] => 5 [qtext] => I am clear about what is expected of me in my job [page] => 1 ) Array ( [questions] => q6 [qnum] => 6 [qtext] => My induction helped me to settle into my job [page] => 1 ) Array ( [questions] => q7 [qnum] => 7 [qtext] => I understand the ABC vision [page] => 1 ) Array ( [questions] => q8 [qnum] => 8 [qtext] => I know how what I do fits into my team's objectives [page] => 1 ) Now, in my php page I have the following piece of script: $questions = fetch_questions($page); And when I print_r $questions, as below: print_r($questions); I only get the following back from the array, 1 row: Array ( [questions] => q8 [qnum] => 8 [qtext] => I know how what I do fits into my team's objectives [page] => 1 ) Any ideas why that might be? Thanks in advance, Homer.

    Read the article

  • how to display a array value in view page

    - by udaya
    Hai I am using codeigniter...I my function phpcalview()... This is my function function phpcalview() { $year = $this->input->post('yearvv'); $data['year'] = $this->adminmodel->selectyear(); $data['date'] = $this->adminmodel->selectmonth(); print_r($data['date'] ); $this->load->view('phpcal',$data); } I am printing the values with print_r($data['date'] ); I get values like Array ( [0] => Array ( [dbdatenum] => 1 ) [1] => Array ( [dbdatenum] => 2 ) [2] => Array ( [dbdatenum] => 3 ) [3] => Array ( [dbdatenum] => 4 )) I want to display the array seperately as array[0],array[1] in my view page how can i do that

    Read the article

  • php foreach looping twice

    - by Jack
    Hi, I am trying to loop through some data from my database but it is outputting it twice. $fields = 'field1, field2, field3, field4'; $idFields = 'id_field1, id_field2, id_field3, id_field4'; $tables = 'table1, table2, table3, table4'; $table = explode(', ', $tables); $field = explode(', ', $fields); $id = explode(', ', $idFields); $str = 'Egg'; $i=1; while ($i<4) { $f = $field[$i]; $idd = $id[$i]; $sql = $writeConn->select()->from($table[$i], array($f, $idd))->where($f . " LIKE ?", '%' . $str . '%'); $string = '<a title="' . $str . '" href="' . $currentProductUrl . '">' . $str . '</a>'; $result = $writeConn->fetchAssoc($sql); foreach ($result as $row) { echo 'Success! Found ' . $str . ' in ' . $f . '. ID: ' . $row[$idd] . '.<br>'; } $i++; } Outputting: Success! Found Egg in field3. ID: 5. Success! Found Egg in field3. ID: 5. Could someone please explain why it is looping through both the indexed and associative values? UPDATE I did some more playing around and tried the following. $fields = 'field1, field2, field3, field4'; $idFields = 'id_field1, id_field2, id_field3, id_field4'; $tables = 'table1, table2, table3, table4'; $table = explode(', ', $tables); $field = explode(', ', $fields); $id = explode(', ', $idFields); $str = 'Egg'; $i=1; while ($i<4) { $f = $field[$i]; $idd = $id[$i]; $sql = $writeConn->select()->from($table[$i], array($f, $idd))->where($f . " LIKE ?", '%' . $str . '%'); $string = '<a title="' . $str . '" href="' . $currentProductUrl . '">' . $str . '</a>'; $sth = $writeConn->prepare($sql); $sth->execute(); $result = $sth->fetch(PDO::FETCH_ASSOC); foreach ($result as $row) { echo 'Success! Found ' . $str . ' in ' . $f . '. ID: ' . $row[$idd] . '.<br>'; } $i++; } The interesting thing is that this outputs the below: Success! Found Egg in field3. ID: E. Success! Found Egg in field3. ID: E. Success! Found Egg in field3. ID: 5. Success! Found Egg in field3. ID: 5. Success! Found Egg in field3. ID: E. Success! Found Egg in field3. ID: E. Success! Found Egg in field3. ID: 5. Success! Found Egg in field3. ID: 5. I have also tried adding $i to the output and this outputs 2 as expected. If I change fetch(PDO::FETCH_BOTH) to fetch(PDO::FETCH_ASSOC) the output is as follows: Success! Found Egg in field3. ID: E. Success! Found Egg in field3. ID: E. Success! Found Egg in field3. ID: 5. Success! Found Egg in field3. ID: 5. This has been bugging me for too long, so if anyone could help I would be very appreciative!

    Read the article

  • numpy array mapping and take average

    - by user566653
    Dear all, I have three array value = np.array ([1, 3, 3, 5, 5, 7, 3]) index = np.array ([1, 1, 3, 3, 6, 6, 6]) data = np.array ([1, 2, 3, 4, 5, 6]) and want to take average for item of "value" by array "index", and assign a new array with value of "data", such as [2, nan, 4, nan, nan, 5] first value is the average of 1st and 2nd of "value" second value is nan because there is not any key in "index" third value is the average of 3rd and 4th of "value" ... Thanks for your help!!! Regards, Roy

    Read the article

  • comparing multidimensional array

    - by John K
    Hello everyone, I have the following array: Array ( [0] => Array ( [0] => 87 [1] => 55 [2] => 85 [3] => 86 ) [1] => Array ( [0] => 58 [1] => 84 ) [2] => Array ( [0] => 58 ) ) This array above is an example. The actual array is of variable size, but structured like this. Basically, I'd like to run array_intersect on each second level array and grab the value (number) that is common between them. In this case, it would be 58. I'm not quite sure where to start on this. Any advice?

    Read the article

  • PHP Pass Dynamic Array name to function

    - by Brad
    How do I pass an array key to a function to pull up the right key's data? // The array <?php $var['TEST1'] = Array ( 'Description' => 'This is a Description', 'Version' => '1.11', 'fields' => Array( 'ID' => array( 'type' => 'int', 'length' =>'11', 'misc' =>'auto_increment' ), 'DATA' => array( 'type' => 'varchar', ' length' => '255' ) ); $var['TEST2'] = Array ( 'Description' =? 'This is the 2nd Description', 'Version' => '2.1', 'fields' => Array( 'ID' => array( 'type' => 'int', 'length' =>'11', 'misc' =>'auto_increment' ), 'DATA' => array( 'type' => 'varchar', ' length' => '255' ) ) // The function <?php $obj = 'TEST1'; print_r($schema[$obj]); // <-- Fives me output. But calling the function doesn't. echo buildStructure($obj); /** * @TODO to add auto_inc support */ function buildStructure($obj) { $output = ''; $primaryKey = $schema["{$obj}"]['primary key']; foreach ($schema["{$obj}"]['fields'] as $name => $tag) // #### ERROR #### Invalid argument supplied for foreach() { $type = $tag['type']; $length = $tag['length']; $default = $tag['default']; $description = $tag['description']; $length = (isset($length)) ? "({$length})" : ''; $default = ($default == NULL ) ? "NULL" : $default; $output .= "`{$name}` {$type}{$length} DEFAULT {$default} COMMENT `{$DESCRIPTION}`, "; } return $output; }

    Read the article

  • Access to bytes array of a Bitmap

    - by Deulis
    1- In Windows CE, I have a Bitmap object in C#. 2- I have a C function in an extern dll that expects as parameters the pointer to a bytes array that represents an image in RGB565 format, width and height. This function will draw on this array of bytes. So I need to pass the byte array pointer of the Bitmap object, but I can find a practical way to get this pointer. One way is convert this Bitmap into a bytes array using a memory stream or something else, but it will create a new bytes array, so I will keep in memory both object, the Bitmap and the bytes array, but I don’t want it because the few available memory, that’s why I need to access to the bytes array of the bitmap object, not create a new bytes array. Anyone can help me?

    Read the article

  • Array Related Doubt.......

    - by AGeek
    I have the following program........... int insert(int *array, int arraySize, int newElement) { array[arraySize + 1] = newElement; return (arraySize+1); // Return new Array size...... } int main() { int array[] = {1,2,3,4,5}; int arraySize = sizeof(array) / sizeof(int); insertInArray(array, arraySize,6); print(array); } I am trying to work out this program in C programming language... But when i print the array after insertion,,, it doesn't prints the desired output which is needed.. Please correct me if i am doing something wrong..... Thanks..

    Read the article

  • Parsing array data

    - by Sam
    I am trying to parse this array data that way generated from JQuery and JSON. Array ( [d] = Array ( [0] = Array ( [order] = 1 ) [1] => Array ( [order] => 2 ) [2] => Array ( [order] => 3 ) [3] => Array ( [order] => 4 ) [4] => Array ( [order] => 5 ) ) ) I am trying to save the above date into a mysql table, but cannot seem to parse the data properly to be inserted into the database. Can anyone help?

    Read the article

  • how to get key value of array with curl (php)

    - by Vierri
    Hello I want to make use of an API but it print alot of info and i don't know how i can get a few key values of the array. <?php $query = "SELECT * FROM kvk WHERE adres='Wit-geellaan 158'"; $host = "http://api.openkvk.nl/php/"; $url = $host ."/". rawurlencode($query); $curl = curl_init(); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_exec($curl); curl_close($curl); ?> Is my php script and it shows array(array("RESULT"=>array("TYPES"=>array("int","bigint","varchar","varchar","varchar","varchar","varchar","int","int","smallint","smallint","int"),"HEADER"=>array("id","kvk","bedrijfsnaam","adres","postcode","plaats","type","kvks","sub","bedrijfsnaam_size","adres_size","verhuisd"),"ROWS"=>array(array("1303095","271242250000","Schoonmaakbedrijf Regio","Wit-geellaan 158","2718CK","Zoetermeer","Hoofdvestiging","27124225","0","23","16","0"))))) Thanks in advance Greetings, Vierri

    Read the article

  • populating on the basis of array elements in php

    - by Avinash
    This is my code. if(in_array("1", $mod)){ $res=array('First Name','Insertion','Last Name','Lead Country');} if(in_array("2", $mod)){ $res=array('Landline No:','Mobile No:','Lead Country');} if(in_array("3", $mod)){ $res=array('City','State','Country','Lead Country');} if(in_array("4", $mod)){ $res=array('Email','Lead Country');} return $res; Upto this it works fine. But if the array contains more than one value say (1,3) I need to return both results of 1 and 3. eg: if the array is like this array([0]=>1 [1]=>3) then $res=array('First Name','Insertion','Last Name','City','State','Country','Lead Country') But if there are 2 lead country only one should be displayed how to do this? Pls help me.

    Read the article

  • c++ delete[] and array of objects

    - by osgx
    Hello I have allocated and array of Objects Objects *array = new Objects[N]; How should I delete this array? Just delete[] array; or with iterating over array's elements? for(int i=0;i<N;i++) delete array[i]; delete[]; Thanks

    Read the article

  • How to find the Biggest and smallest in Int[] Array using c#

    - by karthik
    If the array is as follows, int[] array = new int[] { 7, 4, 1, 8 }; I want to find the Biggest, smallest, second smallest, second biggest If the array is as follows, int[] array = new int[] { 7, 4, 1 }; I want to find the Biggest, smallest, second smallest If the array is as follows, int[] array = new int[] { 7, 4 }; I want to find the Biggest, smallest How can i achieve this programmaticly.

    Read the article

  • How to detect a sign change for elements in a numpy array

    - by cb160
    I have a numpy array with positive and negative values in. a = array([1,1,-1,-2,-3,4,5]) I want to create another array which contains a value at each index where a sign change occurs (For example, if the current element is positive and the previous element is negative and vice versa). For the array above, I would expect to get the following result array([0,0,1,0,0,1,0]) Alternatively, a list of the positions in the array where the sign changes occur or list of booleans instead of 0's and 1's is fine.

    Read the article

  • PHP: Remove the first and last item of the array

    - by phpBOY
    Hi, Suppose I have this array: $array = array('10', '20', '30.30', '40', '50'); Questions What is the fastest/easiest way to remove the first item from the above array? What is the fastest/easiest way to remove the last item from the above array? So the resulting array contains only these values: '20' '30.30' '40'

    Read the article

  • Correct way to clear/release an array of arrays

    - by iFloh
    And again my array of arrays .... When I have an array "x" that contains multiple instances of an array "y", how do I clear/release it without risking memory leaks? are the following calls sufficient? (a) clearing the array [x removeAllObjects]; (b) releasing the array [x release]; or do I need to enumerate the array, such as: (c) clearing the array for(int i=0;i<x.count;i++) [[x objectAtIndex:i] release]; [x removeAllObjects]; (d) releasing the array for(int i=0;i<x.count;i++) [[x objectAtIndex:i] release]; [x release]; thanks in advance

    Read the article

  • Printing distinct integers in an array

    - by ???
    I'm trying to write a small program that prints out distinct numbers in an array. For example if a user enters 1,1,3,5,7,4,3 the program will only print out 1,3,5,7,4. I'm getting an error on the else if line in the function checkDuplicate. Here's my code so far: import javax.swing.JOptionPane; public static void main(String[] args) { int[] array = new int[10]; for (int i=0; i<array.length;i++) { array[i] = Integer.parseInt(JOptionPane.showInputDialog("Please enter" + "an integer:")); } checkDuplicate (array); } public static int checkDuplicate(int array []) { for (int i = 0; i < array.length; i++) { boolean found = false; for (int j = 0; j < i; j++) if (array[i] == array[j]) { found = true; break; } if (!found) System.out.println(array[i]); } return 1; } }

    Read the article

  • ordering array keys?

    - by fayer
    i want to create an array with 2 keys and i want them in following order: $array['higher']; $array['escalate']; how could i accomplish this without creating any value. i want to add values to the array with later on... $array['higher'][] = 'some_value'; $array['escalate'][] = 'some_value'; ...but first i need to create the keys in that order. thanks in advance!

    Read the article

  • Populating a color array with every 8th pixel in an image. C#

    - by Piper
    I have an image that is 512x280 pixels. I want to populate a 64x35 array with every 8th pixel in the matrix. Here is what I have right now: Color[,] imgArray = new Color[b.Width, b.Height]; for (int y = 0; y < 35; y++) { for (int x = 0; x < 64; x++) { imgArray[x, y] = b.GetPixel(x, y); } } But that will get just the top corner of the image. How would I change the loop so it grabs every 8th pixel to fill the array with? edit: I think I may have gotten it. Can someone read this and assure me that it is correct? Color[,] imgArray = new Color[64, 35]; for (int y = 0; y < 280; y+=8) { for (int x = 0; x < 512; x+=8) { imgArray[x, y] = b.GetPixel(x, y); } }

    Read the article

  • What does it mean when you try to print an array or hash using Perl and you get, Array(0xd3888)?

    - by Luke
    What does it mean when you try to print an array or hash and you see the following; Array(0xd3888) or HASH(0xd3978)? EXAMPLE CODE my @data = ( ['1_TEST','1_T','1_TESTER'], ['2_TEST','2_T','2_TESTER'], ['3_TEST','3_T','3_TESTER'], ['4_TEST','4_T','4_TESTER'], ['5_TEST','5_T','5_TESTER'], ['6_TEST','6_T','^_TESTER'] ); foreach my $line (@data) { chomp($line); @random = split(/\|/,$line); print "".$random[0]."".$random[1]."".$random[2]."","\n"; } RESULT ARRAY(0xc1864) ARRAY(0xd384c) ARRAY(0xd3894) ARRAY(0xd38d0) ARRAY(0xd390c) ARRAY(0xd3948)

    Read the article

  • Extracting array with set::class utility

    - by Sabourinov
    Is there a way to extract the array for a specified id with the set::class utiliy? I can't figure out the XPath. I.E. I would like to extract the array where the id = 1 [Document] = Array ( [0] = Array ( [id] = 1 [filename] = 1.txt ) [1] = Array ( [id] = 2 [filename] = 2.txt ) [2] = Array ( [id] = 3 [filename] = 3.txt ) )

    Read the article

< Previous Page | 41 42 43 44 45 46 47 48 49 50 51 52  | Next Page >