Please visit: php code loop.

Source: Internet
Author: User
Please visit: php code loop. The previous code verifies that the mysql connection is correct.
What I want to achieve here is: if activite returns more than one parameter, it performs an SQL query for each parameter and then displays each query result. However, it is an endless loop, but a parameter is returned and the result is not displayed. is that the case?
Mysql_select_db ($ mysql_database, $ link );
If (isset ($ _ POST ["activite"]) {
For ($ I = 0; $ I <count ($ activite); $ I ++ ){
$ Strsql = "select n_naps from activage where famille = '$ activite [$ I]'";
Echo $ strsql;
$ Result = mysql_query ($ strsql );
$ Nb = mysql_num_rows ($ result );
For ($ I = 1; $ I <= $ nb; $ I ++ ){
$ Info = mysql_fetch_row ($ result );
Echo" $ Info [0]
";
}
}
}
Thank you for your advice.


Reply to discussion (solution)

Error!
1. for ($ I = 0; $ I <count ($ activite); $ I ++ ){
$ Activite value not displayed
2. $ strsql = "select n_naps from activage where famille = '$ activite [$ I]'"
Ying writing
$ Strsql = "select n_naps from activage where famille = '{$ activite [$ I]}'"

Error!
1. for ($ I = 0; $ I <count ($ activite); $ I ++ ){
$ Activite value not displayed
2. $ strsql = "select n_naps from activage where famille = '$ activite [$ I]'"
Ying writing
$ Strsql = "select n_naps from activage where f ......
Moderator, thank you for answering some of my idiotic questions every time. let me explain the question in detail:
The code in 1.php is as follows:
Activit é s gymniques

Activit é s gymniques aquatiques

Activit é s fitness/forme

Activit é s douces/bien-gatetre

2. php receives parameters in 1. php: the local code is as follows:
Verify that the connected database is correct.
$ Activite = isset ($ _ POST ["activite"])? $ _ POST ["activite"]: "";
If (isset ($ _ POST ["activite"]) {
For ($ I = 0; $ I <count ($ activite); $ I ++ ){
$ Strsql = "select n_naps from activage where famille = '{$ activite [$ I]}'";
Echo $ strsql;
$ Result = mysql_query ($ strsql );
$ Nb = mysql_num_rows ($ result );
Echo $ nb;
For ($ I = 1; $ I <= $ nb; $ I ++ ){
$ Info = mysql_fetch_row ($ result );
Echo"$ Info [0]
";
}
}
}
As mentioned by the moderator, the Activit és gymniques option is selected in 1.php. the above code output is:
Select n_naps from activage where famille = 'activit é s gymniques '0
I don't know why the query result is 0. I copied and pasted the text and put it in mysql. I found four results.

Here is 0. I don't know why...

Reply to reference xuzuning on the first floor: error!
1. for ($ I = 0; $ I <count ($ activite); $ I ++ ){
$ Activite value not displayed
2. $ strsql = "select n_naps from activage where famille = '$ activite [$ I]'"
Ying writing
$ Strsql = "select n_naps f ......
Add to the second floor. If all the items after where are removed, all n_naps will be displayed. that is to say, where is the problem, but I can't find anything wrong .... write $ strsql = "select n_naps from activage where famille = 'activit é s gymniques 'or say it is 0 ......

The character set is 2 bytes in the Chinese operating system, and its internal code is related to the character set used.

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.