B
B
Bobur Bakhritdinov2015-12-15 10:14:03
PHP
Bobur Bakhritdinov, 2015-12-15 10:14:03

The request is not working correctly. What is the reason?

Hello friends, help me solve the problem, there is a sql query, it doesn’t work correctly or I’m wrong somewhere, I need your help!
SQL query:

$db->query("SELECT * FROM news" , 1);
            
$count_news = $db->num_rows();
list($pagertop, $pagerbottom, $limit) = pager('10', $count_news, 'news.php?');

$db->query("SELECT n.* , u.name AS user_name , u.class AS user_class  , u.avatar
        FROM news AS n
        LEFT JOIN users AS u ON u.id = n.id_user
        ORDER BY n.date DESC
        ".$limit."");

MYSQl database:
e98bcbe367b043198bc8baee70092d3e.jpg
Result on the site:
90ac94a08998480c94611ef22564d611.jpg
Problem:
Table 3 is news, while the site shows only the latest added. although the display limit is worth a maximum of 10 results per 1 page

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Safonov, 2015-12-15
@elevenelven

Run a raw SQL query in phpMyAdmin. You're using a LEFT JOIN, so all of the entries in news will get it. The problem in the request can only be with $limit . If there are no errors in the limit, and a clean request gets 3 news, then look for the problem further along the code. In a controller or view.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question