Page 1 of 1

displaying records

Posted: Thu Apr 16, 2020 4:57 pm
by Mark
hello

im using this to display my records in a table with pagination but it will show all the records but i want it do it only shows the records that the username put in to the database i tried this.

below shows all the records
Code: Select all
$sql = 'SELECT * FROM orders LIMIT '.$page1.', 4';
this is ment to just show the records off the person logged in but seems to get an error.
Code: Select all
$sql = 'SELECT * FROM orders  WHERE OrderBy = '$username'LIMIT '.$page1.', 4';

Re: displaying records

Posted: Sat Apr 18, 2020 7:07 pm
by CodenStuff
Thu Apr 16, 2020 4:57 pmMark wrote:
hello

im using this to display my records in a table with pagination but it will show all the records but i want it do it only shows the records that the username put in to the database i tried this.

below shows all the records
Code: Select all
$sql = 'SELECT * FROM orders LIMIT '.$page1.', 4';
this is ment to just show the records off the person logged in but seems to get an error.
Code: Select all
$sql = 'SELECT * FROM orders  WHERE OrderBy = '$username'LIMIT '.$page1.', 4';
Maybe try:
Code: Select all
$sql = "SELECT * FROM orders WHERE OrderBy = '$username' LIMIT '.$page1.', 4";
Unsure if that will work but let me know either way.

Re: displaying records

Posted: Sat Apr 18, 2020 7:08 pm
by CodenStuff
Also what is the error?

Re: displaying records

Posted: Sun Feb 21, 2021 9:14 pm
by Livengood
Might have been a small error in your code that was provided. Sometimes its a bit buggy when you try and place variables into a string. Can you try the following?

When you are using LIMIT, you are passing a number, make sure to also leave out the '.
Code: Select all
$sql = "SELECT * FROM orders WHERE OrderBy = '{$username}' LIMIT {$page1}, 4";
Code: Select all
$sql = 'SELECT * FROM orders WHERE OrderBy = '" . $username . "' LIMIT '" . $page1 . "', 4';