How Do You Assign A Various Number Of Variables?
I'm struggeling with a small search engine here. I'm trying to put everything together myself, but I have a problem.
I've made a small form where search-words can be entered. This string is put into a variable $search. Then I've split this string up in pieces using the SPLIT command. something like this:
list ($one, $two, $three) = split ('[ ]', $search);
This works very nicely, but there is only one small problem. I can't possibly know how many search words will be used. It could be only one, but it could very be 10 or more (although unlikely). I thought about creating 10 variables, and in case they use less, they are just blank, but then if I use a OR function between these empty variables, the complete database (MySQL by the way) is called for.
I don't know if you're getting the picture, but I want to know how I can assing a number of variables not knowing the amount in advance.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Assign A Number From 1 To 9
I was wondering how to assign a number from 1 to 9 to a $variable which is used by a random feature if random is possible in PHP ?
Trying To Assign Number To Image..
I am working on a countdown script that will display the number of days to go to an event. I am after a graphical version. I have the code working that displays the amount of days to go to the event but I now want to display that number as a graphic. Whats the way of parsing the varible with "19" in it to make up a graphic? I have graphics for digits 0 - 9 made. Do you use some sort of array?
The Same Operation On A Number Of Variables.
I have a big number of variables, mostly data from the form. I want to convert all empty variables into "NULL". Obviously for each variable I could write: if (empty($a)) $a=="NULL"; if (empty($b)) $b=="NULL";...and so on.... But let's say I have like a hundred of them. Is there any way to write it in just a few rows ???
Multiply A Number Of Variables...
I been wondering which way is the correct way to code this .... i have 5 variables i need to add together then multiply by 5. So i got this: $Total = $StrengthInput + $DexterityInput + $DefenceInput + $AgilityInput * 5; Then i wondered would it be better to do this: $Total = $StrengthInput + $DexterityInput + $DefenceInput + $AgilityInput; $NewTotal = $Total * 5;
Get Unknown Number Of Variables From POST Or GET.
I am trying to create a page that redirects users to an advertiser's page. The reason for the redirect is statistics about who clicks where. The situation is simple when I only need to redirect them to a page, but some of the ads on my site include forms which put data in either POST or GET and I need to know how to allow my redirect page to take that data from POST or GET, whatever that data is, and pass it on to the page that the data were intended for. I think that once I get the data I can simply create a hidden form, on the redirect page, with the data from POST or GET already in it. However, I don't know how to get an arbitrary number of variables from POST or GET.
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?
PHP 5 Re-assign $this PROBLEM
Just a quickie, in case it's been covered, like a million times or something. I'm self taught, and thought I was being pretty clever when building a "messaging" class. The idea was to abstract "html email", "text email" and "sms message" up a layer into a "message". To get a message started, I call on something like this: $msg = new Message("sms"); Message (which re-assigns the $this variable) then looks something like this: class Message{ var $message_hash; var $message_path;//this can be changed, in case stuff is moved in future... function ryan_Message($type=""){//starts the whole thing switch($type){ case "html"://this means an html email include_once("HtmlMessage.php"); $this = new HtmlMessage(); break; case "text"://this means a text mail include_once("TextMessage.php"); $this = new TextMessage(); break; case "sms"://this means an sms message include_once("SmsMessage.php"); $this = new SmsMessage(); break; }// end switch }// end function }// end class Each class has methods that are named the same, but act a little differently, so, basically, I can use the same set of commands to compose a message and send it, regardless of what type of message it is. Things work fantastically under php4, but I know that when I swap over to php5, it's going to throw a hissy fit, because reassigning $this is not allowed. Aside from going around the Message class, and just starting messages of a particular type from scratch: Is there some sort of cunning retro-fit I could do to the Message class, so I don't have to trawl through thousands of lines of code?
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.
Assign Value On Click
is there a way to change the value of a variable when a hyperlink is clicked? like im include()ing a variable $content. and when you click it changes from URL to links or whatever?
Assign Value To The Link
I am creating a order-online application. I create some links in my html file. And in my table that I created by mySQL, there are some fields including picture_id, picture_name. What I want is to assign the picture_id to the link so that the picture_name will be selected (using mySQL) when the link was clicked. Can someone tell me how to write PHP code to assign the picture_id to the link?
Assign Japanese String To Var
Following code contains japanese string that is assigned to variable $str. code ============= <?php $str = "$B%0%C%I%P%$%T%+%=(B"; ?> ========= When i am executing above program it gives me error as following. Parse error: parse error, unexpected $ in /var/www/html/bhavin/mohla1.2.2/b.php on line 3 Do anybody have solution for the above problem. How can i assign above japanese string($B%0%C%I%P%$%T%+%=(B) to variable without error.
Extract 5 Rows Assign Name
I want to extract the last 5 thumbnail names added into my products table and assign each one a variable, for example: thumb0452 = '$thumb1' thumb0234 = '$thumb2' thumb0678 = '$thumb3' thumb0876 = '$thumb4' thumb0123 = '$thumb5' I assume I would start with something like this: PHP Code:
How Can I Assign Output To A Variable?
I'm trying to send an email and would like to put the output of some of my script into the body of the email. Here's the part that needs to be executed: PHP Code:
Fatal Error: Cannot Re-assign $this
i am running a code created with php4 on a php5 engine and I am running into problems with the $this . In php4 its a variable and in php5 its a ref to a class object (if am right) I get the following error in a class "Fatal error: Cannot re-assign $this in {path}" which is caused by this line "$this = new $db( $serv, $user, $pass, $dbName );" How can i resolve this ? am thinking of renaming $this to something like $this_var but then this is likely not to work.
Assign Table Value As A Session??
someone logs into my application - a login function runs from a pinc file. What is suppose to happen is if the username and password match - it is suppose to assign a session to the username - which is being passed from form and to the first and last name which are in the table for the user. Can I assign a session variable to value in a mysql table? It does properly set the cookie I am assigning on the setCookie line but is is not setting any of the three sessions. Here is the function I am using: Code:
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.
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 ???
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.
Fatal Error: Cannot Use Assign-op Operators
Getting the following error message: "Fatal error: Cannot use assign-op operators with overloaded objects nor string offsets" The PHP file includes one rather substantial array. I tried taking a few lines out of it just in case the sheer size of the array was giving me prolems, but this made no difference. PHP Code:
How Do We Assign 16 Bytes Unsigned Integer In PHP?
We are unable to represent an unsigned integer with 16 bytes memory size. The current integer size is 4 bytes by default. There is no way for us to store large integer in this case. The valid number range is from 0 to 2^128-1 (340282366920938463463374607431768211455).
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();...
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?
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);
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"...
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); }
Replace Hex Number Or Decimal Number In A String ?
String may contain alphanumeric values. What is the bestway to replace a hex number such as 0x122aaa and decimal number such as 5678 with a string "blah" Example: I want to replace below-- wr_thru1 data or mask mismatch!! for addr=0x00000b73a0540 & mdfid:11 with wr_thru1 data or mask mismatch!! for addr=hexVal & mdfid:decVal
Order Number Or Tracking Number
I need to create some kind of random number within a persons session that can be inserted into a customer id column for their orders, customer, and credit card tables. Unless their is a better way to link a customers information together between a few tables besides using auto increment. Things could get screwed up for me if I use auto increment, especially if someone submits their information but does not actually place an order. My question is " How can I create a random order number that can be used within a persons session and will stay the same throughout the whole program for that one person? "
Database Stores Default Number Everytime, But I Havent Set A Default Number??
Im having some problems with my database. Everytime i store a number which is longer than 10 numbers the script or database puts this number into the database: 2147483647. Its does this everytime no mather how i write the numbers and nomather how long the number is, it just needs to be over 10. I have set any default value in the database and to be sure i havent i tried deleting the table, but same thing happends again???
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.
Same Named Variables.. Or Addressing Variables In A Loop
I'm just starting to program in PHP.. fairly new to programming in general... and I've run across a (probably simple) programming problem I hope someone can help me with. I'm sending variable names through an HTTP get that are generated through a foreach loop. The names are along the lines of name1=, begin1=, end1=, name2=, begin2=, end2=.. etc. The number is the number of the current cycle through the loop. My problem is addressing the variables on the next page... namely how do I evaluate those variables in a loop? I want the value of name1.. but obviously for (i=1; i<3; i++) { echo "$name$i"; }; is not working. Is there an easy way to do this?
Passing Variables & Dummy Variables
Hi! thanks for all the previous help - I've made some progress & have dropdowns and a checkbox; however I have 2 probs which I can't figure out: grateful for any further help. THANKS! 1. Not sure how to code so that user can query from just 1 or all of the dropdowns (at the moment unless they select the correct answers from each dropdown - no results!) = defeats the whole purpose of searching. By selecting from menu options user selects from 2 diff tables. [the page allows user to search catalogue by selecting year of release, artist, music type - results from 2 tables need to be selected & sent to mysql. I just don't know how to code it so that user must make an initial selection to get any results, and whichever menu options they choose "add them together" if you like to make a complete query.... sorry my coding just isnt deep enough! A friend suggested using a dummy variable but as I'm a bit out of my depth; I need to get some help! The coding I've done so far;
Passing Variables And Session Variables
I'm currently working on a shopping cart script that works just fine with register_globals turned on but when turned off i get all kind of errors. The following page displays a detail of the book with the "Add to cart" link at the bottom. PHP Code:
Passing My Variables With Forms Variables
how to carry variables onto the next page along with the forms variables. I need to carry my own over too, but when I press submit on the form page only the forms variables carry over, not my own ?? I have two drop down menues on my form that provide two values "start & end" which I require to go with my own variables.I have tried "a href=" link which carries my variables but not the forms variables. <?php echo"<form method=get action=somepage.php?one=$one&two=$two&three=$three&four=$four>";?> also tried <a href=somepage.php?one=$one&two=$two&three=$three&four=$four&start=$start&end=$end
Persistant Variables - Application Variables
In the books I have read about PHP I haven't been able to find any descriptions of how to set variables that persist in the servers memory, in the way that Application variables persist in Cold Fusion. In CF, if I set an application variable then any of the application pages that are run will have access to those variables. And you can put complex arrays of data in the Application Variables and then access these variables at any time, without having to reload those variables for each page when it loads. I expect you can do this is PHP, but I can't find any info about how to do this.
Variables That Change Session Variables
I'm currently writing a mulit-page form app that uses a session to retain data from each form element in order for the user to jump between pages, then the final data is passed to a calculation script. However, I've noticed that if I assign a session variable to another variable, which then performs a mathematical calculation, the session variable changes. i.e. $_SESSION["inflation"] = 4; $temp_inf = $_SESSION["inflation"]; if ($_SESSION["inflation"] =="RPI") { $inflation = $rpi;} else {$inflation = ($temp_inf/100.0);} now it equals = 0.04 How can I take a value from a session and perform operations on it without altering the original session value.
Form Variables To Session Variables
I am writing a small script that consists of two pages: page one displays a bunch of values from a DB (ie. First Name, Last Name, Phone Number). On this page you will find a form that follows this format: <input type="text" name="edit_firstname" size="20" maxlength="35" value='Bob'> <input type="text" name="edit_lastname" size="20" maxlength="35" value='Smith'> <input type="text" name="edit_phone" size="20" maxlength="35" value='5552222'> So when you see the page there will already be a 'default' value in each line (which is information extracted from a DB). This works perfectly and has been tested thoroughly. On the second page I have the following code: $editfirstname = $_POST['edit_firstname']; $editlastname = $_POST['edit_lastname']; $editphone = $_POST['edit_phone']; What I am trying to do is this: the default value for edit_firstname from the form is 'Bob' by default, but the user can change this in the input field on the first page. This value, whether changed or unchanged, should then be stored as edit_firstname and by calling up the function $_POST[''] on the second page I want to transfer the value to the variable $editfirstname. However, it seems that $_POST['edit_firstname'] and the other fields do not return a value at all, hence $editfirstname = '' or $editfirstname = 'NULL'. I have never tried to do things this way before.
Building Variables From Variables
I am trying to build a variable, that will have a amount of that variable, can someone describe/explain in detail the best method to do this?
Number For Each Value
What I am doing is getting values from a database and what I need to do is print out each of them and print a number for each one, like this.
Odd Even Number
if I have a for loop : for ($i=0; $i<count($replyDetails); $i++){ ... bgcolor = 123 (OR 456)... ... } and will show bgcolor = 123 if $i is an even number or $i=0 and will show bgcolor = 456 if $i is an odd number
Number St Nd Rd Th
How can I have a number variable and see whether it needs a st, nd, rd, or th at the end?like 1st, 2nd, 3rd, 4th... I originally thought I could select the last number but for example if it equaled 11, 12 or 13 the idea wouldn't work as they take th.
Number Of Records
I want to find out how many records, but I am using LIMIT in mySQL so if set the limit to 20 and I have 56 records then it will display 20 instead of 56. I have been using: mysql_num_rows What should I be using?
Help With Getting A Number Of Posts
Hi, I've been trying to make a message board of sorts, and I'm having trouble getting the number of posts in each forum to show correctly. The two tables in mysql im trying to use in order to do this are a table called info, and a table called forumlist. Forumlist has two columns, one with forum_id, and one with forumname. Right now it has three entries, Test Thread, Game Thread, and Discussion Thread, with forum_ids of 1, 2, and 3 respecitively. In the table info, there is a bunch of columns pertaining to the author, the description, but those don't really matter, the one column that does in info is the column forum_id which is an integer I am using to keep track of which thread is in which forum. Right now there is only one entry in the info table, and that has a forum_id of 1. I have been trying to get it to show that there is one total post in the Test Thread, and 0 in the two others, but for some reason it keeps saying there is one in the Game Thread, and 0 in the others. I tried changing the forum_id to 2 in the info table, but then it said that I had one post in the Discussion Thread and 0 in the others. It seems to be jumping ahead by one for some reason. I could use some help, here is my code:
Most Recent By ID Number
Is there anyway to get the 5 most recent links added by using the field ID that I have in my database?
|