Search Results

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

Page 100/1708 | < Previous Page | 96 97 98 99 100 101 102 103 104 105 106 107  | Next Page >

  • Dynamical array of strings in C

    - by Ir0nm
    I'm trying to make array of strings, I have function rLine which reads line from stdin, each inputted line I need to save in array, but I don't have any idea about number of inputted string lines. So I need to dynamically increase array size to store them, I wrote such code: char *res[2], *old = res; while( 1 ){ line = rLine( stdin ), len = strlen( line ); res[row] = (char*)malloc( len + 1); strcpy( res[row++], line); res = (char**) realloc( res, row ); /* adding 1 more row, not sure adding size row? */ if ( /*some cond*/ ) break; } But this code doesn't seem to work, how correctly declare array and increase it size?

    Read the article

  • comparing 3 arrays and result in 1 array

    - by frightnight
    i have 3 arrays, i want to get the result of those 3 arrays in one, but how can i deleted those same answer in a arrays? here's my example: <?php $array1 = array("a" => "green", "red", "blue"); $array2 = array("b" => "green", "yellow", "red"); $array3 = array("c" => "white", "blue", "black"); $result = ??? ($array1, $array2, $array3); print_r($result); ?> Array ( [0] => green [1] => red [2] => blue [3] => yellow [4] => red [5] => white [5] => black ) please help me guys.. thank you..

    Read the article

  • Troubleshooting multiple GET variables In PHP

    - by V413HAV
    This may be a very simple question but I don't what's the wrong thing am doing here... To explain you clearly, I've set a real simple example below: <ul> <li><a href="test.php?link1=true">Link 1</a></li> <li><a href="test.php?link2=true">Link 2</a></li> <li><a href="test.php?link3=true">Link 3</a></li> </ul> <?php if(isset($_GET['link1'])) { if(($_GET['link1']) == 'true') { echo 'This Is Link 1'; } } if(isset($_GET['link2'])) { if(($_GET['link2']) == 'true') { echo 'This Is Link 2'; } } if(isset($_GET['link3'])) { if(($_GET['link3']) == 'true') { echo 'This Is Link 3'; } } ?> This is a test.php page, here I've set 3 different arguments for $_GET, and show contents accordingly, now everything works perfect, the only thing am not understanding is how to block this kind of url say if user clicks on link 1 the url will be : http://localhost/test.php?link1=true And the Output of this url is This is Link 1 Now if I change this url to : http://localhost/test.php?link3=true&link2=true&link1=true And the Output what I get is This Is Link 1This Is Link 2This Is Link 3 Now this is ok here, but it's very annoying if someone types this and see's forms one below the other, any way I can stop this tampering?

    Read the article

  • How to create a String Array and link it to a Grade array

    - by user1861544
    I have a project that I need to create 2 Arrays, one to hold Student Names and one to hold Student Scores. The user inputs the size of the array, and the array needs to be sorted using BubbleSort (putting the high scores at the top). I have started the project, created the first array for scores, I have successfully done bubble sort and sorted the grades. Now I can't figure out how to make an array for Names, and once I do how do I make the names array correspond to the Grades array BubbleSort? Here is the code I have so far. import java.util.Scanner; public class Grades { public static void main(String[]args){ { Scanner UserIn = new Scanner(System.in); System.out.print( "How many students are there? " ); int[]GradeArray = new int[UserIn.nextInt()]; for( int i=0 ; i<GradeArray.length ; i++ ) { System.out.print( "Enter Grade for Student " + (i+1) + ": " ); GradeArray[i] = UserIn.nextInt(); } bubbleSort(GradeArray); for( int i : GradeArray ) System.out.println( i ); System.out.println(); } } private static void bubbleSort(int[]GradeArray){ int n = GradeArray.length; int temp = 0; String temp2; for(int i=0; i<n; i++){ for(int j=1; j<(n-i);j++){ if(GradeArray[j-1]<GradeArray[j]){ //swap temp=GradeArray[j-1]; GradeArray[j-1]=GradeArray[j]; GradeArray[j]=temp; } } } } } Also how do I change the grades to Double? I started with Int and when I try to change everything to double I get an error saying "Found Double, expected Int".

    Read the article

  • How to log php error in a separate file?

    - by Question Overflow
    I just did an upgrade of my server to Fedora 17 and merged some configuration files containing .rpmnew into the existing ones. I have been successfully logging my php errors in a separate log file by keeping the following in php.ini: log_errors = On error_log = /var/log/php-errors.log I am not sure why the errors are being logged to /var/log/httpd/error_log after the upgrade despite keeping the settings above. Also, $ ls -l /var/log/php-errors.log -rwxrwxr--. 1 apache myself 232 Dec 13 16:49 /var/log/php-errors.log shows that apache did own the php error log file. What could be causing PHP errors to be logged into apache error log file?

    Read the article

  • Generate a valid array key from an URL string in PHP

    - by John Riche
    I have a PHP array with some predefined values: $aArray = array( 0 => 'value0', 1 => 'value1' ); I need to create a function where the string input will always return the same, valid, array key so that when I call: GiveMeAKey('http://www.google.com'); // May return 0 or 1 I receive always the same key (I don't care which one) from the array. Obvisously I can't store the relationship in a database and the string passed to the GiveMeAKey method can be any URL. I wonder if there is a way of doing that ?

    Read the article

  • Modifying MySQL Where Statement Based on Array

    - by Ryan
    Using an array like this: $data = array ( 'host' => 1, 'country' => 'fr', ) I would like to create a MySQL query that uses the values of the array to form its WHERE clause like: SELECT * FROM table WHERE host = 1 and country = 'fr' How can I generate this query string to use with MySQL?

    Read the article

  • PHP & MySQL username validation and storage problem.

    - by php
    For some reason when a user enters a brand new username the error message <p>Username unavailable</p> is displayed and the name is not stored. I was wondering if some can help find the flaw in my code so I can fix this error? Thanks Here is the PHP code. if($_POST['username'] && trim($_POST['username'])!=='') { $u = "SELECT * FROM users WHERE username = '$username' AND user_id <> '$user_id'"; $r = mysqli_query ($mysqli, $u) or trigger_error("Query: $u\n<br />MySQL Error: " . mysqli_error($mysqli)); if (mysqli_num_rows($r) == TRUE) { echo '<p>Username unavailable</p>'; $_POST['username'] = NULL; } else if(isset($_POST['username']) && mysqli_num_rows($r) == 0 && strlen($_POST['username']) <= 255) { $username = mysqli_real_escape_string($mysqli, $_POST['username']); } else if($_POST['username'] && strlen($_POST['username']) >= 256) { echo '<p>Username can not exceed 255 characters</p>'; } }

    Read the article

  • Delete an (exact) element from an array in php

    - by Holian
    Hi Masters! For example i have an array like this: $test= array("0" => "412", "1" => "2"); I would like to delete the element if its = 2 $delete=2; for($j=0;$j<$dbj;$j++) { if (in_array($delete, $test)) { unset($test[$j]); } } print_r($test); But with this, unfortunatelly the array will empty... How can i delete an exact element from the array? Thank you

    Read the article

  • Single-entry implementation gone wrong

    - by user745434
    I'm doing my first single-entry site and based on the result, I can't see the benefit. I've implemented the following: .htaccess redirects all requests to index.php at the root Url is parsed and each /segment/ is stored as an element in an array First segment indicates which folder to include (e.g. "users" » "/pages/users/index.php"). index.php file of each folder parses the remaining elements in the segments array until array is empty. content.php file of each folder is included if there are no more elements in the segments array, indicating that the destination file is reached Sample File structure ( folders in [] ): [root] index.php [pages] [users] index.php content.php [profile] index.php content.php [edit] index.php content.php [other-page] index.php content.php Request: http://mysite.com/users/profile/ .htaccess redirects request to http://mysite.com/index.php URL is parsed and segments array contains: [1] users, [2] profile index.php maps [1] to "pages/users/index.php", so includes that file pages/users/index.php maps [2] to pages/users/profile/index.php, so includes that file Since no other elements in the segments array, the contents.php file in the current folder (pages/users/profile) is included. I'm not really seeing the benefit of doing this over having functions that include components of the site (e.g. include_header(), include_footer(), etc.), so I conclude that I'm doing something terribly wrong. I'm just not sure what it is.

    Read the article

  • ruby sortby 3rd element in a multidimential array npot working properly

    - by Steven
    Hi, I'm using ruby to sort an array where each element in the array is another array. I have this: Data = Data.SortBy { |Info| info[3] } example data in this column: 3.1 2 5.65 -1 0.4 -9.43 -10.87 -2.3 It should sort this into: 5.65 3.1 2 0.4 -1 -2.3 -9.43 -10.87 But it comes out like this: 5.65 3.1 2 0.4 -1 -10.87 -2.3 -9.43 It's only comparing the first char of the float... not the whole number?

    Read the article

  • Fetch multiple rows from SQL in PHP foreach item in array

    - by TrySpace
    I try to request an array of IDs, to return each row with that ID, and push each into an Array $finalArray But only the first result from the Query will output, and at the second foreach, it skips the while loop. I have this working in another script, so I don't understand where it's going wrong. The $arrayItems is an array containing: "home, info" $finalArray = array(); foreach ($arrayItems as $UID_get) { $Query = "SELECT * FROM items WHERE (uid = '" . cleanQuery($UID_get) . "' ) ORDER BY uid"; if($Result = $mysqli->query($Query)) { print_r($UID_get); echo "<BR><-><BR>"; while ($Row = $Result->fetch_assoc()) { array_push($finalArray , $Row); print_r($finalArray ); echo "<BR><><BR>"; } } else { echo '{ "returned" : "FAIL" }'; //. mysqli_connect_errno() . ' ' . mysqli_connect_error() . "<BR>"; } } (the cleanQuery is to escape and stripslashes) What I'm trying to get is an array of multiple rows (after i json_encoded it, like: {"finalArray" : { "home": {"id":"1","created":"0000-00-00 00:00:00","css":"{ \"background-color\" : \"red\" }"} }, { "info": {"id":"2","created":"0000-00-00 00:00:00","css":"{ \"background-color\" : \"blue\" }"} } } But that's after I get both, or more results from the db. the print_r($UID_get); does print info, but then nothing.. So, why am I not getting the second row from info? I am essentially re-querying foreach $arrayItem right?

    Read the article

  • PHP - Pull out array keys that have matching values?

    - by MAZUMA
    Is there a way to look inside an array and pull out the keys that have keys with matching values? Questions like this have been asked, but I'm not finding anything conclusive. So if my array looks like this Array ( [0] => Array ( [title] => Title 1 [type] => [message] => ) [1] => Array ( [title] => Title 2 [type] => [message] => ) [2] => Array ( [title] => Title 3 [type] => [message] => ) [3] => Array ( [title] => Title 2 [type] => Limited [message] => 39 ) [4] => Array ( [title] => Title 4 [type] => Offline [message] => 41 ) [5] => Array ( [title] => Title 5 [type] => [message] => ) And I want to get this Array ( [1] => Array ( [title] => Title 2 [type] => [message] => ) [3] => Array ( [title] => Title 2 [type] => Limited [message] => 39 ) )

    Read the article

  • need to loop through a PHP array in JavaScript

    - by user296516
    Hi guys, For example I have a PHP array, such as this one <?php $s= array('a','b','c','d','e','f') ; ?> And I need to loop through it in JavaScript, any ideas how do I do that? for ( i=0 ; i < <?php echo sizeof($s) ?> ; i++) { document.write('<?php echo $s [somehow need to get the 'i' value into here] ?>'); } Any suggestions? Thanks!

    Read the article

  • Using preg_match as boolean AND array

    - by silow
    I have this code where preg_match is used to break up a string into $pmarr array. Index 1 of that array is then being used to set a value $val = $pmarr[1]. $pmarr = array(); if (preg_match($expression, $orig, $pmarr)) { $val = $pmarr[1]; } What I'm wondering about is why the preg_match itself is being used as a boolean. If the expression doesn't match, does the array stay empty and therefore equate to false? Is the above code the same as saying preg_match($expression, $orig, $pmarr); if(isset($pmarr[1]) AND !empty($pmarr[1])){ $val = $pmarr[1]; }

    Read the article

  • ajax form handling an array

    - by moata_u
    am trying to handle an array comes from php file after submitting the form data , the value of data after submitting the form is = ARRAY but i cant use this array in any way , any idea how can i handle this array !!!! Javascript : $('#file').live('change',function(){ $('#preview').html(''); $('#preview').html('<img src="loader.gif" />'); $('#data').ajaxForm(function(data){ $(data['toshow']).insertBefore('.pic_content').hide().fadeIn(1000); }).submit(); }); PHP : .... ....etc echo json_encode(array('toshow'=>somedata,'data'=>somedata)); data come from php file {"toshow":"\r\n\t\t\t\t\r\n\t\t<table class=\"out\">\r\n\t\t\t<tr ><td class=\"img\"><a title=\"2012-06-02 01-22-09\" rel=\"prettyPhoto\" href=\"img\/2012-06-02 01-22-09.284.jpg\"><img src=\"img\/thumb\/2012-06-02 01-22-09.284.jpg\"\/><\/a><\/td><\/tr>\r\n\t\t\t\r\n\t\t\t<td>\r\n\t\t\t\t<table cellSpacing=\"1\" cellPadding=\"0\">\r\n\t\t\t\t\t<tr><td class=\"data\"><span class=\"click\">2012-06-02 01-22-09<\/span><\/td><\/tr>\r\n\t\t\t\t\t<tr><td class=\"data\"><span class=\"click\">Download<\/span><\/td><\/tr>\r\n\t\t\t\t\t<tr><td class=\"data\"><a href=\"img\/2012-06-02 01-22-09.284.jpg\"><span class=\"click\">View<\/span><\/a><\/td><\/tr>\r\n\t\t\t\t<\/table>\r\n\t\t\t<\/td>\r\n\t\t\t<\/tr>\r\n\t\t<\/table>","span":"<span class='text'><img src='greencheck.png'\/>2012-06-02 01-22-09 Uploaded ,File Size =152Kb <\/span>"}

    Read the article

  • Problem with echoing my array data in PHP

    - by ggfan
    I want to create an array of numbers: 10, 9,8...to 1. But when I echo $numbers, I get "Array" as the output as to the numbers. There is probably a simple thing I missed, can you please tell me. thanks! $numbers=array(); for ($i=10; $i>0; $i--){ array_push($numbers, $i); } echo $numbers;

    Read the article

  • Perl check for the existence of a value in a regular array

    - by Mel
    I am trying to figure out a way of checking for the existence of a value in an array without iterating through the array. I am reading a file for a parameter. I have a long list of parameters I do not want to deal with. I placed these unwanted parameters in an array @badparams I want to read a new parameter and if it does not exist in @badparams, process it. If it does exist in @badparams, go to the next read.

    Read the article

  • Creating an array from a MySQL table

    - by Rob
    I'm trying to create an array to use for a curl_multi_exec, but I can't seem to create the array properly. Here is my code: $SQL = mysql_query("SELECT url FROM urls") or die(mysql_error()); //Query the shell table while($resultSet = mysql_fetch_array($SQL)){ $urls[]=$resultSet; } echo $urls; //Test that the array works But when I run this script, all it does is echo "Array" I have no idea what I'm doing wrong, I've checked around google a bit, but can't figure it out. Any insight would be appreciated.

    Read the article

  • create variable from array actionscript 3

    - by steve
    I'm currently trying to make a dynamic menu via an array and a loop. So when someone clicks on the first item of the array, "menu_bag_mc" it will link to the content "menu_bag_mc_frame" (or some name that will be unique to this array) that is another movieclip that will load. Below is the code I have so far: //right here, i need to make a variable that I can put in the "addchild" so that //for every one of the list items clicked, it adds a movieclip child with //the same name (such as menu_bag_mc from above) with "_frame" appended. //I tried the next line out, but it doesn't really work. var framevar:MovieClip = menuList[i] += "_frame"; function createContent(event:MouseEvent):void { if(MovieClip(root).currentFrame == 850) { while(MovieClip(root).numChildren > 1) { MovieClip(root).removeChild(MovieClip(root).getChildAt(MovieClip(root).numChildren - 1)); } //Here is where the variable would go, to add a child directly related //to whichever array item was clicked (here, "framevar") MovieClip(root).addChild (framevar); MovieClip(root).addChild (closeBtn); } else { MovieClip(root).addChild (framevar); MovieClip(root).addChild (closeBtn); MovieClip(root).gotoAndPlay(806); } } Is there a way to make a unique variable (whatever it is) from the array so that I can name a movieclip after it so it will load the new movieclip? Thanks

    Read the article

  • Accessing array elements in PHP

    - by Elliot B.
    I have an array $aMethods whose print_r output is this: Array ( [0] => Array ( [pattern] => [return_media] => 1 [return_name] => ) ) I'm trying to access 'return_media' with this code: $iReturnMedia = $aMethods[0]->return_media; echo $iReturnMedia; Also, when I tried this: $iReturnMedia = $aMethods[0]['return_media']; I get an error stating: Cannot use string offset as an array in... But it's not working, $iReturnMedia comes back as blank. Could someone tell me what I'm doing wrong here?

    Read the article

  • Strange PHP array behavior overwriting values with all the same values

    - by dasdas
    Im doing a simple mysqli query with code ive used many times before but have never had this problem happen to me. I am grabbing an entire table with an unknown number of columns (it changes often so i dont know the exact value, nor the column names). I have some code that uses metadata to grab everything and stick it in an array. This all works fine, but the output is messed up: $stmt -> execute(); //the query is legit, no problems there $meta = $stmt->result_metadata(); while ($field = $meta->fetch_field()) { $params[] = &$row[$field->name]; } call_user_func_array(array($stmt, 'bind_result'), $params); while ($stmt->fetch()) { $pvalues[++$i] = $row; //$pvalues is an array of arrays. row is an array //print_r($row); print_r($pvalues[$i-1]); } $stmt -> close(); I would assume that $pvalues has the results that I am looking for. My table currently has 2 rows. $pvalues has array length 2. Both rows in $pvalues are exactly the same. If i use the: print_r($row) it prints out the correct values for both rows, but if later on i check what is in $pvalues it is incorrect (1 row is assigned to both indices of $pvalues). If i use the print_r($pvalues[$i-1]) it prints exactly as I expect, the same row in the table twice. Why isnt the data getting assigned to $pvalues? I know $row holds the right information at one point, but it is getting overwritten or lost.

    Read the article

  • Php header('Location") error

    - by Umeed
    I'm having some difficulty with my php coding. I have 3 files, add.php, lib.php, and view.php I created a simple form, and when the user clicks submit, it should direct them to the view.php where it will display the database. Now I'm having a couple issues I can't seem to resolve. when the user clicks submit and the fields are blank or there is an error no entry should be made into the view page (or database)...however when I click submit a blank entry is made into the database. ALSO if i click "enter product" from the top menu bar anytime I click it, it causes a blank entry into the database. I can't figure out why that's happening. My next issue is with the header('Location') and my browser says: "Warning: Cannot modify header information - headers already sent by (output started at lib.php:13) in add.php on line 16" However if I click submit on my form it goes away. Here is the code for the pages: http://ideone.com/Vvz8x I truly apologize if the code is really messy. Any help / advice / solution is greatly appreciated thank you. And yes this was an assignment---it was due last week but since I couldn't finish it, it's not worth any marks anymore.

    Read the article

< Previous Page | 96 97 98 99 100 101 102 103 104 105 106 107  | Next Page >