How to fetch the first 2 or 3 rows from Mysql DB using Mysql PHP function?

Use LIMIT From the manual to retrieve 3 rows: SELECT * FROM tbl LIMIT 3 Or to retrieve rows 6-15: SELECT * FROM tbl LIMIT 5,10 For this query (i.e. With no constraint) if you are not using an ORDER BY clause your results will be ordered as they appear in the database.

Use LIMIT. From the manual, to retrieve 3 rows: SELECT * FROM tbl LIMIT 3; Or to retrieve rows 6-15: SELECT * FROM tbl LIMIT 5,10; For this query (i.e. With no constraint) if you are not using an ORDER BY clause your results will be ordered as they appear in the database.

I think I am gone out of my mind...I don't believe this that I asked this question...Thanks Mate for the reply and alerting me that I am tired..... – OM The Eternity May 12 '10 at 12:25 lol no worries, happens to the best of us :) – Andy May 12 '10 at 12:26 Thanks Again for the condolence :) – OM The Eternity May 12 '10 at 12:27 If you are not using an ORDER BY clause your results will be ordered ran-dom-ly. – Col. Shrapnel May 12 '10 at 12:37 Orrite, I did that before asking this Blunder :) – OM The Eternity May 12 '10 at 12:46.

You can use the limit clause in your query: select * from your_table limit 3 This will select the first three rows. And: select * from your_table limit 5, 3 The later will select rows starting from 5 and return three rows.

Thanks Sarfraz for the detailing – OM The Eternity May 12 '10 at 12:28 @OM The Eternity: You are welcome... – Sarfraz May 12 '10 at 12:30.

You have 2 options: Fire a query to select all the rows and then select 2 or 3 rows as needed using PHP. Fire a query to select only the necessary number of rows using LIMIT clause. The 2nd option is preferable.

Thanks unicornaddict for the "Points to Remember Style" will keep in mind :) – OM The Eternity May 12 '10 at 12:29.

MySQL doesn't have a Fetch Array function. A PHP function that allows you to access data stored in the result returned from a successful mysql_query. Function popping up all over the place.

This lesson will teach you how and why to use mysql_fetch_array in your PHP Scripts. Mysql_fetch_array: Why Use It? Do you know what is returned when you used the mysql_query function to query a MySQL database?

It isn't something you can directly manipulate, that is for sure. Here is a sample SELECT query of a table we created in the MySQL Create Table lesson. The value that mysql_query returns and stores into $result is a special type of data, it is a MySQL Resource.

Additional PHP functions are required to extract the data from this Resource. Returns the first row of data returned by the mysql_query. Our table example basically looks like the table below.

The first row of data in this table is "Timmy Mellowman" and "23". When we fetch an array from our MySQL Resource $result it should have Timmy's name and age in it. Mysql_fetch_array returns the first row in a MySQL Resource in the form of an associative array.

By using the column names of the table. In our table example these are: name and age. To print out the first MySQL Result row.

This is just what we expected would happen! Is that you can use it again on the same MySQL Resource to return the second, third, fourth and so on rows. You can keep doing this until the MySQL Resource has reached the end (which would be three times in our example).

Sounds like an awfully repetitive task. Easy to do script. FALSE if there are no more rows to return!

Can use this information to our advantage. We will get a new row of MySQL information that we can print out each time the while loop checks its conditional statement. When there are no more rows the function will return FALSE causing the while loop to stop!

Now that we know what we need to do and how to go about doing it, the code pretty much writes itself, so let's move on to the next lesson. Here is the code that will print out all the rows of our MySQL Resource. And there we have all the rows from our example table!

You could apply this script to any MySQL table as long as you change both the table name in the query and the column names that we have in the associative array. MySQL eBook from the Tizag.com store. Found Something Wrong in this Lesson?

Report a Bug or Comment on This Lesson - Your input is what keeps Tizag improving with time!

Lykke LI. Who you say? She is just the most amazing musician that I have ever seen or heard.

She is down to earth...not into fussy crowds. She has had an interesting life...growing up in Sweden with a photographer for a mother and a musician for a father. Kings of Leon asked her to do a cover of one of their songs...her choice.

That is pretty neat when a band asks you to cover a song.

I would be best friends with Sarah Silverman, no doubt. Her sense of humor is right on, she's silly and inappropriate, she would be a riot to hang out with, but she seems like she would also be a really loyal friend. End of story.

.

B B King, the last of the great blues musicians. It would also give me access to people like James Cotton and Eric Clapton and so on. Plus he is now at the age where following him around wouldn't be to hard on the liver.

I don't think he's up for those all night parties anymore. But to learn from one of the last of the masters would be an incredible experience.

I would choose to be a Best Friends Forever with LJ Smith, who is an author of a series called "Night World". I would pick her brain and learn how she came up with her characters and learn more about the writing process. I think I would try to learn more from her and take any advice she has to give about my writing, because it will help me in the future.

I am blessed because my best friend is my mother. She is hilariously funny and I wouldn't trade her for all the movie stars, musicians, scientists, economists, or blacksmiths in the world. She is good at everything.

She cooks like a gourmet chef, knows how to get rid of stains on laundry, and can drive in reverse better than I drive forwards. You can keep your Angelina Jolies, your Brad Pitts, your Martha Stewarts, and your Oprahs. I'll stick with mom.

Lon Harris. No question about this, even if he is not a BIG celebrity or a BIG musician…at least from what I heard. Or, maybe I’m wrong.

He is a funny guy and a great friend. Ingenious, smart and he loves coffee as much as I do. He knows when to be serious and when a joke is needed.In other words I think you can learn a lot from him and have fun at the same time.

youtube.com/watch?v=Op-ZX1xhnSQ youtube.com/watch?v=lKgJOz6Wh5s&feature=....

(I say character, because, though he really existed, his exploits are so legendary that probably a good 30 percent of them were fiction in the form of folklore developed over almost two millenia.) If I could be anyone in the world, alive or dead, for 24 hours, I would choose to be Zhuge Liang (Daoist name: Sleeping Dragon), perhaps the most famous mind in the entire Sanguo (Three Kingdoms) Period of Chinese history, who is, actually, the man I also happen to wish to be buried next to after I'm dead. But I'll get to the reasons I want to buried next to him later. For now, let's begin with a few details of this extraordinarily extraordinary man.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions