Evaluating A Concatenated Variable
I have a form with 10 select boxes. The boxes are named "select1", "select2", ..., "select10". On the action page, I would like to be able to use a "for" statement to loop through all 10, since the action taken on each is identical. However, I am unsure how I can evaluate the each variable dynamically. It's probably easier to show.
Page 1:
<form>
<select name="select1">
<option value="blah1">blah1
</select>
<select name="select2">
<option value="blah2">blah2
</select>
etc. etc. etc.
</form>
Action Page:
<?
for ($i=1;$i<=10;$i++) {
$tmpValue = $select . $i; <---- This is the question
}?>
In this case, for i=1, tmpValue becomes "select1", not the evaluation of this variable, or "blah1". How can I assign the value of the variable select1 into tmpValue while using this for loop?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Fopen A Concatenated String
I'm trying to modify the SMS API kindly provided at Sourceforge (http://sourceforge.net/projects/sms-api/) to something that will send WAP PUSH messages. I have tried my best to modify it as much as I can without changing the essentials, but for some reason, I keep receiving an fopen error built into the script that informs me the script has died. Code:
Concatenated Strings In Class Vars
Another thing that's been bugging me for a while.... In classes in php 4.3.4 var $x = "string"; // no problem $y = "string" . " that is a bit longer"; var $x = $y; // no problem var $y = "string" . " that is a bit longer"; // parse error (unexpected ".") Have they fixed that in more recent versions?
Evaluating Strings...
In php, I have an array called "q". The elements are: $q[0] = 2 $q[1] = 4 $q[2] = 5 $q[3] = 3 I'd like to be able to loop through this array via a While loop, and echo the contents of these array elements back to the screen. When I try something like: for($i = 0; $i < 4; $i++) { echo $q[i]; echo eval("$q[i]"); echo eval("$q[" . i . "]"); } I get the "String" instead of the "Contents". For example, the output is $q[0] instead of 2, $q[1] instead of 4, etc.
Evaluating Php Tags/documents Outside Of Web Server?
I need to generate and send multiple xml documents over a socket. Is it feasible to use php as a templating language for these? How would i go about that? I figure i _could_ make them into 'normal pages' and fetch the contents using some http library, but that doesn't sound too elegant. There has to be a better way?
Evaluating Array And Skipping Certain Results
I'm having a brain freeze on this. I have a script where I am reading the contents of a file into an array. I have that up and working with no problem. Then I'm exploding the array using while ($line = fgets($fd, 4096)) { $arrayData = explode("-", trim($line)); } Works fine. But what I want to do now is evaluate arrayData[2] to see if it contains the integers "00" (that's zero zero) and if it does, I want it to skip that entry. I know I need to set it up with if arrayData[2] == "00" { But I'm drawing a blank on how to get it to skip this entire line in the final results. There may be multiple instances of this happening in each file and I want to skip them all.
I Have A Weird Database Problem: It Is Returning Spurious Rows Withall The Fields Concatenated Into One
I have a PHP program that almost works. I'm running it from the command line and simulating a form using a GET method. That part is working, but I get spurious records with all of the fields concatenated into a single field. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html; charset=windows-1252" http-equiv="content-type"> <title>eqdb_read.php - Read the Equipment Database</title> </head> <body> <small>This document last modified <script>document.writeln(document.lastModified)</script>.</small> <?php $_GET['hostname'] = $argv[1]; // grab [1] because [0] holds the script name FOR DEVELOPMENT ON THE COMMAND LINE ONLY $hostname = $_GET['hostname']; if ( is_null($hostname) ) { ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="GET"> Host Name: <input type="text" name="hostname" /> <br /> <input type="submit" name="Lookup by hostname" /> </form>
Coding To Detect Number Of Students That Evaluating A Person
i really in need of a php script that can ensure SYSTEM able to trace the number of people that log in into the system and evaluating person A and detect that number so that we will know whether person A has been evaluated by all her students?. This is to restrict the number of people evaluating a single person to the exact number of students only. eg: person A teaches 10 students and when all her students evaluate her teaching, the system actually detects the number of student under her that already evaluate her; and if the number exceed, the system will detect 'has exceed the number of students'. what if there are person A till Z? while, the number of students for each person is different? My problem is, is there is a php code to detect the number of people that evaluating the same person (indicate as A) and already fill the quota for evaluating that person?
Getting A File Via Http Or Evaluating A Php File And Getting Its Output
I need to somehow merge two separate web programs written in php together (from the user's perspective). This solution won't be perminant, I just need something done quickly. I was thinking of two different approches. One would be to download a processed version (modified so it will create validating html with the page it's being embeded in) of one of the programs with the other, then just use print to embed it in the page. I couldn't find out how to get a file via http here (http://us2.php.net/manual/en/index.php). Sorry if I missed this in the docs. The other would be to process the other program and get it's command line output, and print that. If there's a better way to this, I'd be glad to hear it :) Also, I've never written any php before; so sorry if I missed something obvious to someone who has.
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?
What? Assigning A Session Variable Also Assigns The Local Variable?
Alright, In the following code, I expect the printed result to be: DEBUG: frank's last name is burns. Instead, what I get is: DEBUG: frank's last name is burns. Here is the code: $frank = "burns"; $_SESSION['frank'] = "black"; echo "DEBUG: frank's last name is is $frank"; What is coming into play here? I thought of register_globals but I thought that only dealt with GET, POST, REQUEST, etc.
Passing Multiple Variable Errors...last Variable Vanishes.
I have been trying to figure this one out for a few days now and it is starting to drive me mad. I'm sure this is something simple that I have done wrong but I can't for the life of me figure out what is wrong here. Some background. I decided I needed to learn PHP, I really enjoy it but keep getting stuck on things like this due to my lack of knowledge. So I set myself a challenge to write a PHP CMS system using PHP, mySQL, XHTML and CSS. All was going fine (all be it rather slowly) until I tried to write the page to edit articles in the CMS. I have the 'ID', 'title', 'venue' and 'article' stored in the database fine. I can pull entries out and display them fine. I now want to edit them using a browser. So I thought I would use the same form I used to add mySQL entries and change ti so that it loads in the article into the form fields depending on the id. (This is chosen through a link saying 'edit). Code:
Extract Variable From Database, Then Output That Variable.
I have this strange problem (and probably also a strange question). Let's say you set a variable $blah. The variable has 'test' as content. When I write the variable ($blah) to a database (and not the content of the variable 'test') and I want to output the variable again, I get $blah as output. And not 'test'. PHP Code:
Changing Variable Folder Names To Php Variable
Let me just show you quickly what I mean: The site url: http://www.nothing.com/vr/ will then redirect to http://www.nothing.com/index.php?sec=vr I'm just wondering if this is possible. The folder after the domain isn't an actual folder, but rather a pseudo one, which is then used in a varible. Another example: http://www.nothing.com/test/ -> http://www.nothing.com/index.php?sec=45&desc=test The "folder" has to be variable and so cannot be an actual folder.
Session Variable Becoming Linked To Post Variable
Basically i have a user id stored in session variable eg user_id =1. I have a simple forum that i created myself that inserts this session variable into the db with the persons entry. eg insert into forum value (session[user_id],'$_post['content']); This is all working fine until i go to edit this post from say the moderator account. I set the user_id for the "replace into db" initially to my session value unless i have selected to edit someone elses post, then i set it to the value submited back from the <form action=self> i get as far as selecting the contents from db only for the session variable holding my id to change to the value of the user_id selected from the db. Code:
How To Refer From One Variable To Hidden Variable?
I have started with my php source code shown below, and how can I refer from one var to hidden var? ---------------------------------------------------------------------------- if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO users (UserID, UserName, Password) VALUES (%s, %s, %s)", GetSQLValueString($_POST['UserID'], "int"), GetSQLValueString($_POST['UserName'], "text"), GetSQLValueString($_POST['Password'], "text")); mysql_select_db($database_SHHConnection, $SHHConnection); $Result1 = mysql_query($insertSQL, $SHHConnection) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO holidaymaker (HMID, Name, Status) VALUES (%s, %s, %s)", GetSQLValueString($_POST['HMID'], "int"), GetSQLValueString($_POST['Name'], "text"), GetSQLValueString($_POST['Status'], "text")); mysql_select_db($database_SHHConnection, $SHHConnection); $Result1 = mysql_query($insertSQL, $SHHConnection) or die(mysql_error()); } <input type="hidden" name="UserID" value=""> <input type="hidden" name="HMID" value= ""> ---------------------------------------------------------------------------- The "UserID" is generated by MySql with auto_increment.[color=blue] >UserID int(4) auto_increment primary key,[/color] Assume that I want to add new user and the value for UserID is 5 (after auto increment). Then, I want HMID refer to UserID, the value of HMID is also 5, thats mean HMID = UserID, how can I do that? What is the command?
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.
SQL SELECT Using Variable Unless Variable Is Empty
Iv got a form where users input details that are then used as search criteria and it all works fine as long as all the details are enterd. But if a variable is empty then this blank space is used as search criteria with doesnt match any records and thus creates no results. Code:
Assign Javascript Variable To PHP Variable
i have select option on my website.When i choose select option the value of selecet option which i get in the javascript want to assign to PHP variable .So that i can use that in the query.
Variable Within A Variable Problem ...
i did some searching on these forums .. and tried the 'eval' solution with no success ... here is my problem .. i have a form post that submits to the same page .. then displays a table of the resulting data .. all that works great .. however ... i also need to include a link to a specific pdf file for each record .. i need to do a 'file_exists' to make sure that file is present ... if it is not .. i wat to display "not available" .. i know .. i know .. a simple solution would be to put the links directly in the sql .. but i dont want to do that ... i need to keep the files accesible through the intranet network .. for updates and such .. (its much easier for the bossman just to do it the way he always has .. you know?) .. anyway here is my code .. note .. i have already declared $nidid in the code above through a $_post ... also .. i have tested and it works fine if i put the actual file name in instead of the variable ...
Java Variable Is A PHP Variable
I am trying to create a javascript variable that hold the value or a php variable. The PHP var comes from a database and holds html text. I can do all this correctly but the problem I have is that the html text is multiple lines of code. The JavaScript Variable cannot handle that because the text needs to be all on one line, and since the text is dynamic adding end line code to the JS var is not good. I am not very knowledgeable the JS syntax but I can understand anything you throw at me. Here's what I have: var caltext=new Array() //Set submenu contents. Expand as needed. For each content, make sure everything exists on ONE LINE. Otherwise, there will be JS errors. caltext[1]='<?php echo $CalendarText[1];?>' caltext[2]='<?php echo $CalendarText[2];?>' caltext[3]='<?php echo $CalendarText[3];?>' This code creates text for the calendarday that I have set on an onClick event. This all work ideally. but this is the out I get to the browser:
Variable Name From Variable - Feasible?
Is it possible to define a variable with part of it's name from another variable? For instance you have a variable named var1 with the value of "value1": PHP Code:
Using A Variable Name To Make A New Variable?
Is this possible? Say I have a function, which excepts a variable in its definition... function example($var)....etc Now say I want to add _error on to the end of whatever variable I supply and use this as a new variable name. How could I do this?
Making A Variable From A Variable
I've got a class for producing a tab style look in html, everything is working, but I want to be able to pass a variable to the class and what the contents of the variable made into another variable for the class?!?! PHP Code:
Part Of Variable Name Is Other Variable
I'm writing a portion of a size that allows users to custom configure a product. One of our categories is "Video," and we give users a choice of including up to 8 diffent video devices. Because (a) these 8 menus are all the same and (b) we may change the number in the future when new hardware allows us to support more, I wanted to generate the menus using a while loop. Code:
Variable POST Variable
I'm using a class discussed in one of the DevShed tutorials "How to build an extensible form validator class". However, I need to modify one of the private member functions. PHP Code:
Finding A Variable Within A Variable
Is there a way to find a variable within a variable between two spots? Not exactly KNOWN spots... but imbetween two chars like: Code: $variable = "this is junk<but anything here is good>but this is junk again, but i'll need this later..." Is there a way to split that into three seperate variables, the first being before < and the seccond imbetween < and > and the third after >?
Variable Inside Variable?
I need $count to be inside $_POST['Q$count'] as in the following, but its not working. ++$count; echo "For question # $count, "" .$question->q. "", your answer was {$_POST['Q$count']}. "; I've tried a few different things, but can't get it done. What am I doing wrong here?
Foreach, Use A Variable In Variable Name?
If I have a foreach like: foreach($array as $key => $value) And I want to make a variable like: $var_$key = ..... I want the $key yo be replaced with the key from the array, what do I do to make it work?
Variable With The Name Of Another Variable?
How do you name a variable after another variable? I mean, I have dropdown menus of which the names are generated from a db, so I have for example $processors, $motherboards etc. for the categories processors, motherboards... How do I call these variables in a loop? I should have something like $($cat) but that's impossible...
Variable
If I have : $a =1; $b =2; and I want to define new variable: $1 = "PHP"; $2 = "JSP"; How can I do it ? I try $$a = "PHP"; $$b = "JSP"; but it has parse_error.
Variable Vs URL
It's probably very easy, but I cannot find my mistake: page1.php <?php echo "<a href=page2.php?vartrans=5342>Clic</a>"; ?> page2.php <?php echo "$vartrans"; ?> When I click on the link on page 1, page 2 appears on the screen but with the following error message: Notice: Undefined variable: vartrans in c:program fileseasyphp1-7wwwpage2.php on line 2 What's my mistake? I use php 4.3.3.
Variable In A Variable Name
I have an entry page which can be used to key in data for ten people. My assigned variables for each field are in line with $personage1 $personage2 ....etc $personage9 $personage10 and so on. (I have 8 fields for every person, 80 values in all). To simplify my code and make changes easier I would like to create and use these variables with a variable "x" in the name This by recycling the code with $personX in and changing the value of x and running the code ten times. Probably in some kind of do while loop (fairly new to php, but I have been using Excel VB for years and am familiar with the syntax and effectiveness of Do While Loops). 1) how do I put a variable in a variable name? 2) syntax for a do while loop with this variable name. The beauty is if I can get this working I can make x=1 the first time adding one each time and using value of X in my while statement.
Value Of A Variable Within A Variable
I'm getting an sql query from a database record. Into the query i insert a [$myVar] reference to an existing, global variable available from the current session. When I try to submit the query as is, it complains that [$myVar] is not an entity in the table. i wrote a function (which i will use in all such cases) to extract the [$myVar] from the string. The name of the php variable will change, and there may in fact be several different variables in a query. I need to substitute the actual value of the global variable i extract, for the query. e.g. The variable is $myVar = 1, and $varHolder = "$myVar". I have tryed $$varHolder and ${$varHolder} and $$varHolder = $myVar with $$varHolder and ${$varHolder}.
Variable
I'd like to be able to do the following: $thedate = date('Y-m-d G:i:s', strtotime('-7 days')); except replacing the 7 with a variable like this: $thedate = date('Y-m-d G:i:s', strtotime('-$daysBack days'));
Variable In A Variable
if i am trying to make a variable $day_' . $i . ' and i have $i in a for ($1=1;$i<31; ++$i) - how do i get the variable $day_ to have the $i variable on the end? (the above doesnt work btw) I want to be able to have: $day_1 = Monday $day_2 = Tuesday etc. Kinda thing - where i dont have to define 1,2,3,4
How To Get The Variable Name?
I'm writting a debugger class. It basically takes an arbitrary list of arguments and echos something similar to a var_dump but is smart enough to know if it is in HTML or CLI so it won't echo <br /> to the shell, or try to use a newline in the browser. php Code:
Variable Not Set..
I'm making my first PHP page and got stuck already. Its going to be a guestbook. My code: <HTML><HEAD><TITLE>My guestbook</TITLE></HEAD><BODY><H1>Welcome</H1><H2> Write something:</H2><form action="<?echo $PHP_SELF?>" method="POST"> <textarea cols=40 rows=5 name=note wrap=virtual></textarea><input type=submit value="Send"></form> <? if(isset($note)) This is as far as I get - $note is NOT set when I get here, why? ..... etc. The rest of the code seems to work, if I hardcode $note = "bla" the guestbook saves it and shows it next time etc.
Getting The Variable Name In Php
I have created a function, it gives more readability compared to the print_r function. As of print_r, it works both for array or single variable. I just want to add in it, the opton to view the variable name for the case of non array variables. Also I want to show the array name. Is there any way that the variable name that is passed to the function can be displayed. function formattedoutput($object) { echo "<table style='border:1px #cccccc solid'>"; if(is_array($object)) { ksort($object); reset($object); foreach($object as $f_name=>$f_value) { echo "<tr><td valign='top'><div align='right'>"; if(!$f_value) { echo "<font color='red'>"; } echo $f_name; if(!$f_value) { echo "</font>"; } echo " :</div></td><td valign='top'><div align='left'> "; if(is_array($f_value)) { formattedoutput($f_value); } else { echo $f_value; } echo "</div></td></tr>"; } } else { $f_name = ""; // variable name $f_value = $object; echo "<tr><td valign='top'><div align='right'>"; if(!$f_value) { echo "<font color='red'>"; } echo $f_name; if(!$f_value) { echo "</font>"; } echo " :</div></td><td valign='top'><div align='left'> "; echo $f_value; echo "</div></td></tr>"; } echo "</table>"; }
Variable Of Variable $$, ${ ...
i m trying to find how to access a variable of variable (which is an image) i want to know the size of the picture the name of the picture is photo1 next one is photo2, next one is photo3 ... for ($i=1;$i<$MAX_PHOTOS;$i++) { $photo='photo'.$i; $$photo_size; //don t work }
Keep A Variable.
How can I go about using a $variable on multiple pages? Let's say a user logs in and then goes through three other pages. I want to be able to use a certain variable over and over again in all those pages.
Add Variable To Variable Name
confuzing subject, but that's the thing I'm trying to achieve. For example: $a = "Hello"; $b = 1; I want to change the name of $a to $a1 where 1 is value of variable $b!
Php Url Variable
I have an attendance page which I would like to take attendance over a certain time period. The dates will come from the url which will be something like this... attendance.php?start=2007-01-01&end=2007-06-31. In my code that follows this, I have tried to insert these variables into the code, but I can not really seem to get this to work. The dates in my table are yyyy-mm-dd format. I need some help in trying to figure how to make this work. The start and end variables will come from another page where the user specifies the start an end date. That is easy enough, I just am having trouble getting this bad boy working. I would like the sql statement to pick up the information over the time period specified. Code:
Odd Variable Bug
I am using PHP 4.3.4 and found something strange with a variable name. When I try to use "$company" variable (lowercase), I get odd behavior from that variable. The name of my php file is "company.php" but I didn't think that php associated them together. The behavior is that "$company" will take on values of the previously accessed $_GET variable. I fixed it by using "$company_info" variable instead but I would really like to know why the "$company" variable seems to be a landmine. The code includes the core Pear libraries and the pear IT library but nothing else. I thought that system variables took the form of "$_VAR"? If anyone has run into odd behavior like this before let me know so I can find out what variables to avoid in the future.
|