Need help getting photos in array and display in loop, returning none now

I am trying to return all the photos in the database that has the albumid associated with that table info. I can echo the $album->id (albumid) no problem, but my query it think is somewhat off. Please anyone.


<div id="photo-items" class="photo-list-item">
	<?php
	echo $album->id.'<br>';
	
	// fetch album photos and ids
	$database    =& JFactory::getDBO();
	$query  = "SELECT * FROM jos_photos where albumid  = ".$album->id." ORDER BY ASC";
	$photos = mysql_query($query);	 //This returns and array of photos, but then needs to display all the photos in loop below, but it not retuning none, even if there is 100 photos in table and in the folder directory
		
	if($photos)
	{	
	for( $i=0; $i<count($photos); $i++ ){
	$row =& $photos[$i];
	?>
		<div class="photo-item" id="photo-<?php echo $i;?>" title="<?php echo $this->escape($row->caption);?>">
			<a href="<?php echo $row->link;?>"><img class="" src="<?php echo $row->getThumbURI();?>" alt="<?php echo $this->escape($row->caption);?>" id="photoid-<?php echo $row->id;?>" /></a>
			<?php
			if( $isOwner )
			{
			?>
			<div class="photo-action">
				<a href="javascript:void(0);('<?php echo $row->id;?>');" class="remove"><?php echo JText::_('CC REMOVE');?></a>
			</div>
			<?php
			}
			?>
		</div>
	<?php
		}
	}
	else
	{
	?>
	<div class="empty-list"><?php echo JText::_('CC NO PHOTOS UPLOADED YET');?>   <button class="button button-upload" href="javascript: void(0);&amp;userid=88" id="upload-photos-button">Start Uploading</button></div>
	<?php
	}
	?>
</div>



Untested see comments.


<div id="photo-items" class="photo-list-item">
	<?php
	echo $album->id.'<br>';
	
	// fetch album photos and ids
	$database    =& JFactory::getDBO();
	
	/**
	 * Cast album ID to int to prevent possible SQL injection even though data looks relatively safe. You
	 * could also use mysql_real_escape_string but casting to an int seems simpiler and essentially provides
	 * the same result in regards to avoiding SQL injection.
	 */
	$query  = "SELECT * FROM jos_photos where albumid  = ".((int) $album->id)." ORDER BY ASC";
	
	/**
	 * The return value of mysql_query when selecting data is either false (failed query) or result resource (success)
	 */
	$result = mysql_query($query);	 //This returns and array of photos, but then needs to display all the photos in loop below, but it not retuning none, even if there is 100 photos in table and in the folder directory
	
	/**
	 * @todo
	 * You should implement some type of error handling specific to your environment and/or flow of HTML
	 */
	if(mysql_error()) {
		echo 'Query failed.';
		exit;
	}
	
	/**
	 * Gather all photos
	 */
	$photos = array();
	while($row=mysql_fetch_assoc($result)) {
		$photos[] = $row;
	}
		
	if($photos)
	{	
	for( $i=0; $i<count($photos); $i++ ){
	$row =& $photos[$i];
	?>
		<div class="photo-item" id="photo-<?php echo $i;?>" title="<?php echo $this->escape($row->caption);?>">
			<a href="<?php echo $row->link;?>"><img class="" src="<?php echo $row->getThumbURI();?>" alt="<?php echo $this->escape($row->caption);?>" id="photoid-<?php echo $row->id;?>" /></a>
			<?php
			if( $isOwner )
			{
			?>
			<div class="photo-action">
				<a href="javascript:void(0);('<?php echo $row->id;?>');" class="remove"><?php echo JText::_('CC REMOVE');?></a>
			</div>
			<?php
			}
			?>
		</div>
	<?php
		}
	}
	else
	{
	?>
	<div class="empty-list"><?php echo JText::_('CC NO PHOTOS UPLOADED YET');?>   <button class="button button-upload" href="javascript: void(0);&amp;userid=88" id="upload-photos-button">Start Uploading</button></div>
	<?php
	}
	?>
</div>

Though in all else doesn’t Joomla provide a DB adapter? I don’t think you should be using the mysql_* functions directly. It kinda defeats the purpose of using a framework and makes code more difficult to maintain.