How does php form a number for mysql Query results.

Source: Internet
Author: User
Tags php form
How does php form a number for mysql Query results. For example, I use SQL = select id, title from table
There are three records,
Is there any way to make his results form an array?
==========================================================
Title 1, Title 2, Title 3
======================================
$ Query = mysql_query ($ SQL );
While ($ row = mysql_fetch_array ($ query ))
{
Echo "$ row [title]";
}
It seems not good to use this method.


Reply to discussion (solution)

You just need to add an array in the loop. this is a stupid way!

Since php 5.5 has included mysql extensions in the column to be abolished
So from now on, you need to get rid of the mysql extension habit.

PDOStatement: fetchAll
Mysqli_result: fetch_all
Can generate an array of query results

Since php 5.5 has included mysql extensions in the column to be abolished
So from now on, you need to get rid of the mysql extension habit.

PDOStatement: fetchAll
Mysqli_result: fetch_all
Can generate an array of query results


How can this be used?

While ($ row = mysql_fetch_array ($ query ))
{
$ Ar [] = $ row [title];
}
Print_r ($ ar );

If you find implementation troublesome, we recommend that you find a php mysql class library.

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.