0

I have a database on phpmyadmin (sql) and I want to display some data on php.

<?php
session_start();
ini_set('max_execution_time', 0);
require_once 'src/db.php';
require_once 'src/config.php';

/* Taking other user data from database. */
$a = mysql_query("select * from instagram_users"); 
while($b = mysql_fetch_array($a))
?>

I only want to display 10 data from existing data 1000

example :

id 210 = john 
id 211 = slamet 
id 212 = kikuk 
...
id 220 = yuni
jamalpinang
  • 21
  • 1
  • 7
  • 1
    do `select top 10 * from.....` – Sachu May 25 '15 at 06:45
  • 2
    if you are using `MySQL` use `select * from instagram_users LIMIT 10` – viral May 25 '15 at 06:46
  • Please edit the question to exactly what you are looking for. You have two comments in two answers that vary. If just want 10 it is `limit 10`. `The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants (except when using prepared statements).` https://dev.mysql.com/doc/refman/5.0/en/select.html – chris85 May 25 '15 at 06:55
  • Please be aware that the `mysql_` functions are now no longer just discouraged (as it was over the last years), but officially [deprecated](http://php.net/manual/en/migration55.deprecated.php). You should really use [MySQLi](http://php.net/manual/en/book.mysqli.php) or [PDO](http://php.net/manual/en/ref.pdo-mysql.php), as this code will stop working very soon. Also see [Why shouldn't I use mysql_* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Oldskool May 25 '15 at 07:32

3 Answers3

2

You can use the LIMIT clause. Just replace this line:

$a = mysql_query("SELECT * FROM instagram_users LIMIT 10"); 
gabriel
  • 2,351
  • 4
  • 20
  • 23
1
<?php
session_start();
ini_set('max_execution_time', 0);
require_once 'src/db.php';
require_once 'src/config.php';

/* Taking other user data from database. */
$a = mysql_query("select * from instagram_users limit 10"); 
while($b = mysql_fetch_array($a))
    ?>
JumboClip
  • 183
  • 8
0

Use LIMIT with offset & count like below:

 $a = mysql_query("select * from instagram_users LIMIT 40,10");
Manashvi Birla
  • 2,837
  • 3
  • 14
  • 28
  • I have 1000 the data, how can I display of the data from 40 to 50 – jamalpinang May 25 '15 at 06:50
  • 1
    That will return rows 41- 90, I believe. `With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return.` – chris85 May 25 '15 at 06:58
  • edited the answer according to your question. please check it – Manashvi Birla May 25 '15 at 07:03
  • Thats going to bring back records 41-50. 40 to 50 is actually 11 numbers. You also need to start the offset lower. Please look at the documentation, https://dev.mysql.com/doc/refman/5.0/en/select.html. – chris85 May 25 '15 at 07:12