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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:58:22+00:00 2026-06-16T00:58:22+00:00

Good day to everybody I have a simple counter php+db it checks ref number

  • 0

Good day to everybody

I have a simple counter php+db
it checks ref number of the last content that was added and gives a ref number to newly added content by adding + 1 to the previous ref number of specific content type (order).
it works fine till it gets to ref number 10, then it stock and gives only 10 to content that i add.
so i cant add content with ref number 11 and 12, 13 ,14 …
drupal 7
thank you for your time and help.

if (empty($node->title)){
drupal_set_message('new node');

$query = db_select('node', 'n');
$query->condition('n.type', 'order', '=');
$query->fields('n', array('title'));
$query->orderby('title','DESC');
$query->range(0, 1);
$query->execute();
$result = $query->execute();

$record = $result->fetchAssoc();
drupal_set_message('previous order №: ' .print_r($record['title'], true));
$title = $record['title'] + 1;
drupal_set_message('order №: ' .print_r($title, true));
$form_state['node']->title = $title;
}
  • 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-16T00:58:23+00:00Added an answer on June 16, 2026 at 12:58 am

    Ok, so after a lengthy discussion the answer is:

    You cannot use an alphanumerical column type (varchar(255)) and expect an alphanumerical descending sorting to produce the highest number stored inside that column. This is because a leading ‘9’ will always come out before anything else, even if values like 10, 11, 3529 or whatever iares stored inside that column.

    You either have to change the column type to a numerical type or use a much more complex sorting strategy. If you cannot change the type of that column then you might want to have a try using type casting in your SELECT query and sort by the result of that type cast. Though such approach is very slow and inefficient.

    Also note that your algorithm is unsafe, another insert query might interfere whilst you are still computing your next index if you are working without transactions.

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

Sidebar

Related Questions

Good Day, I have a simple working routine in Perl that swaps two words:
Good day, I have a class that implements the LoaderCallbacks, and hence have the
Good day I have a custom TextBox that has a IndicatorTextBox.ui.xml file as well
Good day everybody! I'm developing application for iPhone. I have table view and list
Good day everybody, I'm having troubles with the display of a data that does
Good day code knights, I have a tricky problem that I cannot see a
Good day, i have a meta like this <meta name=viewport content=initial-scale=1.0, maximum-scale=1.0, user-scalabale=no, width=device-width,
Good day, everyone! I have here a program that sorts 50,000 words from a
Good day, I have like 15 images I need to be buttons. I have
Good day, all. I know that this is a pretty basic question in terms

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.