How can I use PHP to save the data read from the database and then store the data in the variable?

Source: Internet
Author: User
How can I use PHP to save the data read from the database and then store the data in the variable? Echo $ myrow1 [xm_name]; can be used to output the project name. echo $ myrow2 [zf] can be used to obtain the total project score. but how can I save it in a variable in php? $ Xm_name = $ myrow1 [xm_name]; and $ xm_zf = $ myrow2 [zf]; no result is returned after the variable echo.
$ Query1 = mssql_query ("select * from tb_xm where xm_pcid = '$ xmpc_id'"); while ($ myrow1 = mssql_fetch_assoc ($ query1) {echo $ myrow1 [xm_name]; $ xm_name = $ myrow1 [xm_name];/****************/$ query2 = mssql_query ("select sum (xmpf_small_zf) as zf from tb_xmpf where xmpf_xm = '$ myrow1 [xm_name]' "); // echo $ query2; echo" Total score: "; while ($ myrow2 = mssql_fetch_assoc ($ query2 )) {echo $ myrow2 [zf]; $ xm_zf = $ myrow2 [zf];}


Reply to discussion (solution)

Echo $ myrow1 ["xm_name"] try it. the array field name needs to be printed.

How can I save $ myrow1 ["xm_name"] to $ xm_name?

What's wrong with that?

Error message: Parse error: syntax error, unexpected T_STRING in C: \ AppServ \ www \ online_pf \ admin \ jgcx_zt_ OK .php on line 14

Echo $ xm_name; no response.

In your example, you can directly echo $ myrow1 [xm_name]; No. What are the variables used?

Because I want to save the data to a variable and write a data update statement.

$query3=mssql_query("update tb_xm set xm_zf='$myrow2[zf]' where xm_name='$myrow1[xm_name]'");

The system will report an error saying Parse error: syntax error, unexpected T_STRING in C: \ AppServ \ www \ online_pf \ admin \ jgcx_zt_ OK .php

$ Xm_name = $ myrow1 ["xm_name"];

$ Query3 = mssql_query ("update tb_xm set xm_zf = '$ myrow2 [zf] 'Where xm_name =' $ xm_name '");

Your semicolon ends with a full width. you can change it to a half width.

$query3=mssql_query("update tb_xm set xm_zf='$myrow2[zf]' where xm_name='$myrow1[xm_name]'");

The method on the eighth floor still reports an error... Parse error: syntax error, unexpected T_STRING in C: \ AppServ \ www \ online_pf \ admin \ jgcx_zt_ OK .php on line 15

Thank you! It is a semicolon problem. The input method is mixed! Thanks again for your enthusiastic help!

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.