Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8878713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:46:46+00:00 2026-06-14T19:46:46+00:00

I am querying a MySQL database for some records by the query which limit

  • 0

I am querying a MySQL database for some records by the query which limit result max records to 4, but i want add to this result all records which has “keep_actual” column set on 1 but excludes all previous founded records. What is the best way to do this?

  // Sample query which return those 4 i need
  // Result should be those 4 + all from current $cat which has keep_actual=1 but not are in those first 4
 $news = $ed->getByLanguage($lang_id, null, false, 4,false,true);

public function getByLanguage($lang, $cat=null, $main=true, $limit=null, $hasImage=false, $isTopped=false) {

        if ($cat == null) {
            $where = "language_id=$lang";
        } else {
            $where = "language_id=$lang and category_id=$cat";
        }
        if ($main == false && $isTopped==false) {
            $where.=" and main=0";
        }
        if ($hasImage == true) {
            $where.=" and main_picture is not null";
        } 

       if($cat==12){
        $limit=10;
       }

        //Nastavuje, zda se ma zobrazovat top nebo ne(na uvodni strane a aktualne)
        if($isTopped==true)
            $where.=" and top = 1";
        //=========================================================

        //$where.=" and entry.date >= '".date("Y-m-d h:i:s", mktime(0, 0, 0, 1, 1, date("Y")))."' and entry.date <= '".date("Y-m-d h:i:s")."'";
        if ($limit == 1) {
            //nahledy
          return parent::selectOne($this->sc->select("entry", "main_picture,url,name,abstract,date,top", $where, null, "date", $limit));
        } else {
            //main clanek
            return parent::selectAll($this->sc->select("entry", "*", $where, null, "date", $limit));
        }
    }


public function selectAll($sql) {
        $res = mysql_query($sql);
        if ($res) {
            $a = array();
            $i = 0;
            while ($r = mysql_fetch_assoc($res)) {
//                print_r($r);
                foreach ($r as $k => $v) {
                    $a[$i][$k] = $v;
                }
                $i++;
            }

            return $a;
        } else {
            return false;
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:46:48+00:00Added an answer on June 14, 2026 at 7:46 pm

    Okay, this is ‘generic’ code, you need to adapt it to your needs, but this is how it should work:

    $res = mysqli_query($sql, "SELECT * FROM `table` WHERE `Condition` = 1 LIMIT 4");
    $results = array();
    while($row = mysqli_fetch_array($res)) $results[] = $row;
    
    $query = "SELECT * FROM `table` WHERE `keep_actual` = 1 AND ID NOT IN (";
    for($i = 0; $i < 4; ++$i) $query .= "$row[ID], ";
    $query .= "0)"; //To terminate the list of IDs
    $res = mysqli_query($sql, $Query);
    

    This code SHOULD give you what you’re looking for, but it’s completely untested and rather abstract.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this Error when querying MYSQL Database: Glib-Error **: gmem.c:173:falied to allocate 216000000
This is the code I'm using to select some records from my database. I'm
I have some PHP script querying a mysql database and echoing out a piece
I'm working on this tutorial, it's about querying the mysql database by using Json
In PHP, which is quicker; using include('somefile.php') or querying a MySQL database with a
I have a problem for querying records into mysql explanation below The user could
i'm querying a database like this: SELECT * from Log WHERE cookieId IN (select
I am querying a mySQL database to retrieve the data from 1 particular row.
I need to get some data from a mysql database.I'm running a php script
We have a relational database (MySql) with a table that stores Whatever. This table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.