Dynamic Variabel Names In Arrays
I have a php script that makes multiple sql query's that results multiple datasets that I will use in a graph. Its set up something like this.
for($i=0; $i<$n; $i++){
sql query runs here n times and produce each time a dataset that looks like.
2007-10-17 3
2007-10-18 4
2007-10-19 2
I want to put each dataset in an Array with diferent name.
I manage to put on dataset it in one array
$ydata[] = $row[1];
$xdata[] = $row[0];
}
but I need one array of every dataset with names that I can recognize outside the loop, for eks a dynamic variabel name that consist of $i and some other name. like $i.$xdata[], but I cant make this work.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Dynamic Variable Names
I have a shopping cart page that allows a user to type in a new quantity and press a [Submit] button. The quantities entered are in form text boxes with the names "item302", "item7812", etc. reflecting which item that particular textbox is associated to. I store the entered variables using 'import_request_variables("p","p_")' so I end up with $item302, $item7812, etc. My script looks for these variables by looking through the shopping cart array which stores the item numbers themselves and then checks the value of $item<whatever>. If I have a number stored in $item is there any easy way to tell PHP to check the value of variable $p_item<item>? For example, if $item is ¹Ż' how can I tell PHP to evaluate $p_item302?
Dynamic Variable Names.
I want to make it so the name of a variable is changed by '$z' I'm not sure how to do this. Right not I'm trying: [$row + $z] = 1 But it doesn't work.
Dynamic Variable Names For Objects
I need to use dynamic variable names but for objects. As you know something like that works fine: $variable="content"; $part="able"; echo ${"vari".$part}; // gives out content but i need to use a database object after a mysql query something like that $sqlresult= mysql_query("SELECT * FROM t_table_xy"); while (($obj = @mysql_fetch_object($sqlresult)) { echo ${"obj->f_".$fieldname[1]}; } but this dont work, I suppose because of the -pointer. has someone an idea how to solve that ?
How To Process Dynamic Form Field Names
Let me start by saying I don't have a lot of PHP experience, and am just starting to fumble my way around some of this stuff... I'm sure this has been asked a number of times, but after 2 days of searching the internet, I just haven't found a solution that makes sense, so I am hoping someone here can help me. I have a pretty simple project schedule sort of web page that lists a number of tasks & 4 dates associated with each task. (planned start, planned complete, actual start, actual complete. The page is built dynamically based on what is in a mysql database, and the dates listed are form fields, with the intent that a person with access can change any number of these dates. Each task has an id associated with it, so when i build the form, I name the form field <task_id>-<date type>. so, for example, for task id = 10 I have 4 related form fields: 10-planned_start 10-planned_complete 10-actual_start 10-actual_complete This basic pattern is repeated for all the tasks (up to 100 right now, but it could grow slightly). Once all the form fields have been updated, and the user clicks submit I want to update the data in the database with the appropriate data. So, my questions is: 1) How can I process this form, when I don't know what the names of the fields are going to be, and/or how many fields there are? 2) Is there a good way to identify only those fields that have changed and do updates on only those fields, or am I "stuck" updating all the records, even those where the dates have not changed from when the form was built?
Comparing Values Of 2 Arrays Combined With Mysql Field Names
I am trying to create an edithistory table that has a text column into which I will put a string that can be read using strtok later to revert changes if necessary. I want to build this function so that it's dynamic enough to be applied to every table so that I don't have to write one for each table that might be updated. When a row is added to any table (a new entry), it retrieves the next available editid # from the edithistory table and assigns it to that item in the "edits" column for its row in its own table. Every edit made is a new entry in the edithistory table (entryid auto_increment primary key), and the editid is a reference back to the object being edited. Code:
Dynamic Arrays
People come to my site, they choose the name of a car from a database. I want the name of the car to go into an array. I want to put it in an array and not just as a single variable because i want them to have the option of coming back to the page and choose the name of another car. They can have as many names of cars as they like. To make sure i retain the values of the array, i will put them in a session variable. My question is how do i generate the dynamic array? When people come back to the page with the values of the array in the session variable will that cause a problem?
Use Of Isset () In A String Variabel
What I try to do is create a string variabel with some intelligence. I want this variabel to read the information sent by another page and interpret the result. The idea is that is a variabel is set, a line break is printed. First question is if this is possible? Second if so, what should be the correct syntax? I have written it like this, but this errors. $string="{$_POST['name']}{if (isset($_POST['name'])){print ("<br>");}";
Function With Reference-passed Variabel
Are there somebody, who can tell me, what I'm doing wrong with this function: function hej($q, &$h) { if ($q == 0) { return true; $h = 'Hello' } else { return false; $h = 'Goodbye' } } $rt = hej(0, &$a); if ($rt==true) { echo 'Hej' } else { echo 'Farvel' } print_r($a); echo "<br /> ";
Assign Mysql Record Values To Gloabl Variabel
I've been struggle with the code below. I've tried mysql_fetch_assoc and various other functions, but can't seem to get it to work. The code works as far as that point though. global $first_name; global $last_name; global $password; function get_acct_rec($email){ $conn = db_connect(HOST, USER, PASS, DB, PORT); $sql = "SELECT * FROM `clients` WHERE `email` = '" . $email . "'"; $c_result = mysql_query($sql, $conn) or die("Failed to execute query at line " . __LINE__ . ": " . db_error($conn)); while ($row = mysql_fetch_assoc($c_result)) { $first_name = $row['first_name']; $last_name = $row['last_name']; $password = $row['password']; echo $row['first_name']; } mysql_free_result($result); db_close($conn); }
Setting Variable Names Using Field Names?
I'm having trouble creating dynamic variables using field names. Basically I got a heap of fields named after Players and I want to grab the field name and make a variable called it while assigning it a value from a post variable which is also the player name. This is the code I'm using: $result=mysql_query("SELECT * FROM playerstats"); while($fld = mysql_fetch_field($result)) { if ($fld->name!='match_id' && $fld->name!='opponent' && $fld->name!='map') { $fld->name=$_POST[$fld->name]; } }
Arrays Within Arrays, How To Split
I have been stumped on this one and it is probably easier than I think it is, especially since my brain is fried. This is what my array looks like: array(7) { ["injuredPerson"]=> string(0) "" ["dates"]=> string(0) "" ["describe"]=> string(0) "" ["location"]=> string(0) "" ["type"]=> array(3) { [0]=> string(8) "abrasion" [1]=> string(10) "amputation" [2]=> string(12) "asphyxiation" } ["part"]=> string(0) "" ["times"]=> string(0) "" } This is actually an array of information from a form check. I have the error handling check the form and depending on if there is an error or not, the array gets populated with "" or an actual value(s). I am testing a checkbox area of the form (the name is type, so type can hold an array of values, thats why it currently contains abrasion, amputation, and asphyxiation). I have had no problem going through the array until I get to the area with an array within the array. Let me give you some code so you can see how I am doing this:
Searching Arrays With Arrays
ive looked through alot of the array search functions and i dont think any of them support arrays as the "needle" to search for. so say i had a numeric array, $array1 with say 5 elements, 0-4, each element is a single word, lowercase. say i had another numeric array structured the same way called $array2 with say about 5 elements, 0-4. Is there a function which i could use or does anyone know of an easy way to search every element in $array1 and compair it through each of the elements of $array2? and if a duplicate is found in $array2 have that element be removed or unset? im sure this can be done probably easy with some kind of loop function, but thats my weak point right now in php and im working on it.
Bad Names
I have a program that extracts text from a file. But when it extracts the letter “ and some other letters, it outputs them like this: "IllidanĀ“s Revenge". But it first put it into the db
Form Names And PHP
Does PHP handle form names? Suppose I have two forms on one page, named form1 and form2. I pass them to the same php script via the same method. Can PHP distinguish which form was used? How?
How To Get The Names Of All Sub Objects?
My example: $person->telnumber->value $person->faxnumber->value $person->??? The names of the objects "telnumber" and "faxnumber" (and further possible subobjects) are not known for me. How can I get the names of all subobjects of an object?
Irish Names
I have a problem sending email from a for supplied as html if in the person has to supply an additional Name field it works if his name is Smith but if it is O'Brian it fails. is there away to overcome this apostrophe problem.
Pdo Get Field Names
I'm using PDO for the first time. I want to get the field/column names from a SELECT query. I can get the names from the associative array returned by fetch(). But how do I get the field names if the SELECT query returns no rows? I could do this before with the xxxx_fetch_field() functions. Here's a condensed version of my code: // query the database $DbToQuery = new PDO("sqlite::memory:"); $DbToQuery->query("CREATE TABLE MyTable (MyField TEXT)"); $sql = "SELECT * FROM MyTable"; $result = $DbToQuery->query($sql); // Get the number of columns $Cols = $result->columnCount(); // Loop through the results $countrows = 1; while($row = $result->fetch(PDO::FETCH_ASSOC)) { if($countrows == 1) { // Print column names print join(",", array_keys($row)); } $countrows++; // handle the row data // ... }
Variable Names
I want to create a series of variable names in the form of $dist_1, $dist_2, $dist_3 etc....How can I do this using a loop? A scaled back example (ie, forgetting about the for loop syntax) of what doesn't work is: $i = 1; $dist_'$i' = 50; echo $dist_1; I have tried all sorts of variations like $dist.$i, $dist"$i", but none of them seem to work. I could create an array dist[$i] but that is going to cause problems elsewhere.
Subdomain Names?
i have a website which is functional since 2006. But now i just want to add some new services like SMS and so on. i want users to type sms.mywebsitename.com to access the page with the sms service. but i am not aware of how to make the subdomain i mean sms prefix.
Page Names?
Is it possible to somehow read a page title based on the page you are one. for example: if the page is: mainpage.php so inside the mainpagephp it would say: include "pagetitles.inc"; and inside the the pagetitles.inc file it would say something like: if whateverpage echo $pagetitle = "Main Page";
Domain Names
I am writing a reporting tool for the open source project Dansguardian, right now I am taking a URL that a user has visited and need to compare it to a blacklist, which contains just domain names (i.e. - phpfreaks.com). I currently have some code which does this but it does not work for https URL's. Here is the code:
Add Commas Between Names
i've got a script that pulls first name, last name, and suffix from a DB query and echos them only if they are not null. the names are cross-referenced by id number from two other tables. it displays the name pieces that are not null for each "job", and the jobs and names are determined by another id number for an individual issue page. an example of the output is here: Code:
Column Names
how can i get the column names of ms access table?
Php Sessions Over 2 Domain Names
When developing I created two under the same domain name. Both site share most of the same content and database. One of the sites is basicly just a frontend that accesses the pages from the other site and depending on what site you're comming from, the color is different, menu is different, etc... this worked fine with the domains were setup like this: But once the sites were put under URL and URL everything failed. All the session information is lost when accessing a page from the other site. Does anyone have any experience with this?
Sessions And Domain Names
I've got an app that dumps a user id into a session after successful login. the login page is http://www.mydomain.com/login.php. If the user visits pages on my site without the www (i.e., http://mydomain.com/foo.php), the session works fine and login state is maintained. If he visits http://www.mydomain.com/foo.php, the app drops the logged-in state. Any idea how to fix this? I'm running php 4.4.1 w/ linux apache.
Getting File Names On Another Server With PHP
My ISP provides me with minimal space on a dedicated server running PHP, and 250MB on a separate HTTP server. I'm trying to make a gallery using PHP. The script is held on the PHP server, and the thumbnails and images are on the separate HTTP server. Ideally I'd like to be able to get a listing of the contents of the HTTP server where the images are stored. I want to do this so that when I add/delete/change images, the dynamic nature of the site just picks up the new files and I don't have to maintain a separate database of the image names and where they're stored.
How To Make DIR-Names Substituted
I want to make my directories hidden, and I have seen some sites using a very long string to "hide" the real DIRectory name. any idea on how to do this in PHP? The purpose is to make the sites linked to unreachable for users, they see a link in the buttom of the page, or the see it in the address line og the browser, but I want it to be a "Virtual" link, that only exists in the one session they are in. As soon they leave the page, the link must be "erased/unuseable"
File Names Into Array
right so im in the midst of creating a gallery for a friend of mine, i have most of it right, but when i get the file names from the directory and into an array i have the ".." and "..." as the first two elements, any ideas? my getImages functions is simply as follows: #PHP function getImages() { global $images; $mydir = opendir(images); for($i=0; $i<10; $i++) { $entryname = readdir($mydir); $images[] = $entryname; echo("<br>"); } #PHP
Get Names Of Cookies And Run Them Against Database
I set several cookies on the page. Now I need to get the name of each cookie I set and run it against my database if the name from the cookie matches the "ID" in my database I want to display this record. PHP Code:
File Names In Directories
On my current website I have gallery pages with links to different galleries within that gallery section. The problem is, that I have to manually edit every single page when I want to add a new page so that every page now has a link that includes the new page number. Now I have been thinking that surely PHP could be used to automate this instead of me doing it every time I put a new gallery page online. What I'd like to know is if it is possible for PHP to read a file name, then use that to "echo" it into the HTML, then go to the next file name - do the same, until there are no more like sounding filenames in that directory. So for example, I have gallery01, gallery02, gallery03 webpages. I ask PHP to look for a match for "gallery", then add the file number "01", and echo it to the HTML page, and then do the same until there are no more "gallery" pages to be found in that directory. If possible, scould someone point me in which direction to do this (I don't need / want a complete solved solution :) ).
How Can I Get Session Variable Names
Is there any way through which I can get what session variables are created in the session. Suppose there are two pages. Page A and page B Page A has a link for page B When a person clicks link of Page B on Page A, he should get the list of all session variables and there values. Is this possible? Also is it necessary that Page A should also be in php. Will it work if it is java.
Sessions And Domain Names
I've got an app that dumps a user id into a session after successful login. the login page is http://www.mydomain.com/login.php. If the user visits pages on my site without the www (i.e., http://mydomain.com/foo.php), the session works fine and login state is maintained. If he visits http://www.mydomain.com/foo.php, the app drops the logged-in state.
Using Variables At Table Names
Do you guys know how to use PHP variables as table names? I'm trying to create a function that can be used by several pages. PHP Code:
Assembling Variable Names
Is it possible to use a variable by assembling two or more other variable: $varname = 3; $foo = "var"; $bar = "name"; $something = $foo$bar I know that probably won't work, but I want to do something like that.
Finding Variable Names
I am writing a generic function to send an http POST request directly from a PHP script. The idea is that you can send as many variables as you like to the function and it will produce a URL encoded string, as follows... $request .= '&$var1Name=' . urlencode($var1); $request .= '&$var2Name=' . urlencode($var2); ...etc. It then sends this (along with the header info) with an fsockopen() function. My problem is that I have no way of finding out the name of the variables that are being send to the function.
Reading File Names
Im writing a php file that will upload pictures in a remote directory. Im actualy doing a buletin board,and i have a mysql table that has subjext message date and entries(key) columns. I want the user to be able to aslo upload a image when posting a message. So I figured the best way to do this is to upload all files in a dirr and add the column 'image filename' to the mysql table for each entry. Im not sure how to read the file names for each entry. My guess was to use $image = basename($path); but how will it know to store differet file names for each entry in the table. Does anyone know ?
Need Column Names, Not The Array Key...
I am running a script that exports a MySQL table into an excel file. The problem I am having is the column (header) names are not showing up in the final .xls file. I instead get the key value 0, 1, 2, etc. Here is the section of the code that should write the actual names. I can't figure out what's wrong. It looks good to me. Am I missing something? Code:
Upload Images With Names
Is there a way that I can upload an image to a directory on my website and have the image name recorded into a database field without having to create a separate field for that name?
Reading File Names In A Directory.
I'm quite new to PHP, just getting my feet wet really, and I was wondering if I can scan a directory? ie. Counting all files in a certain folder with a ".txt" extension or maybe all files in a folder that contain "news" in it's name.
Displaying MySQL Column Names Using PHP
I'd like to be able to display the column names of a table on a page. Is there a way to read that information in using SHOW? And then to display that information again? Or would I have to store these names in a seperate table and display these values? I tried this, but it sure didn't work: $result = mysql_query ("show columns from industries"); print ("<table>"); if ($row = mysql_fetch_array($result)) { do { print ("<tr><td bgcolor=#cccccc>"); print $row["field"]; print ("</td><td bgcolor=#cccc00>"); print $row["type"]; print ("</td><td bgcolor=#cccc00>"); print $row["null"]; print ("</tr>"); } while($row = mysql_fetch_array($result)); } else {print "Sorry, no records were found!";} print ("</table>");
Listing Field Names - Confusion
I'm trying to simply list the names of fields within a certain table. On another page I figured out how to list the available tables within a database, using the list_tables & table_name, so I figured I could do the same using the list_fields & field_name - but it doesn't seem to be working. Code so far: (works with table list/name) <? $connect = mysql_connect("localhost","login","pass"); $result = mysql_list_fields($db,"tablename"); $i = 0; while ($i < mysql_fetch_array($result)) { $tb_names[$i] = mysql_field_name($result, $i); echo "$tb_names[$i]<br>"; $i++; } ?>
Duplicate Variable Names In The URL Need To Be Put Into An Array
I have a url with duplicate variable names and I need them to be dumped into an array. For example if I have http://www.google.com?boo=0&boo=1&boo=2 I want to have an array that is boo[0] = 0, boo[1] = 1, boo[2] = 2 How do I do this? I know $_SERVER['argv'] will grab everything after the '?' in the URL, but I don't know what do from there.
Building Variable Names Automatically.
I have written a script that will go through a directory and find certain files that are sorted in categories. The name field in the form will be generated with a while loop where the name will look like: name11 name12 name13 name21 name22. and so on. Now I want to retrieve these values and store them into the database in the script where they are passed to. How do I put this into a while loop when I only know the $name part. The maximum value of the other two are passed along, but I do not know how to put it together as one variable. If I try $name$num1$num2 it won't work aswell as putting into quotations. I can see why it doesn't work, but I can't come up with a solution for it. basically I want to build $name11 , $name12 , $name21 out of what I have and then I can retrieve it. Let me know if you don't understand what I tried to explain and I will clarify it for you. The directory can contain up to 500 files.
|