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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:13:25+00:00 2026-06-11T16:13:25+00:00

I want the correct question number to be displayed in the database table but

  • 0

I want the correct question number to be displayed in the database table but problem is that it is displaying incorrect question numbers by +1.

Lets say I have 4 rows and I used file input in row 2 and row 4 to upload the files, then it means the question numbers should be 2 and 4 meaning the table should look like this below:

ImageId    SessionId  QuestionId
01               AAA        2
02               AAA        4

But instead it has got the question number wrong by only plus 1 meaning it is displaying it like this:

ImageId    SessionId  QuestionId
01               AAA        3
02               AAA        5 

I believe the problem is that I am not inncrementing the question numbers correctly. Can anybody see what I am doing incorrectly in my code below that it is inserting the wrong question numbers?

Below is the code:

var qnum = 1; //question number starts at 1
var qremain = <?php echo (int)$_SESSION['textQuestion']; ?>; //the full number of questions

var $qid = $("<td class='qid'></td>" ).text(qnum);
var $image = $("<td class='image'></td>");    

var $fileImage = $("<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='return imageClickHandler(this);' class='imageuploadform' >" + 
        "Image File: <input name='fileImage' type='file' class='fileImage' /></label><br/><br/><label class='imagelbl'>" + 
    "<input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /></label>" + 
    "<label><input type='button' name='imageClear' class='imageClear' value='Clear File'/></label>" +
    "</p></form>"); 


$tr.append($qid);
$tr.append($image);

$('.num_questions').each( function() {

    var $this = $(this);

    var $questionNumber = $("<input type='hidden' class='num_questionsRow'>").attr('name',$this.attr('name')+"[]")
                   .attr('value',$this.val());

    $qid.append($questionNumber);                             

    ++qnum;
    $(".questionNum").text(qnum);
    $(".num_questions").val(qnum);

    --qremain;
    $(".questionRemain").text(qremain);
});

How the $('.num_questions').each( function() { work is like this:

  • When user opens page, qnum (question number) starts with ‘1’ at the top
  • When user appends a table row, then it will take question number ‘1’ from the top and display it within the added row and the qnum (question number) at the top increments so that it now states 2
  • When user appends another row, it will take question number ‘2’ from the top and display it within the added row and the qnum (question number) at the top increments so it now displays 3.
  • And so and so on…
  • 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-11T16:13:26+00:00Added an answer on June 11, 2026 at 4:13 pm

    Why not start with var qnum = 0;? Most incremental functions do!

    EDIT

    You’re incrementing ++qnum before using .text and .val to display the value in the row. Try incrementing afterwards. Your each function would end with:

    $(".questionNum").text(qnum);
    $(".num_questions").val(qnum);
    ++qnum;
    
    $(".questionRemain").text(qremain);
    --qremain;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a stupid question, but I notice that in a good number
I want to verify that my understanding is correct. This kind of thing is
.net MVC 2.0 question: The main problem is I want to paging my data
Problem: I want to write a trigger when a table is inserted, I have
I have a sort of general question but i think that if I tried
I want to convert a date object into a serial number that is consistent
I want to know is below code correct ? I have following code which
I want some like this: How make it ideologically correct?
i want to check if a string only contains correct letters. I used Char.IsLetter
In my application I want to open some files with the correct default programmes,

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.