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

The Archive Base Latest Questions

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

I have a page that is a survey- based on your answers to previous

  • 0

I have a page that is a survey- based on your answers to previous questions shows and hides other questions using jquery (these questions vary with all input types) I have a save function and then a save and submit function – when saving and submitting I need to verify ALL questions that have not been hidden have been answered – in prototyping this with outputs to test the syntax I realized that the massive quantity of mysqli querys I am running slows the page down (could be upward of 300 questions or as short at 10)

what we have below is a query to find out how many questions are assigned to this survey (sid, $surveyid), $qcountup was my way of making the while statement visit every single number between 1 and the highest question number ($qtotal)
we get down to the while statement which is reoperating for every number from 1 – $qtotal) inside the while we run a query to find out if an answer exists for each number in the database (if it was not answered – it wont exist.
again how this is coded currently could mean 300+ mysqli querys (LAG). any suggestions on how to condense this or write it better?

    $qquery = "SELECT * FROM question WHERE (sid = ".$surveyid.");";
$qresult = mysqli_query($dbc, $qquery);
$qtotal = mysqli_num_rows($qresult);
$qcountup = 1;
while($qcountup <= $qtotal){
$squery = "SELECT * FROM answers WHERE sid='".$SID."' AND question='".$qcountup."';";
$sresult = mysqli_query($dbc, $squery) or die(mysql_error());
if (mysqli_num_rows($sresult) )
{
echo("<br>row existed");
} else {
echo("<br>row doesn't exist");
}     
$qcountup = $qcountup + 1;    
}
  • 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-13T07:41:25+00:00Added an answer on June 13, 2026 at 7:41 am

    First of all, since you’re using mysqli, you should be using prepared queries rather than interpolating variables directly into the query strings.

    The first query should be:

    SELECT COUNT(*) qtotal FROM question WHERE sid = "$surveyid"
    

    If you’re only interested in the number, there’s no need to get all the columns. Set $qtotal to the qtotal column of this result.

    For the second part, you can use a LEFT JOIN to match questions against answers, and see which answers are missing:

    SELECT * FROM questions q LEFT JOIN answers a USING (question, sid)
    WHERE q.sid = $SID
    ORDER BY q.question
    

    If an answer is missing, a.question will be NULL in that row.

    I’m not sure if I should be using $SID or $surveyid there; your original code used both in different queries.

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

Sidebar

Related Questions

I have a page that I am using an Ajax Accordion and when I
We have a project that needs to gather survey data. On one particular page
Here's what I need to do. I'm using Google Chrome. I have page that
I have a page that uses jQuery UI, and calls the datepicker on 2
I have page that creates a table: http://gupii.co.uk/rap/weekTable.php and I'm using a plugin to
I have a page that shows data from my database. Before the user sees
I have a page that shows information from my database. Each array has an
I have a form representing a survey that is dynamically generated based on some
I have a page that uses jQuery UI Tabs that has both static and
I have a page that builds out a table. Nothing else on that page

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.