Is It Possible To Assign A Whole Function Or Block To A Variable ???
Is it possible to assign a whole function or block to a variable ???
eg.
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
<? if (db_num_rows($qid_p) == 0) { ?>
<li>No
<? } ?>
<? while ($prod = db_fetch_object($qid_p)) { ?>
<p><b><a href="product_details.php?id=<?=$prod->id?>"><? pv($prod->name) ?></a></b>
<br><? pv($prod->description) ?>
<br>$<? pv($prod->price) ?>
<br>[<a href="cart_add.php?id=<?=$prod->id?>">+ Add to Cart</a>]
<? } ?>
How to assign this code to a unique variable ???
View Complete Forum Thread with Replies
Related Forum Messages:
Assign Variable To A Block Of Html Code
Is it possible to assign variable to a block of html code? Something like this : $myblokvar = "<table width="487" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table width="487" border="0" cellspacing="0" cellpadding="0"> <tr> <td><img src="images/bartitle_login.gif " alt="Login" width="475"...
View Replies !
Assign Function Output To Variable??
I've found some references to this topic at : http://forums.devshed.com/showthrea...ion+to+variable but it does not seem to be working for me. here's a snippet... <? PHP function listPeople ($getArray) { foreach ( $getArray as $val ) { echo "$val, "; } } $foo = listPeople($splitDirector); ?> The function works, and as you can see i'm simply trying to assign the output of the function to $foo. But instead, the output is written to the page where I assign it... like a print or echo statement, and the variable $foo is empty.
View Replies !
Assign MySQL Function Result To PHP Variable
I know to use: mysql_fetch_row($result) to convert a row from a SQL query result set into an array for use with PHP. but in the case of SQL queries that return one value, such as calls to MySQL functions, is there another PHP mysql api function I should use. For example, right now I use a "workaround" technique from PHPBuilder: $result=mysql_query("SELECT COUNT(*) FROM tablename"); list($numrows)=mysql_fetch_row($result); Rather than using this "workaround" code is there a way to simply assign the result of the MySQL function query to a variable. $result=mysql_query("SELECT COUNT(*) FROM tablename"); $numrows=mysteryfunction($result);
View Replies !
Assign Value To Variable
Is there any way I can use a function to create a variable and assign a value to it? I have a Perl script that returns some LDAP information: sn=Shore givenname=Mike logintime=20041008153445Z logindisabled=FALSE Instead of parsing this text and assigning the values, I was wondering if a function exists where I can pass a variable name and a value, and the variable would be created. ie. somefunc("sn", "Shore") Would create the variable $sn and assign the value "Shore" to it.
View Replies !
Assign To Variable
I am trying to take data from the database and assign it to a variable but i'm not sure how this is the code ive been trying $sql = "SELECT Name FROM Names WHERE Name = 'Peter'"; while($row = @mysql_fetch_array($sql)) { $var == $row['Name']; }
View Replies !
Block Variable
How do you do a block of code for 1 variable, so that I can keep all of the variable information in a nice order and tell what is going on when I go to edit it? I don't really care if it is parsed in a nice neat order or not, but just so I can tell what I am doing when I edit the PHP. $navigation = '<ul id="nav"> <li><a href="index.html">Home</a></li> <li><a href="link1.htm">Link 1</a></li> If I just do ' and ' at the beginning and ends, it doesn't capture everything...how do I quote multiple lines and have them all belong to 1 variable?
View Replies !
Ways To Assign A Value To A Session Variable.
I am wandering which way to assign a value to a session variable exist. Which of the following examples will work. Example #1: session_start(); session_register("ex"); $ex = 2.0; Example #2: In first.php: session_start(); session_register("ex"); In second.php: $ex = 2.0; Example #3: In first.php: session_start();...
View Replies !
Assign Variable From Database Field
Is there a way to assign a variable from a database field? I'm thinking along the lines of $make = $row_rsList['make']; $model = $row_rsList['model']; then they'll switch out based on my SQL WHERE statement. This valid syntax?
View Replies !
Assign Userid To A Session Variable
When a user logs into my system, i assign their userid to a session variable [php] $_SESSION['userid'] = $myrow[0]; [php] and then a user logs out, i do the following [php] $_SESSION['userid'] = '' session_write_close(); [php] so, when a user clicks on a link to a page they should only see when logged in, i do the following test [php] if (isset($_SESSION['userid'])) { header('Location: members.php3'); } [php] but the logout does not seem to work for some reason? userid still seems to be set after running the logout script, any ideas? am i doing something silly?
View Replies !
Assign Function To Class....
Is it possible to assign some functions to a of a class? class loginClass { function initialize() {$something} } function CheckLogin() { $something } $login = new loginClass(); $login->onLogin = CheckLogin(); $login->initialize(); where the CheckLogin function will only be run during the initialize of the class, not during loading of the whole document.
View Replies !
Assign A New Value To A Variable Passed From An Html Form
I'm trying to assign a new value to a variable passed from an html form to a php3 script. I'm using an if statement to evaluate variable 3 to see if it is equal to a specific string, if it is I'm reassigning variable 2 to be variable2+variable 3. if ($question3!="select days") { $question2=$question2+$question3; } This is the statement. It keeps giving me a parse error and I can't seem to find the right documentation to show me how to combine two string variables.
View Replies !
Multi-Dimensional Arrays - Assign Variable
It's a simple question, but I'm just not getting it. I have two files: <?php $precinct = array ( array ( number=>2324, centerlat=>-122.31705665588379, centerlong=>47.710367959402525, etc... <?php include ("precinctdata.php"); $filename = $_GET['id']; $number = $precinct[filename-1][number]; etc... I want to assign the value of "2324" to the variable $number. I've done this with arrays that start with number=>1, 2, 3, etc., but not successfully with specific values. What am I missing?
View Replies !
Make Ip Block Function
I would make a ip block script for my site. The blocked ip are stored in a file. I have made the following script. Why does this not work. The file entries must be stored in a array and after that i must check all the fields in the array. Please help... <?php $ip = $_SERVER['REMOTE_ADDR']; $bestand = "ipblock.txt"; $open = fopen($bestand, "r"); $iparray = file ($open); $n = 0; while ($n < count($iparray)) { if ($iparray[$n] == $ip) { print ("NOT"); else { print ("YES"); $n++; } } ?>
View Replies !
Block The Phpinfo() Function
We have authorized ftp access to our clients apache-php server. Alas our clients administrators has recently decided to block the phpinfo() function. Is there any way to simulate that built-in function. Maybe somebody has the same function written in php.
View Replies !
Assign Variable Name As Variable
I want to be able to create a foreach loop that will go through all the intended POST variables and then assign it as a standard variable. For example, I want to have $username = $_POST['username'] without even knowing username exists in the context of the foreach loop. Code:
View Replies !
Variable Scope - Function In Function
Here's something that I can't manage to find explicitly documented. In the following snippet: function outer() { global $a; function inner() { global $a; echo $a.Ƈ<br>' } $a = 's' inner(); echo $a.ƈ<br>' } outer(); ?> If either of the globals statements is removed, the variable is not accessable within inner.
View Replies !
$variable->function();
I'm going to be using this symbol a lot and I don't know what it means. I was just wondering what the arrow ($variable '->' function() means in the command above.
View Replies !
IF Function Within Variable
I am using a submission form to obviously submit a form from my website. I want to be able to control what variables are sent by using an IF function, however as I suspected, I am not having much luck. I KNOW that this code is horribly incorrect, but is there any possible way of doing what I want or will I have to use separate submit forms? PHP Code:
View Replies !
Variable Within A Function?
How do I do a variable within a variable within a function? in the code below, $client is defined in client.inf. If I express $client (as shown), which is the same as the true directory name the script doesn't work. $client=񟍳' Warning: Unable to create '/home/httpd/html//upload/img/test.jpg': No such file or directory in /home/httpd/html/0003/upload/process_upload.php on line 8 failed to copy file However, if I explicitly express $client (ex.?' as the client directory) it works fine. not using an alias under Apache, permissions are wide open during testing, and $client echos in the same script (process_upload.php4) that I receive the error message Code:
View Replies !
& Before A Variable / Function Etc
I have been looking around for a tutorial about the effects and reasons for placing an & (&) before a variable, function, etc in php. Obviously it isn't easy to find one as its difficult to search for the one character. could someone explain what the & symbol does or point me to a post / site that does.
View Replies !
Those Variable Through Function
I want to through a variable through my function and have it come out the other side with updates using preg_replace. So far it works if I were to echo it from inside the function, but if I want to put the variable back together with the updates so I can use it down the line further in other functions how can I do it? function TEST($a, $b, $c){ $result = preg_replace($a, 3, $b[$c]); return $result;}
View Replies !
Getting A Variable From Outside A Function!
I´m working on a script wich outputs xml data from values in a database, and i want to reach a variable from inside a function from another function, i want to do it this way because i have set all a code for a $query variable and want to take the results from that query and use them in another function, this is my code:
View Replies !
Function To A Variable
it possible to pass the output of a function to a variable, as is possible in Unix shells. IE: PHP Code: $string = `echo "Hello, world!";` echo $string;
View Replies !
Variable From Function
I have this in a function $result1 = $db->sql_query("select id, team, pts from ".$prefix."_huntteam ORDER BY team"); echo "<form method="post" action="admin.php">" ; echo "<center><b>"._HUNTNAME.": </b><SELECT NAME="chng_user">";
View Replies !
Variable From One Function
PHP Code: function form_error($error) { Â Â Â Â if (!isset($error_count)) { Â Â Â Â global $error_count; Â Â Â Â $error_count = 1; Â Â Â Â } Â Â Â Â if ($error_count == 1) { echo "<strong>Error:</strong><br />"; } Â Â Â Â echo $error_count.': '.$error."<br /><br />"; Â Â Â Â $error_count++; } This function simply formats form input errors and counts them. Except it doesn't do the counting part. each time the function is called, it seems that $error_count disapears and it creates it again. I'm confused by this, because I thought variables stayed around from function to function.
View Replies !
Function Through Variable
PHP Code: function output1() { Â Â Â Â echo "Today is ".date('Y-m-d'); } function output2() { Â Â Â Â echo "Time is ".date('H:i:s'); i know how to call the function through variable: "output".$_GET['id']; //i had try this.
View Replies !
Cannot Re-assign $this ...
I'm one more guy having the cannot re-assign $this problem. someone left a php4 file here containing the lines |function linkbar() |{ |if(func_num_args() == 1) |{ |$this = func_get_arg(0); |return; } ... |} inside a php4 class definition. func_get_arg(0) in this case delivers an object - working fine in php4. I struggled a bit with the & referencing (while not really understanding it and the problem) but gave up. how must I modify the code to get it to work in php5?
View Replies !
How Do I Pass A Variable Outside A Function?
I'm building a form with php validation, and I'm quite pleased with what I have thus far, but I have a problem - I can't get it to stop! When there are errors in the form it works beautifully, highlighting the missed fields while retaining the info in the filled-in fields. But if there aren't any errors, I can't get it to take the next step and insert the values into MySQL database. PHP Code:
View Replies !
$variable = Function($var2) == Possible?
I'm not sure if it's my function thats not ideal for this task or not, but still I have to ask to be sure. I have a function that take date stored from an MySQL database, and format it into this : "dd month year" and echo it out in the page. IE: 2002-01-18 would be 18 Jannuary 2002. what I need is to set the function into a variable. I've tried numerouse ways of $varname = split_date($date_to_split) ... with " and "" The function: PHP Code:
View Replies !
Pulling A Variable From A Function
Can you pull a variable from one function to another. more specific using a switch case 1 pulls a variable out when displaying a page.ok on this page a link calls the same page but using case 2 this time. I know that the switch goes through all cases before executing, but is there a way to hold a value so it can be used in the next case.
View Replies !
Calling Function By Variable....
I have a function that pulls last 10 records from the database and formats it appropriatly then I need to assign that output into a variable named $content. That variable is used by other scripts when reffered to. Now my question....can I assign function call to the variable name...like that?? $content = any_function_name(); If so, how can I make sure that the function is not called right at the load of the page, but only upon the echo of the variable.
View Replies !
Variable From Function Not Printing
I have a function that gets the information from the logged in user from a database. I use this in another function to print this information but this doesn't work. This prints the firstname of the user, it should but it doens't. PHP Code:
View Replies !
External Variable In A Function
I have a simple variable like this: $test="sometext"; The variable is defined before a function. when I use the $var in the function, it doesn't "see" it. If I use the string "sometext" it works fine... but the string changes, so I need to use a variable... are you allowed to use a $var inside a function that was defined outside a function?
View Replies !
Undefined Variable In Function
I have a script with those good ol checkboxes and those good ol undefined variable errors when a checkbox is not checked. I have managed to fix this problem in all but one of my scripts where I use a function to update the database through an include. Here is the script:
View Replies !
Assigning Function To Variable
I've been trying to pass a function name to a variable to store it and run it later.. here's a snippet: $this->timer(1,"ping",$this->action->ping(),REPEAT); Not putting "$this->action->ping()" in quotes runs it, however putting it in quotes results in the error: Code:
View Replies !
|