PHP:循环保持从SQL检索所有用户而不是一次一个

The concept idea here is that The database would store the youtube channel users name in a cell called YOUTUBE.

I needed the code to look up the USERDB, look up the YOUTUBE cell and retrieve all the usernames that were stored in a list (any blank cells would not show).

From here I needed the code to place users youtube username from the YOUTUBE cell into the FEEDURL

I needed this looped so it would do each individual user from the result. The problem I am getting is that the FEEDURL is showing all the users usernames in the URL instead of one.

EG. http://gdata.youtube.com/feeds/api/users/PewDiePie,MissFushi/uploads?max-results=13

but I need it to be like

EG. http://gdata.youtube.com/feeds/api/users/MissFushi/uploads?max-results=13

here is my code

$communityvideos = mysql_query("SELECT youtube FROM userdb WHERE rights='user' && youtube IS NOT NULL");
while($youtube = mysql_fetch_array($communityvideos)) {

$v[] = $youtube["youtube"];
}

$youtube2 = implode(',', array_filter($v));

$usernames = array($youtube2);

error_reporting(E_ALL);
foreach ($usernames as $user) {
$feedURL = 'http://gdata.youtube.com/feeds/api/users/' . $user .'/uploads?max-results=13';
$sxml = simplexml_load_file($feedURL);
}
$i=0;
foreach ($sxml->entry as $entry) {
      $media = $entry->children('media', true);
      $watch = (string)$media->group->player->attributes()->url;
      $thumbnail = (string)$media->group->thumbnail[0]->attributes()->url;

parse_str( parse_url( $watch, PHP_URL_QUERY ), $my_array_of_vars);

Finally I only want 13 videos showing in total. Not 13 videos from each user, just 13 from all the users joined together. Any ideas on that?

Try using this code. I've made some edits to the way the array was being manipulated. Make sure to start using the mysqli_* extension instead of mysql_* since the former is much more secure and less prone to SQL injection.

$communityvideos = mysql_query("SELECT youtube FROM userdb WHERE rights='user' && youtube IS NOT NULL");
$usernames = array();
while($youtube = mysql_fetch_assoc($communityvideos)) {
    $usernames[] = $youtube['youtube'];
}

//Redacted this does not do what you want it to do. This glues all usernames together and wrecks the $usernames array.
//$youtube2 = implode(',', array_filter($v));
//$usernames = array($youtube2);

error_reporting(E_ALL);

foreach ($usernames as $user){
$feedURL = 'http://gdata.youtube.com/feeds/api/users/' . $user .'/uploads?max-results=13';
$sxml = simplexml_load_file($feedURL);


// Place this inside the $usernames loop
$i=0;
foreach ($sxml->entry as $entry) {
      $media = $entry->children('media', true);
      $watch = (string)$media->group->player->attributes()->url;
      $thumbnail = (string)$media->group->thumbnail[0]->attributes()->url;

        parse_str( parse_url( $watch, PHP_URL_QUERY ), $my_array_of_vars);
        // And whatever came after this it doesn't show in the question.
    }
}

// You will have to figure the part below as well. Since you the last iteration of your foreach loop above will end with the last result in $sxml.
// The loop below will only loop the xml for the last result 

You dont need to do a implode to take the users name. Just do directly for each with array_filter($v) results:

$users = array_filter($v);
foreach ($users as $user) {
$feedURL = 'http://gdata.youtube.com/feeds/api/users/' . $user .'/uploads?max-results=13';
$sxml = simplexml_load_file($feedURL);
}
ommunityvideos = mysql_query("SELECT * FROM userdb WHERE rights='user' && youtube IS NOT NULL");
while($youtube = mysql_fetch_assoc($communityvideos)) {
    $v[] = $youtube['youtube'];

error_reporting(E_ALL);
$usernames = array_filter($v);
foreach ($usernames as $user){
$feedURL = 'http://gdata.youtube.com/feeds/api/users/' . $user .'/uploads?max-results=13';
$sxml = simplexml_load_file($feedURL);
$i=0;

foreach ($sxml->entry as $entry) {
      $media = $entry->children('media', true);
      $watch = (string)$media->group->player->attributes()->url;
      $thumbnail = (string)$media->group->thumbnail[0]->attributes()->url;

        parse_str( parse_url( $watch, PHP_URL_QUERY ), $my_array_of_vars);

for anyone reading and wondering how it was fixed to work in the end? Well here it is