Link to home
Start Free TrialLog in
Avatar of cookiejest
cookiejest

asked on

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!
Avatar of jonathanmelnick
jonathanmelnick

$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);
Avatar of cookiejest

ASKER

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
Change
    'fileUrl' => $feedinfocontent['address'];
to
    'fileUrl' => $feedinfocontent['address'],

Goodluck.
Bonmat86.
ASKER CERTIFIED SOLUTION
Avatar of jonathanmelnick
jonathanmelnick

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial