User-defined functions are repeatedly called on the same page to obtain the same value.

Source: Internet
Author: User
When a user-defined function is called multiple times on the same page and the same value is obtained, a user-defined function pici () is used to obtain the value of the pi field under a sequential number, then + 1 (when there is no record for this serial number, the value is 0 + 1 = 1) and then insert several records into the database in sequence, in the form of: & nbsp; & the nbs calls the user-defined function multiple times on the same page and obtains the same value.
I have customized a function pici (). its function is to get the value of the pi field under a serial number, and then add 1 (when there is no record of this serial number, value 0 + 1 = 1)

Insert several records into the database in sequence, in the form:
Serial number pi product components
1 door cover ..
1 2 door fan ..
1 3 lines ..
2 1 door cover ..
2 2 door fans ..
2 3 lines ..


However, when calling a page in PHP, the database should be retrieved every time, and the values obtained are 1, 2, 3 ...... In this way, however, the obtained values are all 1

Some code is attached below. please answer your question. Thank you








Here is the custom function pici ()

Function pici (){
$ SQL = "select ifnull (max (pi) + 1, '1') pi from bill where produce_no = 'submit '";
$ Query = mysql_query ($ SQL );
$ Rs = mysql_fetch_array ($ query );
$ Svc = $ rs [pi];
Return $ svc;
}


The following describes how to call pici () and insert three pieces of data into the database.


// Door parameter
Mysql_query ("insert into bill (color, series, produce_no, pi, prod_type, stuff_id, z, val, amount, typein) values ('$ _ GET [color]', '$ _ GET [series]', '$ produce_no ','". pici (). "',' $ prod_type ',' $ norms_stuff_id ', 'fan model', '$ _ GET [model_1]', '$ men_shu ', '$ _ SESSION [login_id]') ");
// Door cover parameters
Mysql_query ("insert into bill (color, produce_no, prod_type, pi, stuff_id, z, val, amount, typein) values ('$ _ GET [color2]', '$ produce_no', '$ prod_type ','". pici (). "', '2', 'door cover length',' $ mentaochang_shu ',' $ mentao_shu_2 ',' $ _ SESSION [login_id] ')");
// Line specification
Mysql_query ("insert into bill (color, produce_no, prod_type, pi, stuff_id, z, val, amount, typein) values ('$ _ GET [color3]', '$ produce_no', '$ prod_type ','". pici (). "', '3', 'line size',' $ _ GET [norms_3] ',' $ xiantiao_shu ',' $ _ SESSION [login_id] ')");

------ Solution --------------------
At last, this post was edited by xuzuning at 16:29:00 on. how can I publish another post? More?

I understand this.
Serial number pi product part produce_no
1 door cover ..
1 2 door fan ..
1 null line... pre-submitted
Then
1 3 lines ..
This process, right?
------ Solution --------------------
Or the ifnull (max (pi) + 1, '1') problem
Think about it:
If max (pi) is null because it is "pre-submitted", pi has no value
So what is null + 1 equal?
If the value is null, '1' is returned'
If the value is 1, 1 is returned.
Is that true?

If you want to increase pi, you should count the number of non-pre-submitted records Plus 1
------ Solution --------------------
You have where 1 = 2
What makes it strange to get results?


Ask your colleagues and they will tell you where you are wrong.

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.