J'ai une question qui m'a bloqué, peut-être que vous pouvez aider. J'ai le php suivant:Affectation de variable PHP
if(mysql_num_rows($result) > 0){
//if so set up the xml
$dom = new DOMDocument();
$response = $dom->createElement('response');
$encore = $dom->createElement('encoreSongs');
$dom->appendChild($response);
$previousDate = "";
//if yes cycle through all results, checking their artist
while($row = mysql_fetch_array($result)){
//check if the current songs artist is in the artist array
$song_name = $row['name'];
$song_artist = $row['artist'];
$song_date = $row['date'];
$song_city = $row['city'];
$song_state = $row['state'];
$song_location = $song_city . ', ' . $song_state;
$song_id = $row['unique_song_id'];
$song_segue = $row['part_of_a_sugue'];
$song_info = $dom->createElement('song');
$idElement = $dom->createElement('song_id');
$idText = $dom->createTextNode($song_id);
$idElement->appendChild($idText);
$song_info->appendChild($idElement);
$nameElement = $dom->createElement('song_name');
$nameText = $dom->createTextNode($song_name);
$nameElement->appendChild($nameText);
$song_info->appendChild($nameElement);
$artistElement = $dom->createElement('song_artist');
$artistText = $dom->createTextNode($song_artist);
$artistElement->appendChild($artistText);
$song_info->appendChild($artistElement);
$dateElement = $dom->createElement('song_date');
$dateText = $dom->createTextNode($song_date);
$dateElement->appendChild($dateText);
$song_info->appendChild($dateElement);
$locationElement = $dom->createElement('song_location');
$locationText = $dom->createTextNode($song_location);
$locationElement->appendChild($locationText);
$song_info->appendChild($locationElement);
$segueElement = $dom->createElement('song_segue');
$segueText = $dom->createTextNode($song_segue);
$segueElement->appendChild($segueText);
$song_info->appendChild($segueElement);
//if the song is part of an encore, save it for later
if($row['setOrEncore'] == 'encore'){
$encore->appendChild($song_info);
}
else{
/*if the previous song was an encore from another show and this song is a set,
assume that the previous group of encores went with the previous show
and append the encores before this new song/show */
if($previousDate != $song_date){
echo "tagged at " . $row['name'];
//affix encore songs to 'response'
$encore_songs = $encore->getElementsByTagName('song');
foreach($encore_songs as $a){
$response->appendChild($a);
}
//reset encore variable
$encore = $dom->createElement('encoreSongs');
}
//attach new song
$response->appendChild($song_info);
}
$previousDate = $row['date'];
}//end while
Mon but est de vérifier si la chanson en cours si ce n'est pas un rappel. Sinon, je veux vérifier et voir si elle a la même date que la chanson précédente. Sinon, je veux ajouter ce que j'ai dans '$ bis' à la réponse et réinitialiser '$ bis'. Mon problème est que '$ previousDate' (qui est initialisé à une chaîne vide) est toujours le même que '$ song_date'
Quelqu'un peut-il voir pourquoi?
D'où vient $ song_date? Pouvez-vous montrer la boucle complète? –
Non, la boucle semble o.k. pour moi. Je ne vois pas pourquoi previousDate ne serait pas correct. –