techiefreak05 Posted October 21, 2007 Share Posted October 21, 2007 I have a widget system on my site Im trying to make, where users can choose which widgets they want to display on their home page. I have the following code that selects which "widgets" the user has, and then the second query in the code is supposed to pick out the widgets that the user doesnt already have.. <?php $queryFlips = mysql_query("SELECT flipID FROM userFlips WHERE `userID` = '$_SESSION[id]'") or die(mysql_error()); //Get FLIPS user has. $db = mysql_fetch_array($queryFlips); $fid=$db[flipID]; $queryFlips2 = mysql_query("SELECT * FROM flips WHERE `id` != '$fid'") or die(mysql_error()); // Get info of flips that user doesnt have. while ($db2 = mysql_fetch_array($queryFlips2)){ $flipName=$db2['name']; $flipId=$db2['id']; echo '<tr> <td><form action="" method="post"><input type="submit" name="add" value="Add"><input type="hidden" name="addID" value="' . $flipId . '"></form></td><td>' . $flipName . '</td> </tr>'; } ?> But.. it is displaying widgets that I already have... I'm not great at joining queries or what ever its called, so id love some help! Quote Link to comment https://forums.phpfreaks.com/topic/74180-solved-too-many-rows-outputed/ Share on other sites More sharing options...
Barand Posted October 21, 2007 Share Posted October 21, 2007 [pre] user userflips flips -------- --------- -------- userID --- userID +--- flipID username flipID ---+ name [/pre] To get user's flips SELECT f.name FROM flips f INNER JOIN userflips uf ON uf.flipID = f.flipID WHERE uf.userID = '$user'; flips user doesn't have SELECT f.name FROM flips f LEFT JOIN userflips uf ON uf.flipID = f.flipID AND uf.userID = '$user' WHERE uf.flipID IS NULL Quote Link to comment https://forums.phpfreaks.com/topic/74180-solved-too-many-rows-outputed/#findComment-375060 Share on other sites More sharing options...
techiefreak05 Posted October 22, 2007 Author Share Posted October 22, 2007 should that work right away? anything I need to change? Also, what is "f.name" and "uf" ?? Quote Link to comment https://forums.phpfreaks.com/topic/74180-solved-too-many-rows-outputed/#findComment-375129 Share on other sites More sharing options...
Barand Posted October 22, 2007 Share Posted October 22, 2007 table aliases SELECT f.name FROM flips f LEFT JOIN userflips uf ON uf.flipID = f.flipID AND uf.userID = '$user' WHERE uf.flipID IS NULL $user = $_SESSION['id']; Quote Link to comment https://forums.phpfreaks.com/topic/74180-solved-too-many-rows-outputed/#findComment-375131 Share on other sites More sharing options...
techiefreak05 Posted October 22, 2007 Author Share Posted October 22, 2007 Oh ok, thanks a lot, I'll give it a try and return with the results. Quote Link to comment https://forums.phpfreaks.com/topic/74180-solved-too-many-rows-outputed/#findComment-375136 Share on other sites More sharing options...
techiefreak05 Posted October 22, 2007 Author Share Posted October 22, 2007 It works great! Thanks a lot! I needed to change the "f.flipID" to "f.id" because in the "flips" table, the id column is called "id". and I added a while loop: <?php $queryFlips = mysql_query("SELECT f.name FROM flips f LEFT JOIN userFlips uf ON uf.flipID = f.id AND uf.userID = '$_SESSION[id]' WHERE uf.flipID IS NULL"); while($db = mysql_fetch_array($queryFlips)){ $flipId=$db['id']; $flipName=$db['name']; echo '<tr> <td><form action="" method="post"><input type="submit" name="add" value="Add"><input type="hidden" name="addID" value="' . $flipId . '"></form></td><td>' . $flipName . '</td> </tr>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74180-solved-too-many-rows-outputed/#findComment-375142 Share on other sites More sharing options...
Barand Posted October 22, 2007 Share Posted October 22, 2007 You'll need to select f.id as well as f.name. Quote Link to comment https://forums.phpfreaks.com/topic/74180-solved-too-many-rows-outputed/#findComment-375145 Share on other sites More sharing options...
techiefreak05 Posted October 22, 2007 Author Share Posted October 22, 2007 I was JUST going to ask about that Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/74180-solved-too-many-rows-outputed/#findComment-375147 Share on other sites More sharing options...
techiefreak05 Posted October 22, 2007 Author Share Posted October 22, 2007 Uh oh, wait. it's not quite working yet. I had this, which selected the flip name just fine, but not the ID.. <?php while($db = mysql_fetch_array($queryFlips)){ $flipId=$db['id']; // this didnt work. $flipName=$db['name']; // this DID work. ?> Then I changed it to this, and now name doesnt work as well as ID. <?php while($db = mysql_fetch_array($queryFlips)){ $flipId=$db['f.id']; //this doesnt work.. $flipName=$db['f.name']; ///this doesnt work either. ?> Quote Link to comment https://forums.phpfreaks.com/topic/74180-solved-too-many-rows-outputed/#findComment-375148 Share on other sites More sharing options...
Barand Posted October 22, 2007 Share Posted October 22, 2007 did you change the query to SELECT f.id, f.name FROM flips f LEFT JOIN userFlips uf ON uf.flipID = f.id AND uf.userID = '$_SESSION[id]' WHERE uf.flipID IS NULL Quote Link to comment https://forums.phpfreaks.com/topic/74180-solved-too-many-rows-outputed/#findComment-375150 Share on other sites More sharing options...
techiefreak05 Posted October 22, 2007 Author Share Posted October 22, 2007 Ah, didnt catch that. Ill do it now. Quote Link to comment https://forums.phpfreaks.com/topic/74180-solved-too-many-rows-outputed/#findComment-375152 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.