join statement in mysql db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
qumar
Forum Commoner
Posts: 29
Joined: Wed Nov 01, 2006 8:20 am

join statement in mysql db

Post by qumar »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi friends,
i am using the following statements to display pictures and some inforamtion about the pictures.
i am using the statement in side the loop.

Code: Select all

<?php
$result = mysql_query("SELECT * FROM pictures WHERE event_id!=0 AND enable='Yes' GROUP BY event_id ORDER BY picture_id DESC");

			$result_all_rows = mysql_query("SELECT * FROM pictures WHERE event_id!=0 AND enable='Yes' GROUP BY event_id ORDER BY picture_id");

		 	$totalrows = mysql_num_rows($result_all_rows);

			if($totalrows)
			{
			$daily_pictures="<table  width='99%' border='0' cellpadding='0' align='center' cellspacing='2' align='center' bordercolor='#C0C0C0'>";
			$i=0;

			while ($row = mysql_fetch_array($result))
			{
			$small_pic=$row['picture_small_url'];
			$event_id=$row['event_id'];
			$picture_id=$row['picture_id'];
			$picture_date=$row['picture_date'];
			$picture_caption=addslashes($row['picture_caption']);
			$picture_caption1=str_replace('"','"',$picture_caption);
			$picture_date_formate=date('jS F  Y',strtotime($picture_date));

			$query_sql=mysql_query("SELECT * FROM events,pictures WHERE events.event_id=$event_id AND maaking_pictures.event_id=$event_id");
			$query_ret=mysql_fetch_array($query_sql);
			
			$count_rows=mysql_num_rows($query_sql);			

			$i++;
			if($i%3==1)		$daily_pictures.="<tr>";

			$daily_pictures.="<td>
			<table border='0' align='center' id='picturebox'>
				<tr>
					<td align='center' class='darkgrey' colspan='3'>$eventName1 <span class='highlight'>[ $count_rows ]</span></td>
				</tr>
				<tr>
					<td align='center' colspan='3'><img src='$small_pic'></td>
				</tr>

</table>
</td>";

			if($i%3==0)			$daily_pictures.="</tr>";
			}
			$daily_pictures.="</table>";

	}
	else
	{
		$daily_pictures="<p class='error'>No Event Pictures Added Yet <p>";

	}

	echo $daily_pictures;
?>


but, i want statement without using in the while loop statement.
can anybody help.
thanks,
qumar.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
sunilbhatia79
Forum Newbie
Posts: 24
Joined: Sun Nov 11, 2007 9:37 pm
Location: Mumbai, India

Post by sunilbhatia79 »

Can you please let me know what are you trying to achieve...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You don't need to query inside the loop. You can query both data sets then match in the loops.

You could also use a join, but I am not sure it will give you what you want at the moment.
Post Reply