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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:44:10+00:00 2026-05-22T20:44:10+00:00

Name pretty much explains it all– I have an array and I want to

  • 0

Name pretty much explains it all–

I have an array and I want to run a query for each item in the array

Two variables come from this, volume and page number — the volumes are contained within the array and I need to pull the respective page numbers for each volume

heres my code:

$volsArr = array(1, 2, 3, 4);

foreach ($volsArr as $volume) {
 $pages = mysql_query("SELECT page FROM $table WHERE vol = '$volume' LIMIT 1");
    if (!$pages) { die("Query to show fields from table failed"); }
      while($row = mysql_fetch_array($pages)) {
       $page = $row['page'];
      }
    echo 'volume is '.$volume.'';
    echo 'page is '.$page.'';
   }

I can’t figure out what the issue I’m having is, I am getting an output like this:

Volume is 1
Page is 40

(this is correct for volume 1)

Volume is 2
Page is 40

(page should be 8)

Volume is 3
Page is 40

(page should be different again)

etc…

I tried unset($page) before closing the loop but that doesn’t seem to do anything, any help, please!

And I also tried moving the echos so they are inside the while($row...) loop, but that will only provide me with output for the first item in the array….

  • 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-05-22T20:44:11+00:00Added an answer on May 22, 2026 at 8:44 pm

    Based on your update, the reason is: Rows do not exist where vol in ('2','3','4')

    $page is never being updated because there are no rows to fetch.

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

Sidebar

Related Questions

The name pretty much says it all. Does anyone know how to accomplish functional
The name pretty much says it all. Right now I'm using Squirrel - it
Title pretty much explains what I want to do... I'm not a fan of
The title pretty much says it all. If I have something like (from PHP
Title pretty much says it all. I have a page called login.jsp: <f:view> <html>
The title pretty much says it all. I have a regex that I need
Title pretty much sums it up. Is there a technical name given to a
I'm pretty much a newb with spring-hibernate and I have been trying to make
The title pretty much says it all, how do I know if I'm getting
The whole question is pretty much in the title. For each row of the

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.