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

  • SEARCH
  • Home
  • 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 7967779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:58:35+00:00 2026-06-04T06:58:35+00:00

id title cat lang 6101 AAba 1 1 6102 AAad 4 2 6103 AAaf

  • 0
id  title   cat lang
6101    AAba    1   1
6102    AAad    4   2
6103    AAaf    4   2
6104    AAa 1   1
6105    AAtar   4   2
6106    AAao    1   1
6107    ABya    4   2
6108    ABar    4   2
6109    ACar    1   2
6110    BCad    3   1
6111    CCas    4   1
6112    DCas    4   2
6113    GCaz    2   2
6114    FCaew   2   2
6115    FCaw3   4   2
6116    FCa3    1   1
6117    FCa4    4   2
6118    FCa5    2   1
6119    FCa6    4   2 --- last id

Table news, id is primary key, title – is title field,
cat – there are four types of categories of news, lang – language code 1 or 2.

I want to achieve following:
1) Case Edit news – id is available – for example 6111, lang is 1, cat is 4
I want to collect these id and titles:

6119
6117
6115
6112
6109
6105
6103
6102

which are the opposite language – lang is 2, the same category cat is 4 and
within range of 4 (or n) id before and after given id 6111
also ordered desc

2) Case Add news – id is not available, or after insert in php is mysql_insert_id()
the same functionality – last 10 id with the same cat = 4 and the opposite lang = 2

So far I have tried this:

for case 1) php snippet:

   $id = 6111;
    $lang = 1;
    $tip = 4;
    $sql = "SELECT id, title 
            FROM pubs 
            WHERE id BETWEEN ".($id-4)." AND ".($id+4). " AND 
            tip = ".$tip." AND 
            lang <> ".$lang." 
            ORDER BY id DESC ";

BUT this gets 4 id before and after the id, not from the collection of id I need .

for case 2)

$sql = "SELECT id, title 
        FROM news 
        WHERE cat = 4 AND 
        lang <> 1 
        ORDER BY id DESC LIMIT 10";

This seem to be working, but may be I’m wrong.

Is there any way to achieve Case 1 this with php and mysql?
Better way for case 2?

  • 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-04T06:58:35+00:00Added an answer on June 4, 2026 at 6:58 am

    Given that you only have the $id, this horrible looking beast is the best I can come up with. I’m fairly sure there’s a tidier way to do it, but I think this will work (FIXED)

    $id = 6111;
    
    $query = "
      SELECT `id`, `title`
      FROM `news`
      WHERE `id` IN (
        SELECT * FROM (
          SELECT `id`
          FROM `news`
          WHERE `cat` = (
            SELECT `cat`
            FROM `news`
            WHERE `id` = ".$id."
          ) AND `lang` != (
            SELECT `lang`
            FROM `news`
            WHERE `id` = ".$id."
          ) AND `id` < ".$id."
          ORDER BY `id` DESC
          LIMIT 4
        ) `lower`
      ) OR `id` IN (
        SELECT * FROM (
          SELECT `id`
          FROM `news`
          WHERE `cat` = (
            SELECT `cat`
            FROM `news`
            WHERE `id` = ".$id."
          ) AND `lang` != (
            SELECT `lang`
            FROM `news`
            WHERE `id` = ".$id."
          ) AND `id` > ".$id."
          ORDER BY `id` ASC
          LIMIT 4
        ) `upper`
      )
      ORDER BY `id` DESC
    ";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is My View: CREATE VIEW [Products].[VProductFull] AS SELECT [Pr].[Id], [Pr].[Title], [Pr].[IsScanAllowed], [Pr].[Category_Id], [Cat].[Title]
I am trying to extract the page title from an HTML page cat index.html
This is example of my XML file <head> <cat>some title here... <info>some info here
cat 1.html | grep <title> > title.txt This grep statement is not working. Please
my code- require 'database.php'; $title = mysql_real_escape_string($_POST['title']); //line 48 $cat = $_POST['cat']; $txtart =
1 way Comments are embedded in Post document: { _id: ObjectId(12345), title: Cat ate
Assume this view: SELECT [Pr].[Id], [Pr].[Title], [Pr].[Category_Id] AS [CategoryId], [Pr].[IsScanAllowed], [Pr].[MaxLevelOfRegistration], [Cat].[Title] AS [Category],
Title edits that reflect a better summary of the question are welcome. I'd like
Title pretty much describes it, I just need to get all the order numbers
Title sais it all really. private bool addToBinary(byte[] msg, string filepath) { bool succ

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.