PHP connection MySQL Query a piece of data

Source: Internet
Author: User
Tags php mysql php mysql query sprintf
PHP MySQL Query

There is a table in the database with a primary key Pmcode and other properties
I now want to determine whether a user exists by Pmcode, if there is a message out of it, does not exist return "does not exist", and then through the form of splicing XML sent out, the code is as follows:
Split the distribution of information to get the membership card number $arry =explode ("+", $form _content);              $memberid = $arry [1]; Connect the database $link =mysql_connect (sae_mysql_host_m. ': ').               Sae_mysql_port,sae_mysql_user,sae_mysql_pass);                    if ($link) {mysql_select_db (sae_mysql_db, $link);                 Query data $result 1=mysql_query ("select * from numbers where Pmcode = '". $memberid. "';");                   $num _result = mysql_num_rows ($result 1);                       if ($num _result==1) {//$row = $result 1->fetch_assoc ();                        $row =mysql_fetch_row ($result 1);                         $result _str= "Your member-information is as follows: \ n/A card number: $row [pmcode].\n name:. $row [names].\n Rating:. $row [4].\n points: $a [5]";                         $RESULTSTR = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, $result _str);                                           Echo $resultStr;                   Exit }else{$msgType = "TexT "; $RESULTSTR = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, "--select * from numbers where Pmcode = '". $mem                      Berid. "'");                                      Echo $resultStr;                   Exit            }} else{echo "Connection to database failed". Mysql_error;        } mysql_close ($link); }

But even if the right pmcode are not marrying the data they want, ask God to modify it.


Reply to discussion (solution)

if ($num _result==0) {                           //   $row = $result 1->fetch_assoc ();                           $row =mysql_fetch_row ($result 1);                            $result _str= "Your member-information is as follows: \ n/A card number: $row [pmcode].\n name:. $row [names].\n Rating:. $row [names].\n points: $a [names]";                             $RESULTSTR = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, $result _str);                       echo $resultStr;                                               Exit

It's not going to change into ==0.

Echo $memberid; What value does it take to copy SQL to DOS command line execution to get the data?

Echo $memberid; What value does it take to copy SQL to DOS command line execution to get the data?
The correct value is obtained.

$num _result = mysql_num_rows ($result 1);
echo $num _result; Output what

$num _result = mysql_num_rows ($result 1);
echo $num _result; Output what
1

That's right, your main post code is not a problem, you should be able to enter if inside.

That's right, your main post code is not a problem, you should be able to enter if inside.
After taking out a piece of data, how to get the property inside, how to print out the pmcode,names?

$row =mysql_fetch_row ($result 1);
Print_r ($row);

$row =mysql_fetch_row ($result 1);
Print_r ($row);
Just take names this property?

$row [' names ']

$row [' names ']

 $link =mysql_connect (sae_mysql_host_m. ': ').    Sae_mysql_port,sae_mysql_user,sae_mysql_pass);                        if ($link) {mysql_select_db (sae_mysql_db, $link);                       $memberid = "j00000000b005";                                          Query data $result 1=mysql_query ("select * from numbers where Pmcode = '". $memberid. "'");                      $row =mysql_fetch_row ($result 1);                                        $num _result = mysql_num_rows ($result 1);                        if ($num _result==1) {$resultStr = $row [' names '];                                          echo "FFF". $resultStr;                                                Exit                                                }else{echo "no data Found";                 }} else{echo "Connection to database failed". Mysql_error;              }   Mysql_close ($link); 

Why is the FFF output only?

Print_r ($row); Post the results

Array ([0] = j00000000b005 [1] =??? [2] = = F [3] = [4] = [5] = 20121012 [6] = 20130430 [7] = Z [8] = JE11 [9] = 0 [Ten] = 0 [One] = 0 [[] = [] =]

Print_r ($row); Post the results
Array ([0] = j00000000b005 [1] =??? [2] = = F [3] = [4] = [5] = 20121012 [6] = 20130430 [7] = Z [8] = JE11 [9] = 0 [Ten] = 0 [One] = 0 [[] = [] =]

Oh, I got it wrong.
echo $row [1];

There is garbled, query front plus a sentence: mysql_query ("Set names UTF8"); Give it a try

You change mysql_fetch_row to Mysql_fetch_assoc and try ... And then print the array

  • Related Article

    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.