i have a gallery SCript which i saw in tutorial sitepoint.com
everything is working well except that i want to limit users,which means the albums will be opening accoding to user=name
WHERE SHOULD I PUT THE WHERE CLAUSE LIKE THIS user='$user'
in the script below.

query( "SELECT c.category_id,c.category_name,photo_filename,COUNT(photo_id)
						FROM gallery_category  as c 
						LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id 
						GROUP BY c.category_id" );

here is the link of the tutorial,any help will be appreciated.
http://www.sitepoint.com/article/php-gallery-system-minutes/

According to the mysql manual which has no mention of left join, it would be one of the following:

mysql_query( "SELECT c.category_id,c.category_name,photo_filename,COUNT(photo_id)
FROM gallery_category  as c 
WHERE user='$user'
LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id 
GROUP BY c.category_id" );

or

mysql_query( "SELECT c.category_id,c.category_name,photo_filename,COUNT(photo_id)
FROM gallery_category  as c 
LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id 
WHERE user='$user'
GROUP BY c.category_id" );

But when using this in a mysql query don't forget to make the mysql query one long line. Hope one of those examples works for ya.

i did as u suggested,tested all the ideas and it was giving me this error
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\viewgallery.php on line 23

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\wamp\www\viewgallery.php on line 43


down is the part of the code how i did it

<?php session_start();
$user=$_SESSION['user'];
	include("config.inc.php");
	

	// initialization
	$result_array = array();
	$counter = 0;

	$cid = (int)($_GET['cid']);
	$pid = (int)($_GET['pid']);

	// Category Listing

	if( empty($cid) && empty($pid) )
	{
		$number_of_categories_in_row = 2;

		$result = mysql_query( "SELECT c.category_id,c.category_name,photo_filename,COUNT(photo_id) FROM gallery_category  as c LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id WHERE user='$user' GROUP BY c.category_id" );
						
		//$cool=mysql_query( "SELECT from gallery_photos WHERE photo_category ='$cid' ORDER BY photo_id DESC LIMIT 1 " );				
						
		while($row = mysql_fetch_array( $result ))// this is line 23
		{
		
		if($row[3]==0){
		//echo"no photos";
		//$result_array[] ="<img src=album/folder.png  width=100 height=80 border=0 alt=$user>";
		$result_array[] ="<tr ><td><table class=forumdisplay bgcolor=#ffffff><tr valign=top><td width=120><a href='viewgallery.php?cid=".$row[0]."'><img src=album/folder.png  width=100 height=75 border=0 ></a></td><td width=480 align=left><table><tr><td><a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a></td></tr><tr><td>".$row[3]." photos </td></tr> <tr><td><a href='viewgallery.php?cid=".$row[0]."'>view album</a></td></tr></table></td></tr></table></td></tr>";
		
		}
		else
		{
		//$result_array[] = "<a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."<img src='".$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."'/>"."</a> "."(".$row[3].")";
		 
		$result_array[] ="<tr ><td><table class=forumdisplay bgcolor=#ffffff><tr valign=top ><td width=120><a href='viewgallery.php?cid=".$row[0]."'><img src='".$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."'/></a></td><td width=480 align=left><table><tr><td><a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a></td></tr><tr><td>".$row[3]." photos </td></tr><tr><td><a href='viewgallery.php?cid=".$row[0]."'>view album</a></td></tr></table></td></tr> </table></td></tr>";
		}
		
		
		
			
		}
		mysql_free_result( $result );	//this is line 43

i hope u can help me from here

What is the name of your user table? Is there a user_id column or something similar on the gallery_photos table?

i Succeeded !!
i just added this after the where clauses

WHERE c.user='$user'

instead of just user='$user'

This article has been dead for over six months. Start a new discussion instead.