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

  • Home
  • SEARCH
  • 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 8304575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:53:13+00:00 2026-06-08T17:53:13+00:00

I had posted the code before but had asked it differently as I didn’t

  • 0

I had posted the code before but had asked it differently as I didn’t really know what was going on.

I have several while loops fetching data from the database to form a feed of the latest information. Before you ask I will use mysqli but am just using mysql for now so i can get the loops sorted because i feel more comfortable this way.

Each sql query can but not definitely have several rows of data so a while loop is needed. I also must organize all the data into an array at the end so it can all be ordered by timestamp (timestamp not in sql query yet).

The problem I am having is that to organize it all into the array, with the way it is done now, all the closing curly brackets must be after the array so that every bit of data can be put into it. Due to this some variables could be outputted more than once because there can be different numbers of rows in each sql query. The brackets are not arranged like this at the moment by the way.

In the code below the brackets for each of the second lot of while loops are straight after the variables. This means only one row in the table is outputted into the array.

I hope that that explains it. It’s the best I could do. How can I arrange the while loops so that ALL data from EACH of the second lot of querys can be outputted into the array?

<?php
    //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 bio FROM members WHERE artistname = '$favouritedArtist'")or die(mysql_error()); 
            while ($updatedBio = mysql_fetch_array($fetchupdatedBio)){
                $updatedBio = $updatedBio['bio'];
            }

            //Get any new pictures
            $fetchPic = mysql_query ("SELECT picurl 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 title 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'];
                $trackurl2 = $newTrack['trackname'];
            }

            //asign all variables into an array
            //echo 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-06-08T17:53:16+00:00Added an answer on June 8, 2026 at 5:53 pm

    Your code should have been indented since the beginning.
    In order to get help, please at least make yourself helpable.

    Now let’s see where the problem is.
    If I did correctly get your problem, just use temporary arrays for each of your requests.
    But, as said, PDO gives you a powerful tool named fetchAll. You should give it a look.

    ( http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers )

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

Sidebar

Related Questions

I know this has been asked before but I have looked at every answer
I have posted on this topic before, but as yet I have not had
I posted another one on this,, but i had to edit it really much...
This has been asked before, but the other poster's concern had more to do
I had posted a question in regards to this code. I found that JTextArea
I had posted this earlier on Stack Overflow, but couldn't get a positive result.
I posted before about part of my validation not working. I had to redo
I have a complex C code with me and while executing it, I chanced
while programming throughout the years I have never posted a question on this website,
I had posted a thread a while back about avoiding adding blank rows into

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.