Click to See Complete Forum and Search --> : fast php question


izlik
04-17-2008, 11:53 AM
this script is supposed to list 30 images from my database, how can i make it display them 10 per row horizontaly ?

<?

//This is the number of results displayed per page
$page_rows = 30;

?>

<?php

//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($pagenum)))
{
$pagenum = 1;
}

//Edit $result to be your query
$qx = "SELECT * FROM `images` WHERE `tags` LIKE '%".mysql_real_escape_string($_GET['tag'])."%'";
$resultx = mysql_query($qx);
//OR die(mysql_error());

//This is where you display your query results
//while($info = mysql_fetch_array( $result ))
//{
//Print $info['Name'];
//echo "<br>";
//}
//echo "<p>";

$rows = mysql_num_rows($resultx);



//This tells us the page number of our last page
$last = ceil($rows/$page_rows);


//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}



// This shows the user what page they are on, and the total number of pages

$max = $page_rows * ($pagenum - 1);


//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1)
{
$pagenum = 1;
}

echo " --Page $pagenum of $last-- <p>";






if ($pagenum == 1)
{
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1&amp;tag={$_GET['tag']}'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous&amp;tag={$_GET['tag']}'> <-Previous</a> ";
}

//just a spacer
echo " ---- ";

if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next&amp;tag={$_GET['tag']}'>Next -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last&amp;tag={$_GET['tag']}'>Last ->></a> ";
}

$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
//echo $max;



$page = 1;
$limit = 30;
$result = mysql_query("SELECT COUNT(*) FROM `images` WHERE `tags` LIKE '%". mysql_real_escape_string($_GET['tag']) ."%'");
$count = mysql_result($result, 0);

if(isset($_GET['page']) && $_GET['page'] >= 1 && $_GET['page'] <= ($count / $limit)) {
$page = (int)$_GET['page'];
}


$offset = $limit * ($page - 1);

$query = "SELECT * FROM `images` WHERE `tags` LIKE '%". mysql_real_escape_string($_GET['tag']) ."%' ORDER BY `views` $max";
$result = mysql_query($query);

if(!$result) {
echo "Error with query";
exit;
}

while($row = mysql_fetch_array($result)) {
echo '
<div style="float:left;width:55%">
<a href="/show.php/' .$row['id'].'_' .$row['name'].'">
<img src="/out.php/t' .$row['id'].'_' .$row['name'].' width="75" height="75">
</a>
<br>Views:' .$row['views'].'
<br><br>
</div>';
}

?>
<div style="clear:both">
</div>