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. ='
'. $ ......