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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:11:15+00:00 2026-06-08T14:11:15+00:00

I am having a problem with the while function for a mysql_fetch_array. I have

  • 0

I am having a problem with the while function for a mysql_fetch_array. I have experimented on what to use after the statement and what I have now works better than it did before. I thought i could just run a load of loops inside each other but clearly not. I currently have curly brackets on the first two statements and none on the others, you can see this clearly in the code.

However, what i have now means that having more than one variable after each statement causes the second one to stop working when echoed etc. I am trying to avoid using arrays as variables would be a lot easier to lay out afterwards. Not sure what’s going on here. I normally use curly brackets after every statement but that just made the whole thing redundant. What should I do to keep all the variables working? I am not great with PHP yet and thanks for all the help so far!

I am just having a mess around for future purposes so I know i should be using mysqli. I have only recently learnt mysqli so I was just using mysql because i feel more comfortable with it for the time being.

Here is the code anyway:

 //fetch favourited artist(s)
                  $fetchartistFavourite = mysql_query("SELECT * FROM artistfavourites WHERE username = '$username' AND password = '$pass';")or die(mysql_error()); 
                  while ($artistFavourite = mysql_fetch_array($fetchartistFavourite)){
                  $favouritedArtist = $artistFavourite['artistname'];
                  $favouritedArtistUrl = $artistFavourite['artisturl'];

                     //fetch favourite track(s)
                     $fetchtrackFavourite = mysql_query ("SELECT * FROM trackfavourites WHERE username = '$username' AND password = '$pass'")or die(mysql_error()); 
                     while ($trackFavourite = mysql_fetch_array($fetchtrackFavourite)){
                     $favouritedTrack = $trackFavourite['artistname'];
                     $favouritedTrackUrl = $trackFavourite['artisturl'];

                        //Get news from favourited artist(s)
                           //Get updates to bio
                           $fetchupdatedBio = mysql_query ("SELECT * FROM members WHERE artistname = '$favouritedArtist'")or die(mysql_error()); 
                           while ($updatedBio = mysql_fetch_array($fetchupdatedBio))
                           $updatedBio = $updatedBio['bio'];

                           //Get updates to profile pic
                           $fetchupdatedProfile = mysql_query ("SELECT * FROM members WHERE artistname = '$favouritedArtist'")or die(mysql_error()); 
                           while ($updatedProfile = mysql_fetch_array($fetchupdatedProfile))
                           $updatedProfile = $updatedProfile ['image1'];

                           //Get any new pictures
                           $fetchPic = mysql_query ("SELECT * FROM pictures WHERE artistname = '$favouritedArtist'")or die(mysql_error()); 
                           while ($pic = mysql_fetch_array($fetchPic))
                           $pic = $pic['picurl'];

                           //Get any new tracks
                           $fetchTracks = mysql_query ("SELECT * FROM tracks WHERE artistname = '$favouritedArtist'")or die(mysql_error()); 
                           while ($tracks = mysql_fetch_array($fetchTracks))
                           $trackurl = $tracks['trackurl'];
                           $trackname = $tracks['trackname'];

                           //Get any new gigs
                           $fetchGigs = mysql_query ("SELECT * FROM gigs WHERE artistname = '$favouritedArtist'")or die(mysql_error()); 
                           while ($gigs = mysql_fetch_array($fetchGigs))


                           //arrange gig data into format to be echoed
                           $gig = $favouritedArtist.' is playing for the gig ' .$gigs['gigname'].' at ' .$gigs['venue'].' on the '.$gigs['day'].'th of '.$gigs['month'].', '.$gigs['year'];


                           //Get any new sessions
                           $fetchSessions = mysql_query ("SELECT * FROM sessions WHERE artistname = '$favouritedArtist'")or die(mysql_error()); 
                           while ($sessions = mysql_fetch_array($fetchSessions))

                           $sessionName = $sessions ['title'];

                                  //Get new tracks from favourited tracks(s)if the artist has not been favourited
                                  $fetchnewTrack = mysql_query ("SELECT * FROM tracks WHERE artistname = '$favouritedTrack' AND artistname !='$favouritedArtist'")or die(mysql_error()); 
                                  while ($newTrack = mysql_fetch_array($fetchnewTrack))
                                  $trackname2 = $newTrack['trackname'];



                                      //asign all variables into an 
                                      echo $trackname;

                         }
                         }  
  • 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-08T14:11:17+00:00Added an answer on June 8, 2026 at 2:11 pm

    First of all, you should definitely try not to SELECT *, but just the content you need.
    Like :

    SELECT picurl FROM pictures WHERE artistname = '$favouritedArtist'
    

    instead of

    SELECT * FROM pictures WHERE artistname = '$favouritedArtist'
    

    In your :

    while ($tracks = mysql_fetch_array($fetchTracks))
    $trackurl = $tracks['trackurl'];
    $trackname = $tracks['trackname'];
    

    There is an error, because you don’t need brackets only when there is a single instruction after the while statement.

    Idem with your

    while ($sessions = mysql_fetch_array($fetchSessions))
    

    with no brackets, you can’t do so if there is more than one instruction related to the while.

    While are only needed when you know there will be multiple answers in you MySQL request. Since the might be only one user with this username, you don’t need a while.

    All of this are basics of php and mysql development, a simple google search would have given you the answer.
    I think you might need to read some more tutorials on basics of php and mysql.

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

Sidebar

Related Questions

I'm having a problem with scala generics. While the first function I defined here
I have a flash file menu i am having problem while link it to
Hey dudes.i am having this problem while symlinking. I have successfully deployed a ruby
I am having a problem while calling overloaded C# function through jquery post method.
I'm having this problem while writing my own HashTable. It all works, but when
Having a problem while deserializing a number of objects stored as BLOBs in a
I'm having an odd problem while deploying a Django site using Fabric. I've configured
I've been having this problem for a while and it's driving me nuts. I'm
as the title says I'm having the problem with content getting hidden while scrolling/dragging
While trying to troubleshoot a problem I'm having with a project, I noticed that

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.