Store Variable In An Array
so i have a query that returns a bunch of rows.... i display the contents of the query into a table... one of the variables that the query returns is $title....
after each row is returned im wanting to store the $title variable into an array, so i can then access that array later... here is my code for storing $title into the array Code:
View Complete Forum Thread with Replies
Related Forum Messages:
Store A Array As A Variable
is there any way that i can store a array as a variable because i dont want to creat a database for thousands of variables. heres what i thought of so far <?PHP $arrayval = "1,3,2,7,4,6,8,15,12,78,96,1203,1029,39509,12999"; $array = array($arrayval); echo $array[1],$array[3],$array[2],$array[5],$array[6],$array[4],$array[7],$array[9],$array[5],$array[10],$array[13]; echo "<hr>"; echo $arrayval; echo "<hr>"; $sum = $array[1]+$array[3]+$array[2]+$array[5]+$array[6]+$array[4]+$array[7]+$array[9]+$array[5]+$array[10]+$array[13]; echo $sum; ?>
View Replies !
How To Store A Variable In Ob_start
I am passing a variable into a flash movie using php script when I come from another page. I find the value from the querystring using: <?php $section = $_GET['section']; ?> Everything works fine but not on the first load. I get the following notice when I load the page without a querystring variable: Notice: Undefined index: section in D:sitespc1.comsitedefault.php on line 15 I am trying to use ob_start but am not having much luck. <?php ob_start(); $section=4; ?>
View Replies !
Failing To Store Value Of Session Variable!
When I try to register a session variable by, for an example: $value = "foo"; session_register("value"); It doesn't want to be registered, i have tried to access it by: echo($_SESSION["value"]); The session file that is created then I start the session looks like this: value|N; It seems like it doesnt wanna register the value.
View Replies !
Store Values In An Array
$a=10; $a=15; while ($a <= $b) { $a++; } The output is 10,11,12,13,14,15 How to store the values of $a(10,11,12,13,14,15) in an sigle array.
View Replies !
Store Classes In An Array?
Is it possible to store classes in an array? I am fairly new to PHP, and haven't found anything either way yet. I have a program that where you can have multiple notes attached to a ticket, which are stored in a database. I would like to just pull all the notes from the database, storing each one in a seperate class, which itself is stored in an array (well, another class, but it's a classList, it's mainly an array). I'm getting an error when I run the page: "Cannot use a scalar value as an array", and "Call to a member function on a non-object". The second is related to the first, as I'm calling a function on the array value. If it is possible, I probably coded something wrong. If that's the case, I'll post some code.
View Replies !
Get Data From The Db And Store It In An Array
I want to have an input field in my Admin CP when you are creating a Forum where you can input a list of numbers (member ids) seperated by commars, like this: Quote1,6,4,8,2 These will be the ids of people who can moderate the Forum and will be stored in the db along with all the other stuff like forum name/description etc. That's easy enough. Now my problem is I need to get that from the db and store it in an array... basically so I can do something like: <?php if(in_array($_SESSION['mem_id'], $forum_moderator_array)) { echo('Congratulations, you are a forum moderator.'); } ?> How can I go about doing this?
View Replies !
What's The Best Way To Store An Array In The Database
I am trying to build a simple tree menu where the main items can be either a link or open up a subList of items which themselves can belinks or open into more submenus and so on. An example is: $ar = array( 'new_user' => 'newuser.php', 'tst1' => array( 'subtst' => 'subtstlink.php', 'subtst2' => 'sublink2.php' ), 'heyhey' => 'heyhey.php', ); I am wondering what is the best way to store that in a mysql database (Both the item name and the link to it). Is there any php function that will allow me to make such an array into some sort of variable (String?) which can then be read easilly and made back into the array for manipulation and creation of the tree menu?
View Replies !
How To Store Array In Cookies?
I try to store array in cookie this way: for($i=0;$i<5;$i++) { Â Â Â Â $field[]='test'.$i; } $_COOKIE['field2']=$field; Is it possible do it that way? I don't want to store each value of array list store separately. I'd like to store them at once. If I was storing values just to another "normal" variable (not cookie), I would do it this way: Code:
View Replies !
Can I Store An Array In MySQL?
I would like to store an array in a MySQL table. The values will be numeric and ranging from 1-999. I'm not sure if this is possible, and if it is then I'm not sure on the correct field type to use.
View Replies !
Store An Array In A Text Document
I want to store an array in a text document. what I've been doing so far looks like this: fputs( $myFile, $myArray ); but all it does is write the word "Array", instead of the actual array. I'm new to php and I've done my best to search the manual and numerous web resources (including this forum) for an answer, so please don't flame.
View Replies !
Store Mysql Results Into An Array
i just started using php. i've used it before as a maintainer. fun stuff. well now i'm the writer. i want to abstract all the DB commands away from myself and all other developers. so i'm writing a function to query the php database from all users of the database and store them into an array as a return value so that i can seperate my database code from my html creation code. 1. is there a way to put all my database functions into a php file and include that file into all my other php pages? similiarly to a #include in C++ or a import package name in Java? 2. my code to run down the fetched results and store them into an array doesn't seem to be working the way i want it to. if i print out the results from the mysql returned fetch the data is fine. however the array seems to print out "Array[elementnumber]" instead of the value. Code:
View Replies !
How To Store Checkbox Values To An Array?
I need to allow the user to select multiple mysql records via an html form checkbox. On submission of the form I would like to store these values in an array for either multiple record deletion or creating a list of records. Code:
View Replies !
Four Fields That Are Dates, Store As An Array
I have a form that has over 100 fields. I have four fields that are dates that I would like to store as an array. When I submit the form I place the dates in the array like so: $planworkdate = array("mon" => $planworkdate0,"tue" =>$planworkdate1,"wed" =>$planworkdate2,"thu" =>$planworkdate3); and insert into mysql database. When I try to retrieve the data I get the word Array for the result. What am I doing wrong? $query = "SELECT planworkdate from general"; $resultall = mysql_query($query); $planworkdate=mysql_result($resultall,$x,"planworkdate"); print $planworkdate; ...
View Replies !
Store Form Fields To An Array
i have a form which consists of several fields for name, address, number etc. i use a php form to process this and output it onto a html form. the thing is, i'd like to store the information in an array. so for each user, the array will have their details. and this can be printed on the screen. can you tell me how this is possible. i have seen examples of arrays, but the values are assigned to the variables already.
View Replies !
Store The Entire Table In A Two Dimensional Array
I am reading info from a tab-delimited text file and I was wondering if anyone knew how to get this concept to work. I am trying to store the entire table in a two dimensional array, but the way I'm doing it right now won't work. for($i=0; $i<$numrows; $i++) {$columnsvalue[i] = explode(" ",$newfile[i]);} does anyone else know how to better work with multi-dimensional arrays?
View Replies !
Mysql_fetch_array Way To Pull Out All The Data, Store It In An Array
I have a webpage which runs repetitive queries agaist a database in order to extract one item at a time and then put the items in an HTML table. The reason for this is formatting, plus the page hits 4 databases. Instead of running multiple queries pulling one item at a time...is there a way to pull out all the data, store it in an array, and then pull individual items from the array with php as I want to insert them in the table? So, example is Code:
View Replies !
Variables To Store (Name,Species,Sex) Inside An Array
In PHP, is there anyway of using variables to store each piece of information (Name,Species,Sex) inside an array. Then, when it comes to fetching the information, the array position (e.g. 0) is called along with the information type (Name etc). A bit like the following: record(1).name The information is coming from the record array, at position 1 displaying names.
View Replies !
Array Problem - Extract And Store In Seprate Variables .
I have an array from a program of the type $list_box_contents[$row][$col]['text']; There are 3 columns and an indefinite no. of rows. Each array element contains a few bits of information. I want to to extract this and store in seprate variables . $list_box_contents[$row][2]['text']; has 2 bits of information, a price and a small text box with some text. How can extract the price data from this .
View Replies !
Array Problem... - Store This List In $_SESSION['liste'];
the user selects 6 numbers in a list I have to store this list in $_SESSION['liste']; (I cant do it differently) the list is stored like that: 34-21-44-32-12-11 (cant do it differently either) what I need to do is to explode the array, get rid of the - , sort the values in ascending order and send them to my table as a string. so in the end I should have: 111221323444 I tried using a variation of laserlight's script (given in a previous post) without success... hope that someone will have time to give me a hand again in telling me what I could change in saberlights script to make it work.
View Replies !
Loop Through Array And Create Variable Session Variable Names
As part of my user authentication class I've written a method that sets session variables. I pass an array to the function by reference which contains elements populated with information from the users table in the DB (name, street, country etc) At the moment the function looks like this: /* Set the session variables for easy access to user data */ function _setSessionData(&$userData) { $_SESSION['loggedOn'] = true; // Logged on $_SESSION['userID'] = $userData['UserID']; $_SESSION['username'] = $userData['UserName']; $_SESSION['password'] = $userData['Password']; $_SESSION['firstName'] = $userData['FirstName']; $_SESSION['surname'] = $userData['Surname']; $_SESSION['email'] = $userData['Email']; $_SESSION['street'] = $userData['Street']; $_SESSION['city'] = $userData['City']; return true; } What I'm wondering is if it is possible to loop through the $userData array, and dynamically name and populate the session variables rather than listing them all and assigning like I have?
View Replies !
PHP "Calender Like" Pop Up To Select Date And Store As Variable In Mysql Format?
I use to have this feature on my site about two years ago when i hired someone. It would allow the user to select between two different dates, via a small calender, save it as a variable then query the database. Does anyone know where I can find the script for the small calender? I think it must of been populated by an external clock since all the dates were accurate etc. July 21st was on a saturday.
View Replies !
How To Store HTML Code (with " ", ' ') Inside A Variable In Php Script?
Assuming i have this simple script : <?PHP //Opening tag =' $html_header=' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ' // Closing tag =' echo $html_header; ?> If the opening & closing tags are both ' then it works fine, but if the html script itself contains a ' then i need some way to escape it, no ? How should i do it if i had something like <HEAD><TITLE='PHP foo'></HEAD>?
View Replies !
Array Question - First Letter Of The Variable As A Variable?
I have been going through arrays and have a multidemensional array. When I want to print everything to the screen this is the code I used. To print the array values I used $a from $arrayvals, does php always take the first letter of the variable and use it as a variable? For the key I used $k and for the values I used $v, are these set in stone variables, or can you use any variable name you want for them? $arrayvals = array( array( "name" => "Taylor", "age" => "26", "occupation" => "Supernurse", ), array( "name" => "Rachel", "age" => "25", "occupation" => "Supernurse", ) ); echo $arrayvals[$a>0]['name']; foreach ($arrayvals as $a) { while (list($k, $v) = each ($a)) { echo "$k ... $v <br/>"; } }
View Replies !
Create Session Then Store A Session Variable
I use the following code to create session then store a session variable called query and then redirect to another page called insertaccount.php where i wish to use the session value query. when i get to insertaccount.php the session variable query does not exist.can any one tell me why this is. page1.php <php? session_start(); $_SESSION['query'] = $query; header("Location: http://127.0.0.1/signup/insertaccount.php"); ?> insertaccount.php //inside <?php session_start(); $sql_query = $_SESSION['query']; ?>
View Replies !
Setting Variable To Array Within Mysql_query() Array
I found your site while attempting to solve the problem of utilizing JOIN statements in a PhP mysql_query. Your timely and well-structured assistance to LemonFizz was very helpful, and enabled me to develop the query below. I have now queried multiple tables to produce an associative array of all of a particular student's data after selecting the student's unique ID from a drop-down. This required the use of JOIN statements in my query. The query section of the file is as follows:
View Replies !
Variable Variable Array Indexes
I am converting my script to run with globals off, this is for image uploads before I used to store the data in a variable variable ${"image".$i} with $i coming from a for loop. How do I convert this to work with $_REQUEST ${"_REQUEST['image".$i."']"} this doesn't want to know and as I see it that is the logical conversion, I have searched the forums but haven't come up with this yet.
View Replies !
Using Variable As Array Key
I'm using postnuke and want to be able to use one sql statement to get one item from different tables. Here 's where I define my tables to use: $gettable = $pntable[$table]; $getcolumn = &$pntable[$column]; Without getting in to my sql statement, I can't get this to work: echo " test:" . $getcolumn[$subject]; It prints out $getcolumn[mfg]. The mfg as the key name is want I want, but i want it to printout the value of $get column. Here's my sql statement:
View Replies !
Variable In Array
Is it possible to put Variable in Array? Here is what I need: $array = Array($a,$b); $a = 'something' $b = 'something else' foreach ($array as $val) { echo "$val"; } Output should be: something something else Array is: Array ( [0] => $a [1] => $b ) If this is not possible is there any other way to do this? Thing is that I need to display some data based on array content. So far I have used: if (in_array(Ƌ', $array)) { echo 'data that should be display based on array value. I cant put this data in array because array is stored in cookie and then read' }
View Replies !
Using Array In Variable
My question today is about using and array like this: $var = 'a'; $array = ('a'=>'blah','b'=>'blarg'); $iable = $array[$var]; but in my code below using it like that does not display anything Code:
View Replies !
Using Variable As Array Value
I would like to use a variable as an array value so that I can display the proper values. For example, instead of fname[1], I would like to replace the "1" value with a variable because I am using a counter. This doesn't work: Code: $count=$count+1; echo $fname[$counter]; (repeat loop as needed) Any ideas?
View Replies !
Array And Variable
Wondering if someone might be able to help me out with this, for some reason it just doesnt want to work. Perhaps even a suggestion of another way to do it. PHP Code: $allproducts contains 3:Ink 5:Chalk 9:Pens <? $eachproduct=explode(" ",$allproducts); foreach($eachproduct AS $productandamount){ list($amnt,$product) = explode(":", $productandamount); echo"$amnt x $product<br>"; //this is correct and echoes correctly $product=strtolower($product);......
View Replies !
Array Using Variable
How come this doesnt works. PHP Code: $theArrayEntry = " 16=>array('?dt=xx','linked-day'), 21=>array('?dt=xx','linked-day') "; $days = array( $theArrayEntry );
View Replies !
Variable Array Name
I'm trying to use nested foreach loops to loop through two arrays. Each element in the first array corresponds to another array. The brandcode part of the first array is the same as the name of the corresponding array. Basically, one array is of the brand info, and the second is of the cars made by that brand. To loop through all the brands, and then print their corresponding cars, I tried: foreach ($brands as $curbrand) { foreach (${$curbrand['brandcode']} as $curcar) { echo $curcar; } } But I get "Invalid argument supplied for foreach()".
View Replies !
Using A Variable In An Array($test)
Code working but yields first int instead the sum of $test which is 70 ========================== $test = '10,20,30' $numunits_test = array($test); ================================== // If I were not going to use the $test variable... then the syntax should look like this: //$numunits_test = array(10,10,20,30); //I cannot hard code these numbers .. I have to recieve these numbers from a user input of a form. I have to use a variable in the array. //the incorrect out put for the above is 10 see below ============================= echo "sum = ".array_sum($numunits_test)." "; // 10 which is the first integer of $test. ========================= //How can i fix this? =========================== // This sums the integers properly.. but you see that the array is not array($variable) ... Instead it is array(2,3,4,6,7) etc. $a = array(2, 4, 6, 8); echo "sum = ".array_sum($a)." ";
View Replies !
Variable Variables And Array
I need to name a form field in a variable var1[0], var1[1], var[2]. I've got no problem doing this. However this is a dynamic form, and in other instances I need the variable to be called var2[0], var2[1], var2[2] and var3[0] the next time and so on. I think the solution is somehow related to variable variables, but I can't figure it out. If I just needed var[0] and var [1] that is easy I just do: for ($x = 0; $x <3; $x++) { echo "var[$x]";} but when I try and get the variablename and the array number to increment I'm stuck: for ($i = 0; $i<$mytotal; $++) { $var= "var" . "$i"; for ($x = 0; $x <3; $x++) { echo "$var[$x]";} doesn't work because it is looking for the array $var1[0] which doesn't exist. I tried echo "$var.[$x], and everything I can think of. Somehow I think I need a variable variable but can't figure it out.
View Replies !
Variable-variables For Array?
This has puzzled me for a while, what's the best (most efficient) way to get something from within an multi-dim array by using a variable for the key location? Here's what I currently do. PHP Code:
View Replies !
Using An Array Variable From An Includes?
I am making an array of browsers that do not support AJAX. I want to of course have this as an includes somewhere so I don't have to maintain several lists simultaneously. I'm not sure how to compare the useragent ($useragent) against this array ($useragents['noajax']) and I've tried something like... if ($useragent == $useragents['noajax']) {echo 'ajax not supported!'} I didn't think it'd be that easy of course. What would be the best way to compare the $useragent to the $useragents['noajax'], and is there anything special I have to do to get this to work besides an includes? <?php $useragent = $_SERVER['HTTP_USER_AGENT']; $useragents = array ( 'noajax' => array // $useragents['noajax'] ( 'Opera/3', 'Opera 3', // Spoofing 'Opera/4', 'Opera 4', // Spoofing 'Opera/5', 'Opera 5', // Spoofing 'Opera/6', 'Opera 6', // Spoofing 'Opera/7', 'Opera 7', // Spoofing 'Opera/8.00', 'Opera 8.00', // Spoofing 'Opera/8.01', 'Opera 8.01', // Spoofing ), ) ); ?>
View Replies !
|