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 6387455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:09:16+00:00 2026-05-25T03:09:16+00:00

Please help me with a mysql query, using PHP to access databse and process

  • 0

Please help me with a mysql query, using PHP to access databse and process data:

I have variables

1) $content_number_of_characters
2) $number_of_comments

and mysql table name: udjacomments

fields of table udjacomments: id, full_name, content, comment_url, is_published, and time_added

I would like to retrieve each entry into an array. For content, I would like to only get the content up to the character $content_number_of_characters (In other words, if $content_number_of_characters is 120, and content is 300 characters, I only want the first 120 characters).

(I do not know how I could use the mysql LEFT(str, len) into the query)

Then, I only want number of records ( $number_of_comments ) in a descending order from id and if field is_published == 1

Example:

I have records with id: 50, 51, 52, 53, 54, 55, 56
all records have is_published == 1, with the exception of record with id 55; record id 55 is_published == 0. Last, variable $number_of_comments == 3

the query would retrieve records 56, 54, and 53

Thank you,

  • 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-05-25T03:09:16+00:00Added an answer on May 25, 2026 at 3:09 am
    1. Number of comments:

      $query = “SELECT * FROM udjacomments
      where is_published = 1 order by id desc limit $number_of_comments”

    2. 120 chars

      $query = “select id,
      if(CHAR_LENGTH(content) > $content_number_of_characters, SUBSTR(content, 1, $content_number_of_characters), content)
      FROM udjacomments”;

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

Sidebar

Related Questions

I'm trying to optimize this mysql query using EXPLAIN. Can somebody please help me
I'm trying to delete a record in mysql using php. What do I have
Please help, Im trying to search for mysql records using an html form to
So I setup a table using mysql query browser, and now i'm trying to
I'm new to MySQL query, so please help me out of this problem, thanks!
Please help! Background info I have a WPF application which accesses a SQL Server
I am using following PHP code for trigger creation but always get error, please
I am making a PHP web Application in which i am using MySQL as
I am trying to generate a grouped/stratified report using PHP and MySQL. tbl_items has
I am trying to get hold of 1 record from a MySQL table using

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.