Reply to Re: NEXT - PREVIOUS

Your name:

Reply:


Posted by Jerry Stuckle on 06/05/05 23:15

Marcel wrote:
> Hello,
> I'm working on a search application for my website. The website contains a
> lot of pictures, and a search should return clickable thumbnails. No
> problems there. My problem started when I wanted to build in NEXT and
> PREVIOUS buttons, so that you only get 5 or 10 or 20 (I haven't made up my
> mind yet) thumbnails at a time. I use a SQL LIMIT statement to achieve that.
> After displaying the first 5 pictures I would like to see the next 5, etc.,
> which is not happening with what I've written so far.
> A test version can be found at
> http://bluegumdata.com.au/pictures/search/search.php.
> Suggestions please. Thanks, Marcel
>
> The code :
>
> <?php
>
> //make a database connection
> require('db.php');
>
> if (isset ($_POST['submit']))
> {
>
> if (isset($_GET['pageno']))
> {
> $pageno = $_GET['pageno'];
> echo "Pageno : " . $pageno;
> }
> else
> {
> $pageno = 1;
> echo "Pageno : " . $pageno;
> }
>
> //convert search string to lowcase
> //strip search string of unwanted words and characters
> //put stripped search string in $search
> //keep the original term in $newterm
> $newterm = $_POST['_searchterm'];
>
> $_POST['_searchterm'] = strtolower($_POST['_searchterm']);
> $_POST['_searchterm'] = " ".$_POST['_searchterm']." ";
> $_POST['_searchterm'] = str_replace(' and ', ' ', $_POST['_searchterm']);
> $_POST['_searchterm'] = str_replace(' - ', ' ', $_POST['_searchterm']);
> $_POST['_searchterm'] = str_replace(' the ', ' ', $_POST['_searchterm']);
> $_POST['_searchterm'] = str_replace(' a ', ' ', $_POST['_searchterm']);
> $_POST['_searchterm'] = str_replace(' or ', ' ', $_POST['_searchterm']);
> $_POST['_searchterm'] = str_replace(' ', ' ', $_POST['_searchterm']);
> $_POST['_searchterm'] = trim($_POST['_searchterm']);
>
> $search = $_POST['_searchterm'];
>
> //split search string in separate words
> //count the number of qwords
> $words = explode(' ',$search);
> $numterms = count($words);
>
> //build up search string for database
> $match = "keywords LIKE '%" . $words[0] . "%'";
> for ($i = 1;
> $i < $numterms;
> $i++)
> {
> $match .= " AND keywords LIKE '%" . $words[$i] . "%'";
> }
>
> //count the number of matching records
> $query = "SELECT COUNT(*) FROM pictures "
> . "WHERE $match ";
>
> $result = mysql_query($query);
> $query_data = mysql_fetch_row($result);
> $numrows = $query_data[0];
>
> //set the numbers per page and the number of pages needed
> $rows_per_page = 5;
> $lastpage = ceil($numrows / $rows_per_page);
>
> //create the LIMIT-clause and execute the query
> $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page . ',' . $rows_per_page;
>
> $query = "SELECT DISTINCT url, keyword1, title, thumbfile, country,
> location, yearofpic "
> . "FROM pictures "
> . "WHERE $match "
> . "ORDER BY yearofpic, imageid "
> . "$limit ";
>
> $result = mysql_query($query);
>
> //display results
> //if there aren't any, display a message 'no results'
> if (mysql_num_rows($result))
> {
> echo "<p>You searched our website for: <b>" . $newterm ."</b> and this
> is what we found...</p>\n";
> echo "<p>";
>
> while ($row = mysql_fetch_row($result))
> {
> echo "<div class ='thumbnaildiv'>";
> echo "<a href = '" . $row['0'] . "'><img src = '". $row['3'] ."'
> border = '0'></a><br>";
> echo "<b>What: </b>" . $row['2'] . ", ". $row['1'] . "</br><b>Where:
> </b> ". $row['5'] . " , " . $row['4'] . "<br>";
> echo "<b>When: </b>" . $row['6'];
> echo "</div>";
> }
> echo "</p>\n";
> echo "<br class='clearboth'>";
>
> //create NEXT and PREVIOUS buttons
> //This will be expanded as soon as I get the NEXT button to work...
> if ($pageno==1)
> {
> echo "<div class='navigation'>";
> echo "<ul class='horizontal'>";
> echo "<li> <a
> href='search.php?_searchterm=$newterm?pageno=2'><span>NEXT</span></a> </li>
> ";
> echo "</ul>";
> echo "</div>";
> echo "<br class='clearboth'>";
> }
> }
> else
> {
> echo "<p>You searched our website for: <b>" . $newterm . "</b> but we
> couldn't find anything..</p>\n";
> echo "<p>";
> }
> }
>
> ?>
>
>

Well, for one things, are you POSTing the form or GETting it? If the
former, $_GET['pageno'] will not be defined. If the latter,
$_POST['submit'] won't be defined.

Also, check your braces. If $_POST['submit'] isn't set, you'll skip
everything.

Just a couple of things I saw on at a quick glance. There may be others.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация