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($feedinf o)){
$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!
$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($feedinf
$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!
ASKER
Thanks for the response, i seem to be getting this error:
Parse error: syntax error, unexpected ';', expecting ')' in /home/.requiem/cookiejest/ rss2facebo ok.com/the news/merge /merge.php on line 83
which is very similar to what i was getting before
Parse error: syntax error, unexpected ';', expecting ')' in /home/.requiem/cookiejest/
which is very similar to what i was getting before
Change
'fileUrl' => $feedinfocontent['address' ];
to
'fileUrl' => $feedinfocontent['address' ],
Goodluck.
Bonmat86.
'fileUrl' => $feedinfocontent['address'
to
'fileUrl' => $feedinfocontent['address'
Goodluck.
Bonmat86.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$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($feedinf
$feedList[] = array(
'fileUrl' => $feedinfocontent['address'
'itemCount' => 4
);
}
}
// $feedList has been populated !
print_r($feedList);