Hi,
I am trying to display images from my db with the following code..

<?php
			include_once("scripts/connect.php");
			if ($q == "All Images") {
			$sql = mysql_query("SELECT * FROM gallery");
			$q = "All Images";
			} else {
			$sql = mysql_query("SELECT * FROM gallery WHERE caption LIKE '%$q%'");
			}
			$limit = 7;
			$count = 0;
			while($row = mysql_fetch_array($sql)) {
			$caption = $row['caption'];
			$id = $row['id'];
			$num_results = mysql_num_rows($sql);
			if($num_results == 0) {
			echo "<tr><td><font face='Arial'><b>Sorry, no results found...</b></font></td></tr>";
			} else {
			if($count < $limit) {
			if ($count ==0) {
			echo "<tr>";
			}
			echo "<td style='border-style:none; border-width:medium;'>";
			echo "<p align='center'>";
			echo "<a href='cms/gallery/$id.jpg' title='$caption' rel='lightbox[PhotoGallery1]'>";
			echo "<img id='$id' style='opacity:0.65' onmouseover=\"Animate('$id', '', '', '', '', '100', 250);return 

false;\" onmouseout=\"Animate('$id', '', '', '', '', '65', 250);return false;\" src='cms/gallery/$id.jpg' width='100' >";
			echo "</a>";
			echo "</td>";
} 
else {
$count == 0;
			echo "</tr><td style='border-style:none; border-width:medium;'>";
			echo "<p align='center'>";
			echo "<a href='cms/gallery/$id.jpg' title='$caption' rel='lightbox[PhotoGallery1]'>";
			echo "<img id='$id' style='opacity:0.65' onmouseover=\"Animate('$id', '', '', '', '', '100', 250);return 

false;\" onmouseout=\"Animate('$id', '', '', '', '', '65', 250);return false;\" src='cms/gallery/$id.jpg' width='100' >";
			echo "</a>";
			echo "</td>";
}
$count++;
}}
echo "</tr>";
?>

But when I execute it, it display first seven results in columns and the others 1 in 1 row... PLZ HELp...

The line:

echo "</tr><td style='border-style:none; border-width:medium;'>";

is at fault I think. You close the row with the </tr> followed immediately with a <td> node. Are you able to view the source in the browser? I think you will find that you will have cells (<td>) outside of rows (<tr>) because of the line mentioned above, which will confuse the browser when it renders the table.

Also, you have some <p> tags that aren't closed, and your <img> tags aren't closed either.

No, i tried everything but it didn't work... PLZ HELP...!!!

hi

I think line no 9 $limit = 7;

and also you are checking if($count < $limit)

you have given the limit as 7 by default so it is not going beyond 7 so please try to change and test it

no, that's not the problem, i have changed it many times... i don't know what else..

please post your last iteration of code.
you said you've 'changed it many times' so what are you looking at now, what issues are you still having?

plzzzzzzzzzzz help
But when I execute it, it display first seven results in columns and the others 1 in 1 row... PLZ HELp...

in what format do you want to display your images?

in what format do you want to display your images?

Sorry.. I think my question is not understandable to you. format means 4x4 or 3x3 grid format.

it can be any format....

any format

I would not exactly recommend doing it this way, but this will solve your issue.

<?php

    include_once("scripts/connect.php");
    if ($q == "All Images") {
		$sql = mysql_query("SELECT * FROM gallery");
		$q = "All Images";
    } else {
		$sql = mysql_query("SELECT * FROM gallery WHERE caption LIKE '%$q%'");
    }
    
    $count = 0;
	$limit = 7;
	$num_results = mysql_num_rows($sql);
	/******
	// fake the data
	$cap=array();
	$ids = array();
	for ($s=0;$s<21;$s++) {
		array_push($cap,'caption-'.$s);
		array_push($ids,'id-'.$s);
		//$caption[$s] = 'caption-'$s;
		//$id[$s] = 'id-'$s;
	}
	*/
	// fake data from array above, this will be in the numrows variable.
	// $cntr = count($cap);
	//echo "cntr = " . $cntr . "<BR>";
	// want to loop on 7,
	echo "<table>";
	//foreach($cap as $c) {
	//echo "c = " . $c . "<BR>";
	//echo "id = " . $ids[$cnt] . "<BR>";
	while($row = mysql_fetch_array($sql)) {

		//echo "caption = " . $caption . "<BR />";
		//echo "id = " . $id . "<BR>";
		$caption = $c;
		$id = $ids[$cnt];
		//$caption = $row['caption'];
		//$id = $row['id'];		
		if($num_results == 0) {
			echo "<tr><td><font face='Arial'><b>Sorry, no results found...</b></font></td></tr>";
		} else {
			if($count < $limit) {
				if ($count == 0) {
					//echo "CNT was 0<br>";
					echo "<tr>";
				}
				
				echo "<td style='border-style:none; border-width:medium;'>";
				echo "<p align='center'>";
				echo "<a href='cms/gallery/$id.jpg' title='$caption' rel='lightbox[PhotoGallery1]'>";
				echo "<img id='$id' style='opacity:0.65' onmouseover=\"Animate('$id', '', '', '', '', '100', 250);return
				 
				false;\" onmouseout=\"Animate('$id', '', '', '', '', '65', 250);return false;\" src='cms/gallery/$id.jpg' width='100' >";
				echo "</a>";
				echo "</td>";
			} else {
			    // this is not how I would recommend solving your problem but this code will do the action you are requesting.
				// based on limit of 7 you want to start a new row for every 8th total record coming across so:
			    if ($count == 8 || $count == 16 || $count == 24 || $count == 32 || $count == 40 || $count == 48) {
					echo "</tr><tr>";
				}			
				//$cnt == 0;
				echo "<td style='border-style:none; border-width:medium;'>";
				echo "<p align='center'>";
				echo "<a href='cms/gallery/$id.jpg' title='$caption' rel='lightbox[PhotoGallery1]'>";
				echo "<img id='$id' style='opacity:0.65' onmouseover=\"Animate('$id', '', '', '', '', '100', 250);return
				false;\" onmouseout=\"Animate('$id', '', '', '', '', '65', 250);return false;\" src='cms/gallery/$id.jpg' width='100' >";
				echo "</a>";
				echo "</td>";
			}
		
		//$count++;  <--- this was in the wrong place.
		}		
	$count++;
	}
echo "</tr>";
echo "</table>";
?>

ddymacek Thankyou very much...!!! It Worked...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.