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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:51:31+00:00 2026-05-14T08:51:31+00:00

Thanks for the contributions so far – I can see now that $rowq is

  • 0

Thanks for the contributions so far – I can see now that $rowq is not a single array but lots of them – I’d like to bring all the rows back in the array, any suggestions?

First off, the code which brings back my data into an array:

function fetch_questions($page) {
global $link;
$proc = mysqli_prepare($link, "SELECT * FROM tques WHERE page = ?");
mysqli_stmt_bind_param($proc, "i", $page);
mysqli_stmt_execute($proc);


$rowq = array();
stmt_bind_assoc($proc, $rowq);

// loop through all result rows
while ($proc->fetch()) {
//      print_r($rowq);
}


mysqli_stmt_close($proc);
mysqli_clean_connection($link);
return($rowq);
} 

Now, when I `print_r($rowq);’ I get the following, which is all good:

Array ( [questions] => q1 [qnum] => 1 [qtext] => I find my job meaningful [page] => 1 ) Array ( [questions] => q2 [qnum] => 2 [qtext] => I find my job interesting [page] => 1 ) Array ( [questions] => q3 [qnum] => 3 [qtext] => My work supports ABC's objective [page] => 1 ) Array ( [questions] => q4 [qnum] => 4 [qtext] => I am able to balance my work and home life [page] => 1 ) Array ( [questions] => q5 [qnum] => 5 [qtext] => I am clear about what is expected of me in my job [page] => 1 ) Array ( [questions] => q6 [qnum] => 6 [qtext] => My induction helped me to settle into my job [page] => 1 ) Array ( [questions] => q7 [qnum] => 7 [qtext] => I understand the ABC vision [page] => 1 ) Array ( [questions] => q8 [qnum] => 8 [qtext] => I know how what I do fits into my team's objectives [page] => 1 )

Now, in my php page I have the following piece of script:

$questions = fetch_questions($page);

And when I print_r $questions, as below:

print_r($questions);

I only get the following back from the array, 1 row:

Array ( [questions] => q8 [qnum] => 8 [qtext] => I know how what I do fits into my team's objectives [page] => 1 )

Any ideas why that might be?

Thanks in advance,

Homer.

  • 1 1 Answer
  • 4 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-14T08:51:32+00:00Added an answer on May 14, 2026 at 8:51 am

    Your $rowq variable is only holding the last row that was fetched. When you print_r during your fetch loop, each row is fetched into the $rowq variable, and then immediately printed, but because you overwrite the variable each iteration, when the loop completes only the final row is contained within $rowq.

    If you want to hang onto all the rows, you can augment your function:

    function fetch_questions($page) {
      // ...
    
      $rows = array();
      while ($proc->fetch()) {
        $rows[] = $rowq;
      }
    
      // ...
    
      return $rows;
    }
    

    With this code (only the relevant parts are included), every time a row is fetched, it is placed within an array $rows, which then contains all rows when the loop completes.

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

Sidebar

Related Questions

I've started learning Python 3 - and now so far that I need some
Have any other iPhone developers experienced this phenomenon? I can see his contributions in
Thanks to the epic work of Dennis Williamson, I am now able to calculate
Thanks in advance to anyone who can think of a more efficient or a
Today I am going to get as far as I can setting up my
The host that I want to host with does not support server side url
Say that I have made some software (which has both library form and can
I recently found out how to use tuples thanks to great contributions from SO
I realize that this question spans many technologies, but I am only looking for
Thanks for the help on here with my query on here the other day

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.