9three Posted September 26, 2009 Share Posted September 26, 2009 Hey, I can't seem to get 2 while loops to work properly. public function RandomFilterBox($intID) { $intID = (int)$intID; if (empty($intID)) return false; $strQueryCheckRandomSettings = 'SELECT u_id, random_settings from home_settings WHERE u_id = :id'; $objStatement = $this->DB->prepare($strQueryCheckRandomSettings); $objStatement->bindParam(':id', $intID, PDO::PARAM_INT); $objStatement->execute(); if ($row = $objStatement->fetch()) { if (!empty($row['random_settings'])) $strQueryRandom = 'AND ('.$row['random_settings'].')'; $strQuery = 'SELECT id, song_file FROM customers WHERE type = "A" AND verified = "Y" '.$strQueryRandom.' ORDER BY RAND() LIMIT 0, 18'; $objStatement->closeCursor(); $objStatement = $this->DB->prepare($strQuery); $objStatement->execute(); } else { $strQuery = 'SELECT id, song_file FROM customers WHERE type = "A" AND verified = "Y" ORDER BY RAND() LIMIT 0, 18'; $objStatement = $this->DB->prepare($strQuery); $objStatement->execute(); } $strQueryVotes = 'SELECT v_id, a_id, n_stars FROM votes WHERE v_id = :voter_id'; //$objStatement->closeCursor(); $objStatement2 = $this->DB->prepare($strQueryVotes); print_r($this->DB->errorInfo()); $objStatement2->bindParam(':voter_id', $intID, PDO::PARAM_INT); $objStatement2->execute(); $intI = 0; while ($rowArtist = $objStatement->fetch()) { while ($rowVotes = $objStatement2->fetch()) { See where the while loop starts? If I do while ($rowArtist = $objStatement->fetch()) { echo $rowArtist['id']; It works fine. If I do while ($rowArtist = $objStatement->fetch()) { while ($rowVotes = $objStatement2->fetch()) { echo $rowArtist['id']; It doesnt display anything. How can I get these two to work, I need to compare the values to continue. Link to comment https://forums.phpfreaks.com/topic/175567-nesting-while-loops/ Share on other sites More sharing options...
trq Posted September 26, 2009 Share Posted September 26, 2009 What are you really trying to do? You likely don't need all these loops at all. Link to comment https://forums.phpfreaks.com/topic/175567-nesting-while-loops/#findComment-925137 Share on other sites More sharing options...
9three Posted September 26, 2009 Author Share Posted September 26, 2009 Well I plan on changing up the SQL a little, probably a UNION (don't know yet). What I need to do is compare the $rowArtist['id'] and the $rowVotes['v_id'] Link to comment https://forums.phpfreaks.com/topic/175567-nesting-while-loops/#findComment-925148 Share on other sites More sharing options...
redarrow Posted September 26, 2009 Share Posted September 26, 2009 Why not use a msql join? http://dev.mysql.com/doc/refman/5.0/en/join.html Link to comment https://forums.phpfreaks.com/topic/175567-nesting-while-loops/#findComment-925160 Share on other sites More sharing options...
9three Posted September 26, 2009 Author Share Posted September 26, 2009 That is one of my options. I'm just wondering why nesting while loops like that don't work for me. Link to comment https://forums.phpfreaks.com/topic/175567-nesting-while-loops/#findComment-925445 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.