Jump to content

[SOLVED] I need some help with my code!


vetman

Recommended Posts

My code doesn't give me columns and rows in a table, I believe the code might bew wrong. Could somebody take a look. It works but instead of putting 3 columns per row, it puts 1. I'm kind of lost on how to fix it. I'm reading my picture locations from my table.

Here my code!

Thanks in advance.

 

 

<?php
include 'config.php';	// include your code to connect to DB.

$con = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db("rwts_webmaster") or die(mysql_error());

        //echo "Connected to Database <br>";
//Place code to connect to your DB here.


$tbl_name="gold";		//your table name

// How many adjacent pages should be shown on each side?
$adjacents = 2;

/*
   First get total number of rows in data table.
   If you have a WHERE clause in your query, make sure you mirror it here.
*/
$query = "SELECT COUNT(*) as num FROM $tbl_name";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];

/* Setup vars for query. */
$targetpage = "retrieve_gold-3.php"; 	//your file name  (the name of this file)

$limit = 3; 								//how many items to show per page

$page = $_GET['page'];
if($page)
	$start = ($page - 1) * $limit; 			//first item to display on this page
else
	$start = 0;								//if no page var is given, set start to 0

/* Get data. */
$sql = "SELECT * FROM $tbl_name LIMIT $start, $limit";
$result = mysql_query($sql);

/* Setup page vars for display. */
if ($page == 0) $page = 1;					//if no page var is given, default to 1.
$prev = $page - 1;							//previous page is page - 1
$next = $page + 1;							//next page is page + 1
$lastpage = ceil($total_pages/$limit);		//lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1;						//last page minus 1

/*
	Now we apply our rules and draw the pagination object.
	We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{
	$pagination .= "<div class=\"pagination\">";
	//previous button
	if ($page > 1)
		$pagination.= "<a href=\"$targetpage?page=$prev\">previous</a>";
	else
		$pagination.= "<span class=\"disabled\">previous</span>";

	//pages
	if ($lastpage < 7 + ($adjacents * 2))	//not enough pages to bother breaking it up
	{
		for ($counter = 1; $counter <= $lastpage; $counter++)
		{
			if ($counter == $page)
				$pagination.= "<span class=\"current\">$counter</span>";
			else
				$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
		}
	}
	elseif($lastpage > 5 + ($adjacents * 2))	//enough pages to hide some
	{
		//close to beginning; only hide later pages
		if($page < 1 + ($adjacents * 2))
		{
			for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
			}
			$pagination.= "...";
			$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
			$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
		}
		//in middle; hide some front and some back
		elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
		{
			$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
			$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
			$pagination.= "...";
			for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
			}
			$pagination.= "...";
			$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
			$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
		}
		//close to end; only hide early pages
		else
		{
			$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
			$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
			$pagination.= "...";
			for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
			}
		}
	}

	//next button
	if ($page < $counter - 1)
		$pagination.= "<a href=\"$targetpage?page=$next\">next</a>";
	else
		$pagination.= "<span class=\"disabled\">next</span>";
	$pagination.= "</div>\n";
}
?>
<html>
<head>
<title>My Gold Page</title>
<link rel="stylesheet" type="text/css"
media="screen" href="page_style.php">
<title>Gold Specimens</title>
    <script type="text/javascript" src="highslide/highslide.js"></script>
    <script type="text/javascript">
        hs.graphicsDir = 'highslide/graphics/';
        hs.showCredits = false;
     </script>

     <style type="text/css">
	* {
	    font-family: Verdana, Helvetica;
	    font-size: 10pt;
	}
	.highslide {
		cursor: url(highslide/graphics/zoomin.cur), pointer;
	    outline: none;
	}
	.highslide-active-anchor img {
		visibility: hidden;
	}
	.highslide img {
		border: 2px solid gray;
	}
	.highslide:hover img {
		border: 2px solid white;
	}
	.highslide-wrapper {
		background: white;
	}
	.highslide-image {
		border: 10px solid white;
	}
	.highslide-image-blur {
	}
	.highslide-caption {
	    display: none;
	    border: 5px solid white;
	    border-top: none;
	    padding: 5px;
	    background-color: white;
	}
	.highslide-loading {
	    display: block;
		color: black;
		font-size: 8pt;
		font-family: sans-serif;
		font-weight: bold;
	    text-decoration: none;
		padding: 2px;
		border: 1px solid black;
	    background-color: white;

	    padding-left: 22px;
	    background-image: url(highslide/graphics/loader.white.gif);
	    background-repeat: no-repeat;
	    background-position: 3px 1px;
	}
	a.highslide-credits,
	a.highslide-credits i {
	    padding: 2px;
	    color: silver;
	    text-decoration: none;
		font-size: 10px;
	}
	a.highslide-credits:hover,
	a.highslide-credits:hover i {
	    color: white;
	    background-color: gray;
	}

	a.highslide-full-expand {
		background: url(highslide/graphics/fullexpand.gif) no-repeat;
		display: block;
		margin: 0 10px 10px 0;
		width: 34px;
		height: 34px;
	}

	/* These must always be last */
	.highslide-display-block {
	    display: block;
	}
	.highslide-display-none {
	    display: none;
	}
</style>
</head>
<body>

<?php


// store the record of the "gold" table into $row

$current = '';


// keeps getting the next row until there are no more to get

while($row = mysql_fetch_array( $result ))
	 {
$id = $row['id'];
if (!$current) {
echo "<center><table>";
$current = $id;
} elseif ($current != $id){
echo "</table><br><br><table>";
$current = $id;
}
// Print out the contents of each row into a table
echo '<tr>
                           <td><div><a id="thumb1" href="'.$row['image'].'" class="highslide" onclick="return hs.expand(this)">
	<img src="'.$row['image_th'].'" title="Click to enlarge" /></a>

<div class="highslide-caption">'.$row['caption'].'
</div></td>';

}
        echo "</table>";
        echo "<br>";

?>
</body>
</html>
<?=$pagination?>

Link to comment
https://forums.phpfreaks.com/topic/113894-solved-i-need-some-help-with-my-code/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.