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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:09:14+00:00 2026-06-17T10:09:14+00:00

Okay, so here’s my function: function getNewJobNumber($jobPrefix, $addition = 0) { $addition = $addition

  • 0

Okay, so here’s my function:

function getNewJobNumber($jobPrefix, $addition = "0") {
$addition = $addition + 1;
//echo $addition . "<br />";    
$yearDate = date("Y");
$firstDigit = $yearDate[strlen($yearDate) - 1];
$db = DatabaseHelpers::getDatabaseConnection();
$jobQuery = 'SELECT jobID, jobNumber, jobPrefix FROM tblJobNumbers WHERE jobPrefix = "' . $jobPrefix . '" AND jobNumber LIKE "' . $firstDigit . '___" ORDER BY jobID DESC LIMIT 1';
//echo $jobQuery . "<br />";
$stmt1 = $db->query($jobQuery);
$stmt1->setFetchMode(PDO::FETCH_OBJ);
$firstResult = $stmt1->fetch();
//above should select the latest created job number with selected prefix
//print_r($firstResult);
$jobNumber = $firstResult->jobNumber; //top row, will be last job number
//echo "jobNumberFromDB:" . $jobNumber . "<br />";
if (!$jobNumber) {
    //no job number exists yet, create one
    //will be last digit of year followed by "000" ie in 2013 first
    //new job number is "3000"
    $newJobNumber = str_pad($firstDigit, 4, "0");
    return $newJobNumber;
} else {
    //job number already exists, try next one
    $nextJobNumber = $jobNumber + $addition;
    $nextJobQuery = 'SELECT jobID, jobNumber, jobPrefix FROM tblJobNumbers WHERE jobPrefix = "' . $jobPrefix . '" AND jobNumber = "' . $nextJobNumber . '" ORDER BY jobID DESC LIMIT 1';
    $stmt2 = $db->query($nextJobQuery);
    $stmt2->setFetchMode(PDO::FETCH_OBJ);
    $nextResult = $stmt2->fetch();
    $dbNextJobNumber = $nextResult->jobNumber;      
    if (!$dbNextJobNumber) {
        //new job number is unique, return value
        echo "return:nextJobNumber-" . $nextJobNumber . "<br />";
        return($nextJobNumber);
    } else {
        //new job number is not unique, and therefore we need another one
        if ($addition <= 99) { //don't let this recurse more than 99 times, it should never need to
            //in order to loop this programatically call function again, adding one to addition factor
            getNewJobNumber($jobPrefix, $addition+1);
        } else {
            return;
        }
    }
}
}

here’s my call:

        $ourNewJobNumber = getNewJobNumber($_POST['txtJobPrefix'], 0);
        echo ":}" . $ourNewJobNumber . "{:<br />";

and here’s my result:

return:nextJobNumber-3005
:}{:

The code is executing perfectly, pulling values out of the database and comparing them and doing everything just the way I want it to. It is getting the correct value in every circumstance I can test, but it just outright refuses to return that value back to the calling script. Does anyone see any stupid errors that I have glossed over? Having my debug echo immediately before my return statement seems as if it eliminates any possibility of it going wrong before the return statement but I just don’t know at this point.

Edit: Just to be clear, 3005 is the value I am expecting out of my database at this point. This is to set up job numbers at work which are always Zxxx where Z is the last digit of the year. These are always created sequentially, but for jobs that span more than one year we only change Z so this is the code I use to work around the fact that 3030 can (and does) exist before 3000 is ever created.

  • 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-17T10:09:15+00:00Added an answer on June 17, 2026 at 10:09 am

    You are calling your function recursively but you are not doing anything with the return value:

        if ($addition <= 99) { //don't let this recurse more than 99 times, it should never need to
            //in order to loop this programatically call function again, adding one to addition factor
            getNewJobNumber($jobPrefix, $addition+1);
        } else {
            return;
        }
    

    Should be something like:

        if ($addition <= 99) { //don't let this recurse more than 99 times, it should never need to
            //in order to loop this programatically call function again, adding one to addition factor
            return getNewJobNumber($jobPrefix, $addition+1);
            ^^^^^^
        } else {
            return -1;    // some kind of error message?
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay here's the program I have typed up(stdio.h is included also): /* function main
Okay here's my situation. I have the following branches development development-kirby (270 commits ahead
Okay here is what I'm trying to do: I have a model object that
Okay so here's, the scenario I have a thumbnail that contains an artists profile
Okay so here is what I want to do. I want to add a
Okay so here's what I'm doing. I'm making a request to a server to
Okay so here is the deal. As the question states, I'm trying to POST
Okay basically here's where I'm at. I have a list of PropertyDescriptor objects. These
Okay so here's my algorithm for finding a Cut in a graph (I'm not
Okay, here's the situation: I've created a class extending Android's SQLOpenHelper class. I've also

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.