Programming. Solution

Source: Internet
Author: User
Programming... & Nbsp; the existing MYSQL database server with the username root and password root has a database named mongogl, how to use PHP programming to display the first 15 records of the student table in the PostgreSQL GL database, and use mysql_connect ('localh for programming...
The existing MYSQL database server with the username "root" and password "root" has a database named mongogl. how to use PHP programming to display the first 15 records of the student table in the mongogl database
------ Solution --------------------
Mysql_connect ('localhost', 'root', 'root') or die (mysql_error ());
Mysql_select_db ('invalid GL ') or die (mysql_error ());
$ Rs = mysql_query ('select * from student limit 15') or die (mysql_error ());
While ($ r = mysql_fetch_assoc ($ rs )){
Echo join ('', $ r ).' ';
}


------ Solution --------------------


Mysql_connect ('localhost', 'root', 'root') or die (mysql_error ());
Mysql_select_db ('invalid GL ') or die (mysql_error ());
// Assume that your field name is id.
$ Rs = mysql_query ('select * from student order by id desc limit 15') or die (mysql_error ());
While ($ r = mysql_fetch_assoc ($ rs )){
Echo join ('', $ r ).' ';
}


------ Solution --------------------

$mysql_server_name='localhost';
$mysql_username='root';
$mysql_password='root';
$mysql_database='JWGL';
$mysql_table='student';
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database) or die(mysql_error());
mysql_select_db($mysql_database,$conn);
$sql='SET NAMES UTF8';//if utf8
mysql_query($sql);

$queStr ='SELECT * FROM '.$mysql_table.' ORDER BY id ASC LIMIT 0,15';//if pri key id
$result=mysql_query($queStr);
while($row = mysql_fetch_array($result)){
echo $row[0]." ".$row[1]." ";//or $row["test_col"]
}
mysql_close($conn);

------ Solution --------------------
SELECT * FROM student limit 0, 15

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.