[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3422
  • Last Modified:

create array with a loop from mysql database.

I have an array that i am trying to populate using information from my database. The array looks like this:

$feedList = Array(

// The first entry
Array("fileURL" => "http://www.softwaremarketingresource.com/blog-feed.xml",
      "itemCount" => 4,
      ),

Array("fileURL" => "http://www.feedforall.com/tutorials/FeedForAll_Tutorials.xml",
      "itemCount" => 4,
      ),

// The last entry
Array("fileURL" => "http://www.feedforall.com/blog-feed.xml",
      "itemCount" => 4
      ),
);

//////////////////////////////////////////////////
PHP CODE:

$theuser = $_GET['theuser'];

$query1 = "SELECT * FROM users WHERE userid = '$theuser'";
$result1 = mysql_query($query1) or die(mysql_error());

      while($row1 = mysql_fetch_array($result1)){
      
            $feedid = $row1['feedid'];
            
            $getfeedinfo = "SELECT * FROM feedinfo WHERE ID ='$feedid'";
            $feedinfo = mysql_query($getfeedinfo) or die(mysql_error());
            
                  while($feedinfocontent = mysql_fetch_array($feedinfo)){

                        $feedurl = $feedinfocontent['address'];

                  }
      }
///////////////////////////////////////////////

I have this php that grabs a list of URLs depending on the user ID. My attempts to combine the two scripts have all failed, help experts!
0
cookiejest
Asked:
cookiejest
  • 2
1 Solution
 
jonathanmelnickCommented:
$theuser = $_GET['theuser'];

$query1 = "SELECT * FROM users WHERE userid = '$theuser'";
$result1 = mysql_query($query1) or die(mysql_error());

// define the $feedList array
$feedList = array();

      while($row1 = mysql_fetch_array($result1)){
     
            $feedid = $row1['feedid'];
           
            $getfeedinfo = "SELECT * FROM feedinfo WHERE ID ='$feedid'";
            $feedinfo = mysql_query($getfeedinfo) or die(mysql_error());
           
                  while($feedinfocontent = mysql_fetch_array($feedinfo)){

                        $feedList[] = array(
                          'fileUrl' => $feedinfocontent['address'];
                          'itemCount' => 4
                         );
                  }
      }

// $feedList has been populated !
print_r($feedList);
0
 
cookiejestAuthor Commented:
Thanks for the response, i seem to be getting this error:

Parse error: syntax error, unexpected ';', expecting ')' in /home/.requiem/cookiejest/rss2facebook.com/thenews/merge/merge.php on line 83

which is very similar to what i was getting before
0
 
Khanh DoanSenior DeveloperCommented:
Change
    'fileUrl' => $feedinfocontent['address'];
to
    'fileUrl' => $feedinfocontent['address'],

Goodluck.
Bonmat86.
0
 
jonathanmelnickCommented:
exactly, I forgot to switch the semicolon to a comma. guess I was tired ;)  Here is the complete code again :

$theuser = $_GET['theuser'];

$query1 = "SELECT * FROM users WHERE userid = '$theuser'";
$result1 = mysql_query($query1) or die(mysql_error());

// define the $feedList array
$feedList = array();

      while($row1 = mysql_fetch_array($result1)){
     
            $feedid = $row1['feedid'];
           
            $getfeedinfo = "SELECT * FROM feedinfo WHERE ID ='$feedid'";
            $feedinfo = mysql_query($getfeedinfo) or die(mysql_error());
           
                  while($feedinfocontent = mysql_fetch_array($feedinfo)){

                        $feedList[] = array(
                          'fileUrl' => $feedinfocontent['address'],
                          'itemCount' => 4
                         );
                  }
      }

// $feedList has been populated !
print_r($feedList);
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now