Jump to content

[SOLVED] Too many rows outputed!


techiefreak05

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/74180-solved-too-many-rows-outputed/
Share on other sites

[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

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>';
}
?>

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.
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.