0

I'm trying to get my site to only output a specific amount of data from my database, and not just the whole thing. Can anyone help me with this? Im trying to get it to display the first 25 lines of data.

Right now my php code, is as follows:

$sql = "SELECT * FROM cards WHERE name LIKE '%$query%';";
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
  • 8
    use `LIMIT` in your query? – ArtOsi Dec 22 '17 at 11:58
  • _Im trying to get it to display the first 25 lines of data._? Really? I see you take all data, not just 25. – pavel Dec 22 '17 at 11:58
  • $sql = "SELECT * FROM cards WHERE name LIKE '%$query%'" limit 25; – Nitin Dhomse Dec 22 '17 at 11:59
  • You should really do it in SQL—just figure out the performance of retrieving one million rows to discard all except 25. And there's no standard SQL syntax to do so so you need to check your database engine documentation (you don't say which one it is). – Álvaro González Dec 22 '17 at 11:59
  • 2
    Also bear in mind that specifying a limit without also specifying which order you want them will lead to undefined results. – iainn Dec 22 '17 at 12:20
  • Recommended reading: [How universal is the LIMIT statement in SQL?](https://stackoverflow.com/questions/1528604/how-universal-is-the-limit-statement-in-sql) – Álvaro González Dec 23 '17 at 11:57

2 Answers2

0
  $sql = "SELECT * FROM cards WHERE name LIKE '%$query%' LIMIT 10;";

if you are using MySql u can use LIMIT to get a limited number of records.

If you are using MSSQL you can use TOP

hope this helps.

FULL STACK DEV
  • 15,207
  • 5
  • 46
  • 66
0

Try it:

$sql = "SELECT * FROM cards WHERE name LIKE '%$query%' LIMIT 0,25;"
Nitin Dhomse
  • 2,524
  • 1
  • 12
  • 24
Zann
  • 1
  • 2