Jump to content

[SOLVED] limit mysql_query amount


Recommended Posts

how can i start a new line after every three database entry's ?

 

here is my code

<div id="body"> 
<?php
if (isset($_GET['image_id']))
{
if ((int) $_GET['image_id'] > 0) 
{

$imageid = $_GET['image_id'];
$sql = "SELECT * FROM hayleyimages WHERE image_id=$imageid";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$imageprofname = $row['image_name'];
$imageprofcaption = $row['image_caption'];
$imageproflink = $row['image_link'];
if(mysql_num_rows($result) > 0)
{
?>
	<table align="center" border="1"><th><?php echo "$imageprofname"; ?></th>
<tr><td><?php echo '<a href="'.$row['image_link'].'" rel="lightbox" title="'.$row['image_caption']. '" ><img src="'.$row['image_link'].'"width="200px" /></a>'; ?></td><td width="200px"><?php echo 'Image ID :'.$row['image_id'].''; ?></td></tr><tr><td><?php echo ' '.$row['image_caption']. ' </a>'; ?></td></tr></table>
<?php
}
	if (mysql_num_rows($result) < 1) {
		 echo 'This ID does not exist in the database<br>';
		 echo "<a href=\"index.php\">Return to Image Page</a>";
		 exit();
	}
exit();
}
	else {
	 echo "Unknown Image ID! <br />";
	 echo "<a href=\"index.php\">Return to Image Page</a>";
	 exit();
	}
}
//No ID passed to page, display user list:
$query = "SELECT image_id, image_name, image_link, image_caption FROM `hayleyimages`";
$result = mysql_query($query) or die("Error:" . mysql_error());

if (mysql_num_rows($result) > 0) {
?>
<table border="1"><th>Images</th>
<?php
	while($row=mysql_fetch_array($result)){ // Start looping table row
	?>

	<tr><td><?php echo ' <a href="?image_id='.$row['image_id'].'">'.$row['image_name']. ' Details</a>'; ?></td><td><?php echo ' <a href="'.$row['image_link'].'" rel="lightbox [main]" title="'.$row['image_caption']. '" >'.$row['image_name']. ' </a>'; ?></td><td><?php echo ' <img src="'.$row['image_link'].'"width="150px" /></a>'; ?></td></tr>
	<?php

	}
	?>
</table>
<?php
		if (mysql_num_rows($result) < 1) {
		echo "No Images To Display";
		}
}
mysql_close();
?>
</div>
</body>
</html>

Link to comment
Share on other sites

<table border="1"><th>Images</th>

<?php
               $loop = 3;
	while($row=mysql_fetch_array($result)){ // Start looping table row

	if ($loop == 3 {
                        echo "<tr>";
                }

	$toecho .= '<td><a href="?image_id='.$row['image_id'].'">'.$row['image_name']. ' Details</a>; </td><td> <a href="'.$row['image_link'].'" rel="lightbox [main]" title="'.$row['image_caption']. '" >'.$row['image_name']. ' </a></td><td> <img src="'.$row['image_link'].'"width="150px" /></a></td>;
                <?php
                if ($loop == 3 {
                        echo "</tr>";
                        $loop=0;
                }   


	}
               if (substr($toecho, -5) != "</tr>") {
                  $toecho .= "</tr>";
               }
               echo $toecho;

</table>

 

Try it.  Didn't test it, but it should work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.