I tried to make next and previous pics links
1st i wated to do it above all the html code
and when it starts to work put it inside the table
now it says when i press "Next" button hoping to get a new
photo
"You have an error in your SQL syntax near '' at line 1"
file is a personal profile of a member
here it is:
<?
require("page.inc");
$content= '';
$con = mysql_connect("localhost","user","password")or
die(mysql_error());
mysql_select_db("db",$con)or
die(mysql_error());
$query="SELECT * FROM members, photos WHERE
member.id= photos.memberid and memberID=$personalID" ;
$result= mysql_query($query)
or die(mysql_error());
$row= mysql_fetch_array($result) ;
// set number of results to display per page
$pagelimit = "1";
// run query
$query2="SELECT photo FROM photos, members
WHERE photos.memberid=members.id and
id=$personalID" ;
$strSQL = mysql_query($query2)
or die(mysql_error());
$picrow= mysql_fetch_array($strSQL) ;
// count number of matches
$totalrows = mysql_num_rows($strSQL);
// determine how many pages there will be by using ceil()
and dividing total rows by pagelimit
$pagenums = ceil ($totalrows/$pagelimit);
// if no value for page, page = 1
if ($page==''){
$page='1';
}
// create a start value
$start = ($page-1) * $pagelimit;
// blank matches found
echo "<b>" . $totalrows . " photos </b><br>\n";
// Showing Results 1 to 1 (or if you're page limit were 5)
1 to 5,
etc.
$starting_no = $start + 1;
if ($totalrows - $start < $pagelimit) {
$end_count = $totalrows;
} elseif ($totalrows - $start >= $pagelimit) {
$end_count = $start + $pagelimit;
}
echo "Results $starting_no to $end_count shown.<br>\n";
// create dynamic next, previous, and page links
/* lets say you're set to show 5 results per page and
your script comes out with 7 results.
this will allow your script to say next2 if you're on
the first page and previous5 if you're on the second page. */
if ($totalrows - $end_count > $pagelimit) {
$var2 = $pagelimit;
} elseif ($totalrows - $end_count <= $pagelimit) {
$var2 = $totalrows - $end_count;
}
$space = " ";
// previous link (make sure to change yourpage.php
to the name of your page)
if ($page>1) {
echo "? <a href='" . $PHP_SELF . "? page=".($page-1)."'
class=main>Previous" . $space . $pagelimit . "</a>"
. $space . $space . "";
}
// next link (make sure to change yourpage.php
to the
name of your page)
if ($page<$pagenums) {
echo "" . $space . $space . $space . $space .
" ?<a href='" . $PHP_SELF . "?page=".
($page+1)."' class=main>Next " . $var2 . "</a> ?";
}
/* output your data wherever you'd like.
BUT
in order for this all to work, before outputting your data,
you have to run the query over using MySQL's LIMIT.
This will limit how many results are actually displayed
on the page. */
$strSQL = mysql_query("SELECT photo FROM photos
LIMIT $start,$pagelimit");
// LIMIT 0,10 will start at 0 and display 10 results
// LIMIT 10,5 will start at 10 and display 5 results
/* now you can do whatever you'd like with this query.
it will only output one page at a time.
change the $pagelimit variable to whatever to output
more than 1 result per page. */
$content = '
<table width="100%" align="center"
bgcolor="white" border="0" cellspacing="10"
cellpadding="5">
<tr>
<td>
<table width="100%" border="0"
cellspacing="10" cellpadding="10">
<tr>
<td><img
src="' . $picrow['photo'] . '" border="0" alt="' . $row
['FirstName'] . '">
Next Photo<br />
<b><h3> '.$row['FirstName'].'
</h3></b><br></td>
<td>
<br />
<b>Hobbies:</b> '.$row['Hobbies'].' <br/>
<br />
<b>About me: </b>'.stripslashes($row['AboutMe']).' <br/>
</td>
</tr>
</table>
</td></tr>
</table>';
$homepage = new Page();
$homepage -> SetContent($content);
$homepage->Display();
?>