我對mysql_fetch_array的while函數有問題。我已經在聲明之後試用了什麼,現在我的工作比以前更好。我以爲我可以在彼此內部運行一個循環,但顯然不是。我現在在前兩個語句中有大括號,其他都沒有,你可以在代碼中清楚地看到。mysql_fetch_array導致意外錯誤的幾個while語句
但是,我現在意味着每個語句之後有多個變量會導致第二個變量在回顯時停止工作等。我嘗試避免使用數組作爲變量,事後佈局會更容易。不知道這裏發生了什麼。我通常在每個陳述後都使用大括號,但這只是使整個事情變得多餘。我應該怎麼做才能保持所有變量的正常工作?我對PHP並不擅長,並感謝迄今爲止的所有幫助!
我只是爲了未來的目的而陷入混亂,所以我知道我應該使用mysqli。我最近才學會了mysqli,所以我只是使用mysql,因爲我暫時感覺更舒適。
這裏是無論如何代碼:
所有的//fetch favourited artist(s)
$fetchartistFavourite = mysql_query("SELECT * FROM artistfavourites WHERE username = '$username' AND password = '$pass';")or die(mysql_error());
while ($artistFavourite = mysql_fetch_array($fetchartistFavourite)){
$favouritedArtist = $artistFavourite['artistname'];
$favouritedArtistUrl = $artistFavourite['artisturl'];
//fetch favourite track(s)
$fetchtrackFavourite = mysql_query ("SELECT * FROM trackfavourites WHERE username = '$username' AND password = '$pass'")or die(mysql_error());
while ($trackFavourite = mysql_fetch_array($fetchtrackFavourite)){
$favouritedTrack = $trackFavourite['artistname'];
$favouritedTrackUrl = $trackFavourite['artisturl'];
//Get news from favourited artist(s)
//Get updates to bio
$fetchupdatedBio = mysql_query ("SELECT * FROM members WHERE artistname = '$favouritedArtist'")or die(mysql_error());
while ($updatedBio = mysql_fetch_array($fetchupdatedBio))
$updatedBio = $updatedBio['bio'];
//Get updates to profile pic
$fetchupdatedProfile = mysql_query ("SELECT * FROM members WHERE artistname = '$favouritedArtist'")or die(mysql_error());
while ($updatedProfile = mysql_fetch_array($fetchupdatedProfile))
$updatedProfile = $updatedProfile ['image1'];
//Get any new pictures
$fetchPic = mysql_query ("SELECT * FROM pictures WHERE artistname = '$favouritedArtist'")or die(mysql_error());
while ($pic = mysql_fetch_array($fetchPic))
$pic = $pic['picurl'];
//Get any new tracks
$fetchTracks = mysql_query ("SELECT * FROM tracks WHERE artistname = '$favouritedArtist'")or die(mysql_error());
while ($tracks = mysql_fetch_array($fetchTracks))
$trackurl = $tracks['trackurl'];
$trackname = $tracks['trackname'];
//Get any new gigs
$fetchGigs = mysql_query ("SELECT * FROM gigs WHERE artistname = '$favouritedArtist'")or die(mysql_error());
while ($gigs = mysql_fetch_array($fetchGigs))
//arrange gig data into format to be echoed
$gig = $favouritedArtist.' is playing for the gig ' .$gigs['gigname'].' at ' .$gigs['venue'].' on the '.$gigs['day'].'th of '.$gigs['month'].', '.$gigs['year'];
//Get any new sessions
$fetchSessions = mysql_query ("SELECT * FROM sessions WHERE artistname = '$favouritedArtist'")or die(mysql_error());
while ($sessions = mysql_fetch_array($fetchSessions))
$sessionName = $sessions ['title'];
//Get new tracks from favourited tracks(s)if the artist has not been favourited
$fetchnewTrack = mysql_query ("SELECT * FROM tracks WHERE artistname = '$favouritedTrack' AND artistname !='$favouritedArtist'")or die(mysql_error());
while ($newTrack = mysql_fetch_array($fetchnewTrack))
$trackname2 = $newTrack['trackname'];
//asign all variables into an
echo $trackname;
}
}
究竟是什麼問題?你不應該使用mysqli。你應該使用PDO – karka91 2012-07-29 17:38:00
我改變了一些問題,但基本上我不知道發生了什麼,但似乎有幾個while語句停止變量的工作。我對PDO和mysqli以及mysqli進行了大量研究,這是該項目的更好選擇 – 2012-07-29 17:42:28