Page 1 of 1

Query displays twice but I only want it displayed once.

Posted: Sat Jan 16, 2010 5:26 pm
by jimjordan
My page is displaying my query twice, I am connecting two tables and using a recordset but I cannot get my query to display my content without displaying two versions.

Site:

http://www.creativeink.ca/sean/my_listings.php


My Code:

<?php require_once('Connections/Sean.php'); ?>

<?php
mysql_select_db($database_Sean, $Sean);
$query_Archives = "SELECT * FROM pictures p INNER JOIN galleries g ON p.gallery_id = g.id WHERE active='1' ORDER BY g.id DESC";
$Archives = mysql_query($query_Archives, $Sean) or die(mysql_error());
$row_Archives = mysql_fetch_assoc($Archives);
$totalRows_Archives = mysql_num_rows($Archives);
?>


<?php if ($totalRows_Archives > 0) { // Show if recordset not empty ?>
<?php do { ?>
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center" class="text">
<tr>
<td>
<table width="99%" cellpadding="0" cellspacing="0" border="0" class="table" align="center">
<tr background="images/backbar.jpg" valign="bottom"><td align="center" class="title_mylisting" style="line-height:1.9em;"><?php echo substr(($row_Archives['title']), 0, 80); ?></td></tr>
<tr><td align="center"><br /><ul class="gallery clearfix">
<?php
$gallery_id = $row_Archives['id'];
$photoquery = mysql_query("SELECT * FROM pictures p INNER JOIN galleries g ON p.gallery_id = g.id WHERE gallery_id = '".$gallery_id."'");
$photos = mysql_num_rows($photoquery);

for($i = 0; $i<$photos; $i++) {
$row = mysql_fetch_array($photoquery);
if(is_int($i/1)) {
print "<li><a href=\"".$row['picture']."\" rel=\"prettyPhoto\" title=\"".$row['caption']."\"><img src=\"".$row['picture']."\" border=\"0\" height=\"70\" /></a></li>&nbsp;";
}else{
print "<li><a href=\"".$row['picture']."\" rel=\"prettyPhoto\" title=\"".$row['caption']."\"><img src=\"".$row['picture']."\" border=\"0\" height=\"70\" /></a></li>&nbsp;";
}
}
?></ul>

<?php } while ($row_Archives = mysql_fetch_assoc($Archives)); ?>
<?php } // Show if recordset not empty ?>
<?php if ($totalRows_Archives == 0) { // Show if recordset empty ?>
<p align="center"><img src="images/royal_lepage.jpg" border="0" /></p>
<?php } // Show if recordset empty ?>

<?php
mysql_free_result($Archives);
?>

Re: Query displays twice but I only want it displayed once.

Posted: Mon Jan 18, 2010 9:54 am
by social_experiment
How many records match the query? The reason I ask is the do-while statement. Try using :

Code: Select all

 
if ( $totalRows_Archives > 0 ) {
 // display records
}
else {
 // display something else
}