Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

258
Views
Showing the same data on every Page. Nodejs MySql

Showing the same data on every Page. Array have lots of data but it's only showing first ten results in every Page

Query is working fine its giving the all results but I think problem in Sort or maybe in Order By. I have no idea new to MySql

async function getvehicles(username, params) {
    var result = {};

    var mysqlResult;
    db.beginTransaction();
    const users = await db.query('SELECT * FROM users WHERE username = ?', [username]);
    if (users.length === 0) {
        result.success = false;
        result.message = "Invalid User ID";
        result.data = [];
        result.range = '0-0';
        db.commit();
        return result;
    }

    let sortBy = "verified";
    let sortOrder = "DESC";
    if (params.sort) {
        const sortArray = JSON.parse(params.sort);
        sortBy = sortArray[0];
        if (['DESC', 'ASC'].includes(sortArray[1])) {
            sortOrder = sortArray[1];
        }
    }
    const page = params.page ? JSON.parse(params.page) : 1;
    const perPage = params.perPage ? JSON.parse(params.perPage) : 10;

    mysqlResult = await db.query(`SELECT * FROM c_vehicles WHERE imageurl IS NOT NULL OR '' AND proofurl IS NOT NULL OR '' ORDER BY ?? ${sortOrder}, id DESC LIMIT ?,?`, [sortBy, ((page - 1) * perPage), perPage]);
    result.data = mysqlResult;

    const mysqlResultCount = await db.query(`SELECT COUNT(*) AS count FROM c_vehicles WHERE imageurl IS NOT NULL OR '' AND proofurl IS NOT NULL OR ''`);
    if (mysqlResultCount[0].count > 0) {
        const countValue = mysqlResultCount[0].count;
        result.range = `0-${countValue - 1}`;
        result.totalLength = countValue;
    } else {
        result.range = '0-0';
        result.totalLength = 0;
    }

    db.commit();

    result.success = true;
    result.message = "Successfully fetched Vehicles.";
    return result;
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!