PHP Loop

I have an html website that i need to make dynamic using php, so that all records are read from sql tables

My HTML looks like this:

<li id="page_Portfolio">
						<div class="box">
							<a href="#" data-type="close" class="close"><span></span></a>
							<a href="#" class="prev"><span></span></a>
							<a href="#" class="next"><span></span></a>
							<h2>Latest Works</h2>
							<div id="gallery1">
								<ul>
									<li>
										<a href="#!/page_More"><img src="images/page2_img1.jpg" alt=""></a>
										<p>Magnis disient monteidi culus musulla duiuscgiat males uadase odiokaorbi nuncodio, gravidare atursuctus a lorem. Maecenasen tristique orci ac sem. </p>
										<a href="#!/page_More"><img src="images/page2_img2.jpg" alt=""></a>
										<p>Magnis disient monteidi culus musulla duiuscgiat males uadase odiokaorbi nuncodio, gravidare atursuctus a lorem. Maecenasen tristique orci ac sem. </p>
									</li>
									<li>
										<a href="#!/page_More"><img src="images/page2_img3.jpg" alt=""></a>
										<p>Baecenas tristique orci ac sem. Duis ultricies pharetra magna. Kertac accumsan malesuada orci. Donec sit amet eros. Lorem ipsum dolor sitamet consectet. </p>
										<a href="#!/page_More"><img src="images/page2_img4.jpg" alt=""></a>
										<p>Baecenas tristique orci ac sem. Duis ultricies pharetra magna. Kertac accumsan malesuada orci. Donec sit amet eros. Lorem ipsum dolor sitamet consectet. </p>
									</li>
								</ul>
							</div>
						</div>
					</li>

Open in new window


So basically the portfolio section has 2 records in every <li></li>
What I have so far is 1 record in every <li> and its working great but i have to have two rows from the db in each li.

Below is what I have done so far:

#website portfolio
function get_websites(){
$strSQL="SELECT * FROM cms_media WHERE media_active = 1 and media_gallerytype = 2 ORDER BY media_date DESC";
$objRS=mysql_query($strSQL);
	
	echo '<li id="page_PortfolioWeb">';
						echo '<div class="box">';
							echo '<a href="#" data-type="close" class="close"><span></span></a>';
							echo '<a href="#" class="prev"><span></span></a>';
							echo '<a href="#" class="next"><span></span></a>';
							echo '<h2>Websites</h2>';
							echo '<div id="gallery1">';
							echo '<ul>';
							
	while($row=mysql_fetch_object($objRS)){

 							echo '<li>';
							
							
					
							echo "<a href='#!/page_MorePro?id=".$row->media_id."'>".gd_image($row->media_pic,'cropratio=2:1&width=240&height=120')."</a>";
							echo '<p>'.$row->media_name.'</p>';
							
			
							
							
							echo '</li>';
							
	}
							
							echo '</ul>';
							echo '</div>';
						echo '</div>';
					echo '</li>';

}

Open in new window

LVL 1
zahimezherAsked:
Who is Participating?
 
gr8gonzoConsultantCommented:
Try this:

$counter = 0;
$LIs = array();
$LI = "";
while($row=mysql_fetch_object($objRS)){

$LI .= "<a href='#!/page_MorePro?id=".$row->media_id."'>".gd_image($row->media_pic,'cropratio=2:1&width=240&height=120')."</a>";
$LI .= '<p>'.$row->media_name.'</p>';

$counter++;
if($counter == 2)
{
  $LIs[] = $LI;
  $LI = "";
  $counter = 0;
}
      }

echo "<li>".implode("</li><li>",$LIs)."</li>";
0
 
zahimezherAuthor Commented:
Brilliant! :) Thank you
0
 
zahimezherAuthor Commented:
@gr8gonzo
Check this question out it related to what we already started.
Array Issue by:zahi mezher

thanx again
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.