• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3429
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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