Variable variables, PHP and your _ PHP Tutorial

Source: Internet
Author: User
Variable variables: PHP and you. In a recent project, I found a new concept about using variables in PHP. In my program, I need to update multiple records at the same time on a page. in my recent project, I found a new concept, about variables used in PHP. In my program, I need to update multiple records at the same time on a page. after a long time of painstaking thinking, the concept of a variable (variable) suddenly emerges in my mind, and all the confusions are swept away.

Introduction

What is a variable? According to the PHP Manual, a variable refers to the variable name that obtains the value of a variable and uses it as the variable name of another variable. This expression is rather straightforward and easily obfuscated with the word "variable" in a sentence. For a simple example, you define a variable --- x equals to this --- and then define a variable, which means that you use the value of x as the name of the new variable. In this example, the value of this new variable is cake. PHP is used to represent the following:


$ X = "this ";
$ X = "is cake ";

?>

The $ symbol represents the variable in PHP. Now we can reference these two variables $ x and $ x in two different ways.


Echo "$ x $ {$ x }";

?>


Echo "$ x $ this ";

?>

The above two programs will output this is cake. Note: In the echo statement, $ x is written as $ {$ x}, which makes PHP know that the variable you want to output is not a $ character or $ x variable.

Are you still confused? Oh, maybe. do you want some more in-depth and useful examples? In the next section, I will show you how to use variable variables to edit multiple records on one page.

Example

Assume that you already have a MySQL database that stores links to sites you are interested in. the database has a table named submissions. The fields are as follows:

SubmissionID
PostedBy
Link
Description
Approved

Now you want to display all the created but not recognized links in the table. this editing page should be able to correct some input errors, use the appropriate single-choice button to set whether to accept each record, and then submit the updated record to the table at one time.

First, when you extract and display all records from the database, you must set a unique name for each record, this will allow us to repeatedly identify the values of each record during submission. The code is as follows:


// Initialize the variable counter

$ Index = 0;
$ Index_count = 0;

Echo" N ";
Echo"




















Bytes. In my program, I need to update multiple records at the same time on a page, in...

N ";Echo" "." N ";/*********Assume that records have been retrieved from the database to an array.$ Myrow = mysql_fetch_array ().The following do... while loop assigns a value for each $ xstr variable according to its name and connects the value of $ index to the end, starting with 0.In this way, for the first time in this loop, the value of $ SubmissionIDStr is SubmissionID0, and the value of $ SubmissionID1 is SubmissionID1, and so on.***********/Do {$ SubmissionIDStr = SubmissionID. $ index;$ PostedByStr = PostedBy. $ index;$ LinkStr = Link. $ index;$ DescriptionStr = Description. $ index;$ ApprovedStr = Aprroved. $ index;// The value will be displayed on the screen, with one record per line.
Posted LinkDescription Approved

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.