I 'd like to ask you a basic question about php.

Source: Internet
Author: User
I would like to ask you a basic question about php. PHPcode $ conn = mysql_connect (& quot; localhost & quot;, & quot; root & quot;, & quot; 123456 & quot;); if (! $ Conn) {die ('couldnotconnect: '. mysql _ php: I 'd like to ask you a basic question.
PHP code
  $ Conn = mysql_connect ("localhost", "root", "123456"); if (! $ Conn) {die ('could not connect: '. mysql_error ();} else {echo' The link is normal.
';} Mysql_select_db ("zuitu_db", $ conn); $ SQL = "select * from category order by id desc "; // $ SQL = "select * from 'Category '"; is this wrong? $ Res = mysql_query ($ SQL); $ I = 1; $ strTemp = '';/* Why can't I read the data in the while loop below? */While ($ row = mysql_fetch_array ($ res) {if ($ I = 1) {$ strTemp = $ row ["name"];} else {$ strTemp + ='
'. $ Row ["name"];} // ($ I = 1 )? $ StrTemp = $ row ["name"]: strTemp + ='
'. $ Row ["name"]; is this incorrect? $ I + = 1;} echo $ strTemp; // Please correct the above content. thank you!


------ Solution --------------------
StrTemp + ='
'. $ Row ["name"];
$ Must be added to the variable. in this case, it is considered a syntax error because strTemp can only be understood as a constant, and a constant can only be assigned a value through the define () function.
In addition, the PHP string connector is not +, yes.
$ StrTemp. ='
'. $ Row ["name"];

When it comes to question, we recommend that you add a judgment after each mysql_query (). If the database query is wrong, you can find the root cause in time.
------ Solution --------------------
$ SQL = "select * from 'Category '"; is this wrong?
$ SQL = "select * from 'Category '";

($ I = 1 )? $ StrTemp = $ row ["name"]: strTemp + ='
'. $ Row ["name"]; // is this incorrect?
($ I = 1 )? $ StrTemp = $ row ["name"]: $ strTemp. ='
'. $ Row ["name"];
$ StrTemp = ($ I = 1 )? $ Row ["name"]: $ strTemp .'
'. $ Row ["name"];
------ Solution --------------------
*
Why can't I read the data in the following while loop?
*/
While ($ row = mysql_fetch_array ($ res )){
If ($ I = 1)
{
$ StrTemp = $ row ["name"];
}
Else
{
$ StrTemp. ='
'. $ Row ["name"];
}
------ Solution --------------------
Agree to the third-floor method, $ strTemp + ='
'. $ Row ["name"]; this sentence uses the plus sign. php will process $ strTemp as int type data instead of a string.
------ Solution --------------------
Discussion
$ SQL = "select * from 'Category '"; is this wrong?
$ SQL = "select * from 'Category '";

($ I = 1 )? $ StrTemp = $ row ["name"]: strTemp + ='
'. $ Row ["name"]; // is this incorrect?
($ I = 1 )? $ StrTemp = $ row ["name"]: $ strTemp. ='
'. $ ......

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.