php/mysql call first record in recordset

I want to call a set of records from the database but in addition, call out the most recent record in a repeating recordset. Basicly, single out the first record so that I can modify it’s appearance on a web page and in short, create a conditional statement that looks somewhat like this:
if record = 1, display “current cover”, else display “no cover”.

Here is the code I am working with:

                    <li class="boxgrid peek">
                    	<a href="project.php?work_ID=<?php echo $row_rstWebDesign['work_ID']; ?>" class="viewer-details">view project</a>
                        <a href="img_portfolio_dir/<?php echo $row_rstWebDesign['img_1']?>" rel="shadowbox[<?php echo $row_rstWebDesign['CatSe_type']?>]" title="<?php echo $row_rstWebDesign['caption_1']?>" class="viewer-gallery">view <?php echo $row_rstWebDesign['CatPr_type']; ?> <?php echo $row_rstWebDesign['CatSe_type']; ?> gallery</a>
                        <img src="img_portfolio_dir/<?php echo $row_rstWebDesign['cover_thmb']?>" class="cover" style="clip:rect(0px, 266px, 124px, 0px);" />
                        <img src="images/hover.png" class="hover cover" />
                        <!-- image only exists on the first, most recent record --> 
                        <img src="images/the-latest.png" class="cover current" />
                    </li>

I am hoping someone can help - been stuck on this problem for awhile and it’s causing me mass frustration. Thanks.

Mike

In the part of code you posted here, there is no recordset loop. It is hard to give advise on how you can implement what you need. But in short, you need to add a counter to your loop, that will increment by 1 on each iteration. And then add if() statement comparing if current record is first, and process it accordingly.

I’m sorry this is the full code:

            <ul>
	<?php do { ?>
                    <li class="boxgrid peek">
                       <a href="project.php?work_ID=<?php echo $row_rstWebDesign['work_ID']; ?>" class="viewer-details">view project</a>
                        <a href="img_portfolio_dir/<?php echo $row_rstWebDesign['img_1']?>" rel="shadowbox[<?php echo $row_rstWebDesign['CatSe_type']?>]" title="<?php echo $row_rstWebDesign['caption_1']?>" class="viewer-gallery">view <?php echo $row_rstWebDesign['CatPr_type']; ?> <?php echo $row_rstWebDesign['CatSe_type']; ?> gallery</a>
                        <img src="img_portfolio_dir/<?php echo $row_rstWebDesign['cover_thmb']?>" class="cover" style="clip:rect(0px, 266px, 124px, 0px);" />
                        <img src="images/hover.png" class="hover cover" />
                    </li>
                    <?php } while ($row_rstWebDesign = mysql_fetch_assoc($rstWebDesign)); ?>
             </ul>

I’m trying to get it so that on the first record that gets displayed, is added in the line after .

An example of the page I’m using this on is here:
http://www.duvecreative.com/test/dcredux/portfolio.php

I’ve done all the development thus far but I am a designer and need the help. Thanks.

If I were to create an if statement I wouldn’t know how to write how to find the first record. This is where I need help the most. I need an example of how this would work please and hopefully I can take it from there. Any takers? ;D

You need to add counter to your loop. Or use “for” loop, like this:
[php]for($i=1;$i<=mysql_num_rows($rstWebDesign);$i++){
$row_rstWebDesign = mysql_fetch_assoc($rstWebDesign)
if($i==1){ // <— first record

}
else{ // any other record

}
}[/php]

I thought this would have done it but no cigar. Here’s my revised script:

<?php for($i=1;$i<=mysql_num_rows($rstWebDesign);$i++){ $row_rstWebDesign = mysql_fetch_assoc($rstWebDesign) if($i==1) echo '
  • " class="viewer-details">view project" rel="shadowbox[<?php echo $row_rstWebDesign["CatSe_type"]?>]" title="<?php echo $row_rstWebDesign["caption_1"]?>" class="viewer-gallery">view <?php echo $row_rstWebDesign["CatPr_type"]; ?> <?php echo $row_rstWebDesign["CatSe_type"]; ?> gallery" class="cover" style="clip:rect(0px, 266px, 124px, 0px);" />
  • ';
    	  else
    		echo '<li class="boxgrid peek"><a href="project.php?work_ID=<?php echo $row_rstWebDesign["work_ID"]; ?>" class="viewer-details">view project</a><a href="img_portfolio_dir/<?php echo $row_rstWebDesign["img_1"]?>" rel="shadowbox[<?php echo $row_rstWebDesign["CatSe_type"]?>]" title="<?php echo $row_rstWebDesign["caption_1"]?>" class="viewer-gallery">view <?php echo $row_rstWebDesign["CatPr_type"]; ?> <?php echo $row_rstWebDesign["CatSe_type"]; ?> gallery</a><img src="img_portfolio_dir/<?php echo $row_rstWebDesign["cover_thmb"]?>" class="cover" style="clip:rect(0px, 266px, 124px, 0px);" /><img src="images/hover.png" class="hover cover" /></li>';
    
    	}                        
    

    ?>

    It’s reading an error here on line 424… if($i==1)

    here’s a link to my test page:
    http://www.duvecreative.com/test/dcredux/portfolioloop.php

    Missing semicolon at the end of this line:
    [php]$row_rstWebDesign = mysql_fetch_assoc($rstWebDesign);[/php]

    I’m using pagination. While what you have given me works, when I go to the second page the first record again shows up again. I need for it only to appear on the first and most recent example.

    I do not see pagination in the code you provided. If you are using pagination, you need to modify your sql query so that it returns only range of records for given page number.

    Here it is again but with pagination included and your suggestion incorporated into the code. Thanks again for you help - it worked!

    	  else
    		echo '<li class="boxgrid peek"><a href="project.php?work_ID=<?php echo $row_rstWebDesign["work_ID"]; ?>" class="viewer-details">view project</a><a href="img_portfolio_dir/<?php echo $row_rstWebDesign["img_1"]?>" rel="shadowbox[<?php echo $row_rstWebDesign["CatSe_type"]?>]" title="<?php echo $row_rstWebDesign["caption_1"]?>" class="viewer-gallery">view <?php echo $row_rstWebDesign["CatPr_type"]; ?> <?php echo $row_rstWebDesign["CatSe_type"]; ?> gallery</a><img src="img_portfolio_dir/<?php echo $row_rstWebDesign["cover_thmb"]?>" class="cover" style="clip:rect(0px, 266px, 124px, 0px);" /><img src="images/hover.png" class="hover cover" /></li>';
    
    	}                        
    

    ?>

                        <li style="position:absolute;left:0;top:-25px;width:100px;">
                        	<span><a href="<?php printf("%s?pageNum_rstWebDesign=%d%s", $currentPage, 0, $queryString_rstWebDesign); ?>">|&lt;</a></span>
                            <span><a href="<?php printf("%s?pageNum_rstWebDesign=%d%s", $currentPage, max(0, $pageNum_rstWebDesign - 1), $queryString_rstWebDesign); ?>">&lt;&lt;</a></span>
                            <span><a href="<?php printf("%s?pageNum_rstWebDesign=%d%s", $currentPage, min($totalPages_rstWebDesign, $pageNum_rstWebDesign + 1), $queryString_rstWebDesign); ?>">&gt;&gt;</a></span>
                            <span><a href="<?php printf("%s?pageNum_rstWebDesign=%d%s", $currentPage, $totalPages_rstWebDesign, $queryString_rstWebDesign); ?>">&gt;|</a></span>
                        </li>
                    </ul>
    Sponsor our Newsletter | Privacy Policy | Terms of Service