Search Results

Search found 42698 results on 1708 pages for 'php in array'.

Page 97/1708 | < Previous Page | 93 94 95 96 97 98 99 100 101 102 103 104  | Next Page >

  • Writing/Reading struct w/ dynamic array through pipe in C

    - by anrui
    I have a struct with a dynamic array inside of it: struct mystruct{ int count; int *arr; }mystruct_t; and I want to pass this struct down a pipe in C and around a ring of processes. When I alter the value of count in each process, it is changed correctly. My problem is with the dynamic array. I am allocating the array as such: mystruct_t x; x.arr = malloc( howManyItemsDoINeedToStore * sizeof( int ) ); Each process should read from the pipe, do something to that array, and then write it to another pipe. The ring is set up correctly; there's no problem there. My problem is that all of the processes, except the first one, are not getting a correct copy of the array. I initialize all of the values to, say, 10 in the first process; however, they all show up as 0 in the subsequent ones. for( j = 0; j < howManyItemsDoINeedToStore; j++ ){ x.arr[j] = 10; } Initally: 10 10 10 10 10 After Proc 1: 9 10 10 10 15 After Proc 2: 0 0 0 0 0 After Proc 3: 0 0 0 0 0 After Proc 4: 0 0 0 0 0 After Proc 5: 0 0 0 0 0 After Proc 1: 9 10 10 10 15 After Proc 2: 0 0 0 0 0 After Proc 3: 0 0 0 0 0 After Proc 4: 0 0 0 0 0 After Proc 5: 0 0 0 0 0 Now, if I alter my code to, say, struct mystruct{ int count; int arr[10]; }mystruct_t; everything is passed correctly down the pipe, no problem. I am using READ and WRITE, in C: write( STDOUT_FILENO, &x, sizeof( mystruct_t ) ); read( STDIN_FILENO, &x, sizeof( mystruct_t ) ); Any help would be appreciated. Thanks in advance!

    Read the article

  • Create an grid array...

    - by Anicho
    Okay so I am looking to create a grided array in OGRE3D game engine but the array is generic my array skills are pretty basic and need work so I am posting this just to be sure I am doing this correctly. #define GRIDWIDTH 10 #define GRIDHEIGHT 10 int myGrid [HEIGHT][WIDTH]; int n,m; int main () { for (n=0;n<HEIGHT;n++) for (m=0;m<WIDTH;m++) { jimmy[n][m]=(n+1)*(m+1); } return 0; } I am assuming the above will return: 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 Then I can assign each point in the array to a valid node in OGRE3D to create a grid in 3D view would this work? Just need to tell me if I am doing it right or wrong dont need the ogre3d code....

    Read the article

  • How to minify JS in PHP easily...Or something else

    - by RickyAYoder
    I've done some looking around, but I'm still confused a bit. I tried Crockford's JSMin, but Win XP can't unzip the executable file for some reason. What I really want though is a simple and easy-to-use JS minifier that uses PHP to minify JS code--and return the result. The reason why is because: I have 2 files (for example) that I'm working between: scripts.js and scripts_template.js scripts_template is normal code that I write out--then I have to minify it and paste the minified script into scripts.js--the one that I actually USE on my website. I want to eradicate the middle man by simply doing something like this on my page: <script type="text/javascript" src="scripts.php"></script> And then for the contents of scripts.php: <?php include("include.inc"); header("Content-type:text/javascript"); echo(minify_js(file_get_contents("scripts_template.js"))); This way, whenever I update my JS, I don't have to constantly go to a website to minify it and re-paste it into scripts.js--everything is automatically updated. Yes, I have also tried Crockford's PHP Minifier and I've taken a look at PHP Speedy, but I don't understand PHP classes just yet...Is there anything out there that a monkey could understand, maybe something with RegExp? How about we make this even simpler? I just want to remove tab spaces--I still want my code to be readable. It's not like the script makes my site lag epically, it's just anything is better than nothing. Tab removal, anyone? And if possible, how about removing completely BLANK lines?

    Read the article

  • Showing an array of certain pages with WP_Query in Wordpress

    - by Ragnar
    What I'm trying to achieve is showing only certain pages in a loop. 3 certain pages, not more, not less. I've tried many things but I just can't complete it. <?php $special_tabs = new WP_Query(array('post_type' => 'page', 'post_in' => array(100,102,104))); ?> What this does, from what I understand, is that it shows an array of pages and then includes those ID's there as well. <?php $special_tabs = new WP_Query(array ('page_id' => 100)); ?> And this shows only ONE certain page, it doesn't support the showing of array of different IDs. I'm sure I am not the first person to have such specific needs and I'm certain there is a relatively simple way to achieve what I'm trying to achieve, but I just can't come up with a solution or to find one. Can anybody please help me with this? Many thanks in advance!

    Read the article

  • php mysql parallel array checkboxes

    - by gramware
    I have an array of checkboxes that I edit at once to set up a 'tinyint' field. the problem comes in when i uncheck the checkbox and post the vales to mysql. since it posts an array of checkboxes and another parallel array of values to edit, unchecking a checkbox results in the 0 value been ignored by PHP_POST and hence the checkbox array will be less by the number of unchecked values in the form while the array to be edited will have all the records in the form. here is the submit code while($row=mysql_fetch_array($result)) { $checked = ($row[active]==1) ? 'checked="checked"' : ''; ... echo "<input type='hidden' name='TrID[]' value='$TrID'>"; echo "<input type='checkbox' name='active1[]' value='$row[active]''$checked' >"; ... and the processing php script $userid = ($_POST['TrID']); $checked= ($_POST['active']); $i=0; foreach ($userid as $usid) { if ($checked[$i]==1){ $check = 1; } else{ $check = 0; } $qry1 ="UPDATE `epapers`.`clientelle` SET `active` = '$check' WHERE `clientelle`.`user_id` = '$usid' "; $result = mysql_query($qry1); $i++; }

    Read the article

  • Unexpected $end in PHP file

    - by mattbd
    I'm working on a PHP contact form, but I can't get it to work. I get the following error in the Apache server log, running on an Ubuntu Server VM: PHP Parse error: syntax error, unexpected $end in /home/matthew/Sites/contactFormResponse.php on line 75, referer: http://192.168.1.4/contactForm.php From googling this error, it sounds like it's normally caused by either using the short PHP tag when the server's not set up to recognise them, or by having a block of code that isn't closed correctly. But as far as I can see that isn't the case here - as far as I can see it's all closed correctly. Here's the PHP code: <?php error_reporting(E_ALL); // Define variables to hold the name, email address and message, and import the information into the variables $name = $_POST['NameInput']; $email = $_POST['EmailAddress']; $telno = $_POST['ContactNumber']; $querytype = $_POST['QueryType']; $bookingstartdate = $_POST['BookingStartDay'] . $_POST['BookingStartMonth'] . $_POST['BookingStartYear']; $bookingenddate = $_POST['BookingEndDay'] . $_POST['BookingEndMonth'] . $_POST['BookingEndYear']; $message = $_POST['QueryText']; // Validate the inputs - send it if it's OK if(3 < strlen($name) && 3 < strlen($email)) { $email_message = <<< EMAIL Message from contact form at holidaychalet.co.uk Name: $name Email: $email Contact Number: $telno Query Type: $querytype Booking Start Date: $bookingstartdate Booking End Date: $bookingenddate The message: $message EMAIL; $headers = "cc:[email protected]\r\n"; if(mail('matthew@localhost','Contact form email', $email_message, $headers)) { echo "Thanks for completing the form! I'll be in touch shortly!"; } else { echo "Something went wrong - please use the back button and try again"; } } else { echo "You didn't complete the form fully enough! Please use go back using your web browser's back button"; } ?>

    Read the article

  • Exploding by Array of Delimiters

    - by JoeC
    Is there any way to explode() using an array of delimiters? PHP Manual: array explode ( string $delimiter , string $string [, int $limit ] ) Instead of using string $delimiter is there any way to use array $delimiter without affecting performance too much?

    Read the article

  • PHP: Next Available Value in an Array, starting with a non-indexed value

    - by Erik Smith
    I've been stumped on this PHP issue for about a day now. Basically, we have an array of hours formatted in 24-hour format, and an arbitrary value ($hour) (also a 24-hour). The problem is, we need to take $hour, and get the next available value in the array, starting with the value that immediately proceeds $hour. The array might look something like: $goodHours = array('8,9,10,11,12,19,20,21). Then the hour value might be: $hour = 14; So, we need some way to know that 19 is the next best time. Additionally, we might also need to get the second, third, or fourth (etc) available value. The issue seems to be that because 14 isn't a value in the array, there is not index to reference that would let us increment to the next value. To make things simpler, I've taken $goodHours and repeated the values several times just so I don't have to deal with going back to the start (maybe not the best way to do it, but a quick fix). I have a feeling this is something simple I'm missing, but I would be so appreciative if anyone could shed some light. Erik

    Read the article

  • MPI datatype for 2 d array

    - by dks
    I need to pass an array of integer arrays (basically a 2 d array )to all the processors from root.I am using MPI in C programs. How to declare MPI datatype for 2 d array.and how to send the message (should i use broadcast or scatter)

    Read the article

  • Plist array , cannot change dictonaries inside

    - by Andy Jacobs
    i have a plist that's at its root an array with dictonaries inside it. i load a plist from my recourses as an NSMutableArray. [NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Filters" ofType:@"plist"]] i store it into nsuserdefault because it has to be persistent between startups. [[NSUserDefaults standardUserDefaults] setObject:array forKey:@"filters"]; but i can't change the dictonaries in the array because they are not mutable. how can i make them mutable?

    Read the article

  • PHP: Filling in the 'gaps' in an array

    - by aboved
    Hey gurus, I've got a php array (obtained through checkbox values in a form - as you know checkboxes only show up in the _POST variable when they are not set). Array ( [2] => 0,2 [3] => 0,3 ) I need a way to 'fill in' the gaps between the range 0-5. So above would look like (filling the empty spaces with '-1'. I tried array_merge() with an array filled with '-1' but that didn't work. Array ( [0] => -1 [2] => 0,2 [3] => 0,3 [4] => -1 [5] => -1 ) I think I may have gone down the wrong road with the problem I am trying to solve, but I have put too much time into this solution to back out - a feeling I am sure most of you are familiar with(!) Cheers!

    Read the article

  • php sessions in database only writing part of information to the table...

    - by Ronedog
    I'm having difficulty figuring out what's going on here, hoping some one can help me out. I have been using php, mysql storing my session information in the database. The app is only running on localhost, vista. In the php.ini file I commented out the "session.save_handler = files" line and am using a php class to handle the session writes/reads, etc. My login process is this: Submit login credentials via login.php. login.php calls loginprocess.php. loginprocess.php verifies user, and if valid starts a new session and adds data to the session vars, then it redirects to index.php. Here's the problem. the loginprocess.php page has a bunch of session vars that get set like $_SESSION['account_id'] = $account_id; etc. but when I go to index.php and do a var_dump($_SESSION) it just says "array() empty". However, if I do a var_dump($_SESSION) in loginprocess.php, just before the redirection line header("Location: ../index.php"); then it shows all the data in the session variable. If I look in the database where the session information is stored, there is data in the session_id field, created_ts field, and expires field, but the session_data field has nothing inside of it and in the past this is the field where all my session data was stored. How could I be able to var_dump the session in loginprocess.php, but the data not exist in the db table, is it using some kind of caching? I cleared my cookies, etc...but no change. Why is the session_id, being written to the table, but the actual session data is not? Any ideas are appreciated. Thanks.

    Read the article

  • Capture String from Array, C#

    - by Dan Snyder
    I'm trying to figure out how to get a string from an array starting at some given position. Say we have an array that's arbitrarily long and my string starts at location 1000. If I wanted to get a string from a file I would simply use something like getc or scanf or something. How do I carry out these same functions on an array instead of a file? *oh, keep in mind that the array is of type int and is full of numerical representations of ASCII characters.

    Read the article

  • How to add SQL elements to an array in PHP

    - by DanLeaningphp
    So this question is probably pretty basic. I am wanting to create an array from selected elements from a SQL table. I am currently using: $rcount = mysql_num_rows($result); for ($j = 0; $j <= $rcount; $j++) { $row = mysql_fetch_row($result); $patients = array($row[0] => $row[2]); } I would like this to return an array like this: $patients = (bob=>1, sam=>2, john=>3, etc...) Unfortunately, in its current form, this code is either copying nothing to the array or only copying the last element.

    Read the article

  • specifying multiple URLs with cURL/PHP using square brackets

    - by Raj Gundu
    I have a large array of URLS similar to this: $nodes = array( 'http://www.example.com/product.php?page=1&sortOn=sellprice', 'http://www.example.com/product.php?page=2&sortOn=sellprice', 'http://www.example.com/product.php?page=3&sortOn=sellprice' ); The cURL manual states here (http://curl.haxx.se/docs/manpage.html) that i can use square brackets '[]' to specify multiple urls. Used in the above example this would be similar to this: 'http://www.example.com/product.php?page=[1-3]&sortOn=sellprice' So far i have been unable to reference this correctly. This is the complete code segment I'm currently trying to utilize this with: $nodes = array( 'http://www.example.com/product.php?page=1&sortOn=sellprice', 'http://www.example.com/product.php?page=2&sortOn=sellprice', 'http://www.example.com/product.php?page=3&sortOn=sellprice' ); $node_count = count($nodes); $curl_arr = array(); $master = curl_multi_init(); for($i = 0; $i < $node_count; $i++) { $url =$nodes[$i]; $curl_arr[$i] = curl_init($url); curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, true); curl_multi_add_handle($master, $curl_arr[$i]); } do { curl_multi_exec($master,$running); } while($running > 0); echo "results: "; for($i = 0; $i < $node_count; $i++) { $results = curl_multi_getcontent ( $curl_arr[$i] ); echo( $i . "\n" . $results . "\n"); echo 'done'; I can't seem to find any more documentation on this. Thanks in advance.

    Read the article

  • regular expression for indian vehicle number in javascript and php

    - by I Like PHP
    i need regular expression in java script as well as in PHP for Indian vehicle NUMBER here are conditions list let expression is (x)(y)(z)(m)(a)(b)(c) 1. (x) contains only alphabets of length 2. 2. (y) may be - or single space ' ' 3. (z) contains only numbers of length 2 4. (m) may be or , or single space ' ' 5. length of (a) can be 2 or 3. contains alphanumeric value with minimum one alphabetic character. 6. (b) may be - or single space ' ' ( similar to (y) ) 7. (c) contains only numbers of length 4 i show you the various examples of vehicle number valid number RJ-14,NL-1234 RJ-01,4M-5874 RJ-07,14M-2345 RJ 07,3M 2345 RJ-07,3M-8888 RJ 07 4M 2345 RJ 07,4M 2933 invalid number RJ-07 3M 1234 ( both (y) and (b) should be same). RJ-07 M3-1234 ((a) must ends with alphabat). rj-07 M3-123 ( length of (c) must be 4).

    Read the article

  • programmatically creating property list from json to include an array

    - by Michael Robinson
    [{"memberid":"18", "useridFK":"30", "loginName":"Johnson", "name":"Frank", "age":"23", "place":"School", },] Someone else posted a similar question but without the fact that it was coming from a JSON deserialization. Quinn had some suggestions but it was confused about where to place/replace the following code (if it's correct): NSDictionary *item1 = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@" member",[NSNumber numberWithInt:3],nil] forKeys:[NSArray arrayWithObjects:@"Title",@"View",nil]]; into this: NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding]; NSError *error = nil; NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error]; if (dict) { rowsArray = [dict objectForKey:@"member"]; [rowsArray retain]; } My Array.plist needs to look like the following: Root: Dictionary V Rows: Array V Item 0: Dictionary Title: String 18 V Children Array V Item 0 Dictionary Title String 30 etc. Thanks in advance. Every tutorial on JSON only shows a simple array being returned, never a 2-D..It's driving me crazy trying to figure this out.

    Read the article

  • Insert array to mysql database php

    - by ganjan
    Hi. I want to add an array to my db. I have set up a function that checks if a value in the db (ex. health and money) has changed. If the value is diffrent from the original I add the new value to the $db array. Like this $db['money'] = $money_input + $money_db;. function modify_user_info($conn, $money_input, $health_input){ (...) if ($result = $conn->query($query)) { while ($user = $result->fetch_assoc()) { $money_db = $user["money"]; $health_db = $user["health"]; } $result->close(); //lag array til db med kolonnene som skal fylles ut som keys i array if ($user["money"] != $money_input){ $db['money'] = $money_input + $money_db; //0 - 20 if (!preg_match("/^[[0-9]{0,20}$/i", $db['money'])){ echo "error"; return false; } } if ($user["health"] != $health_input){ $db['health'] = $health_input + $health_db; //0 - 4 if (!preg_match("/^[[0-9]{0,4}$/i", $db['health'])){ echo "error"; return false; } if (($db['health'] < 1) or ($db['health'] > 1000)) { echo "error"; return false; } } The keys in $db represent colums in my database. Now I want to make a function that takes the keys in the array $db and insert them in the db. Something like this ? $query = "INSERT INTO `main_log` ( `id` , "; foreach(range(0, x) as $num) { $query .= array_key.", "; } $query = substr($query, 0, -3); $query .= " VALUES ('', "; foreach(range(0, x) as $num) { $query .= array_value.", "; } $query = substr($query, 0, -3); $query .= ")";

    Read the article

  • Pass 2d array to function in C?

    - by Evelyn
    I know it's simple, but I can't seem to make this work. My function is like so: int GefMain(int array[][5]) { //do stuff return 1; } In my main: int GefMain(int array[][5]); int main(void) { int array[1800][5]; GefMain(array); return 0; } I referred to this helpful resource, but I am still getting the error "warning: passing argument 1 of GefMain from incompatible pointer type." What am I doing wrong?

    Read the article

  • Get the index value of an array in php

    - by Aakash Chakravarthy
    Hello, I have array $list = array('string1', 'string2', 'string3'); Now i want to get the index of the value string2 i.e 1 and 2 for string3 All i want is the position of the strings in the array string1 in 0 string2 in 1 string3 in 2 positions How to get this ? i used array_search but it is no use ! please help !

    Read the article

  • Sorting 2D array of chars C++

    - by user69514
    I have a 2d array of chars where in each row I store a name... such as this: J O H N P E T E R S T E P H E N A R N O L D J A C K How should I go about sorting the array so that I end up with A R N O L D J A C K J O H N P E T E R S T E P H E N These is a 2d array of chars..... no strings or char points.....

    Read the article

  • Need Associated ID Added to a While Loop (php)

    - by user319361
    Been trying to get my head around while loops for the last few days but the code seems very inefficient for what Im trying to achieve. I'm assuming I'm overcomplicating this though nothing I've tried seems to work. Each topic in my forum can have related topic IDs stored in a seperate table. A post ID is also stored in this table, as that specific post references why they are considered related. DB Table contains only: topic_id, related_id, post_id // Get related IDs and post IDs for current topic being viewed $result = $db->query('SELECT related_id, post_id FROM related_topics WHERE topic_id='.$id.''); // If related topics found, put both of the IDs into arrays if ($db->num_rows($result)) { while($cur_related = mysql_fetch_array($result)){ $reltopicarray[] = $cur_related['related_id']; $relpost[] = $cur_related['post_id']; } // If the first array isnt empty, get some additional info about each related ID from another table if(!empty($reltopicarray)) { $pieces = $reltopicarray; $glued = "\"".implode('", "', $pieces)."\""; $fetchtopics = $db->query('SELECT id, subject, author, image, etc FROM topics WHERE id IN('.$glued.')'); } // Print each related topic while($related = mysql_fetch_array($fetchtopics)){ ?> <a href="view.php?id=<?php echo $related['id']; ?>"><?php echo $related['subject']; ?></a> by <?php echo $related['author']; ?> // Id like to show the Post ID below (from the array in the first while loop) // The below link doesnt work as Im outside the while loop by this point. <br /><a href="view.php?post_id=<?php echo $cur_related['post_id']; ?>">View Relationship</a> <?php } ?> The above currently works, however I'm trying to also display the post_id link below each related topic link, as shown above. Would be greatful if someone can lend a hand. Thanks :)

    Read the article

  • Display `pretty output` of directory content from array

    - by user275074
    Hi, I'm using the following code to get an array of directories and their sub-directories where each contain file type extension: png. It works great but I need to be able to output the results of the array in a list style format e.g. Test - test2.png - test1.png subfolder - test3.png sub sub folder - test4.png etc Code: $filter=".png"; $directory='../test'; $it=new RecursiveDirectoryIterator("$directory"); foreach(new RecursiveIteratorIterator($it) as $file){ if(!((strpos(strtolower($file),$filter))===false)||empty($filter)){ $items[]=preg_replace("#\\\#", "/", $file); } } Example array of results: array ( 0 => '../test/test2.png', 1 => '../test/subfolder/subsubfolder/test3.png', 2 => '../test/subfolder/test3.png', 3 => '../test/test1.png', ) What would be the best way of achieving the desired result?

    Read the article

< Previous Page | 93 94 95 96 97 98 99 100 101 102 103 104  | Next Page >