Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

nextprevious timeout

Codes here !

Moderators: macek, egami, gesf

nextprevious timeout

Postby da9nlc » Mon Mar 10, 2003 1:36 pm

I have a query script setup which seems to giving a timeout problem causing a fatal error. The problem seems to be when it runs the second query part of the script which returns required data that I want limited results per page.


$strSQL = mysql_query("SELECT * FROM tablename WHERE column_name LIKE '%".$var."%' LIMIT $start,$pagelimit");


I am a little confused should the second query be written exactly like the first I think that is logical.

I have increased the time limit from 30 seconds to 60 and still get the same fatal error. I also noticed in php.ini that memory use is set to 8megs would this make a difference (though I am only running 32megs system). Im not sure if this also is a problem. I do have images to be produced but I know that this is no problem Im storing the images in a file and the route stored in the database and I have run the script beforehand with no problems all images were ok in my results page. Only since adding page limit and next & previous functions has the timeout error appeared and no other in my error log.

I hope this make sense and would appreciate anyone making a suggestion PHP ONLY.

Thanks
da9nlc
New php-forum User
New php-forum User
 
Posts: 21
Joined: Sun Feb 23, 2003 11:58 pm

Postby Redcircle » Mon Mar 10, 2003 9:40 pm

try puttin set_time_limit(300); at the top of the script.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby pootergeist » Tue Mar 11, 2003 2:13 am

cut down the results until something works, then work backwards from that
also check that your field types are best suited for wildcard scans - pretty much anything other than 'text' is ok.

so - same query LIMIT 1"); echo mysql_error();

if on a LIMIT 1 you still get a timeout then the glitch must be elsewhere - just tinker with different code approaches until something starts pointing you in the right direction.
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK

Getting result but...

Postby da9nlc » Tue Mar 11, 2003 4:05 am

Im getting a result now the problem being it appears I used a WHILE statement. I changed it to

$row = @mysql_fetch_array($strSQL);// This seem to work.

As I stated in earlier post the database includes image file this is all working fine getting number of records held in database which I have set to 3 per page.

The problem being that I am only getting one record and the next and previous links dont appear. I have set up the result.php to include("databasequery.php"); All was fine before I included the page LIMIT function. Do you have any idea as to what the problem may be.

Thanx
da9nlc
New php-forum User
New php-forum User
 
Posts: 21
Joined: Sun Feb 23, 2003 11:58 pm

Postby pootergeist » Tue Mar 11, 2003 5:22 am

I assume you've echoed out all the variables to test they are set?
echo $var.' -- '.$start.' -- '.$pagelimit;
?
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK

All variables echoing

Postby da9nlc » Tue Mar 11, 2003 1:45 pm

All variables are echoing and seem to be set ok. My only grievance at the moment is the fact that when I set the $pagelimit = 5 all the records I have in the database (4 at the moment) including images show fine on one page.

The problem occurs again when I drop the $pagelimit back down to 3 I get one record showing and the next= & previous links including page numbers showing. When I click on these any of these I get an error page come up with the Previous link and it seem to restart the query as I get "You have not filled in details" warning.

Could some cast an eye over the script below Im a bit lost as Im getting no errors recorded to give me a hint as to the problem. It says to designate the next and previous page links to my page I take that means my databasequery.php and not result.php?

// set number of results to display per page
$pagelimit = "3";

// run query (change yourtable to the name of your table)
$strSQL = mysql_query("SELECT id FROM $table WHERE LIKE $var");

// 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
$page = ($pagenums);
if ($page==''){
$page='1';
}
// create a start value
$start = ($page-1) * $pagelimit;

// blank matches found
echo "<br><b>" . $totalrows . " matches found</b><br>\n";

// Showing Results 1 to 3 (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='databasequery.php.php?page=".($page-1)."' class=main>Previous" . $space . $pagelimit . "</a>" . $space . $space . "";
}

// dynamic page number links (make sure to change yourpage.php to the name of your page)

for ($i=1; $i<=$pagenums; $i++) {
if ($i!=$page) {
echo " <a href='databasequery.php?page=$i' class=main>$i</a>";
}
else {
echo " <b class='red'>$i</b>";
}
}


// next link (make sure to change yourpage.php to the name of your page)

if ($page<=$pagenums) {
echo "" . $space . $space . $space . $space . " <a href='databasequery.php.php?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 * FROM $table 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
da9nlc
New php-forum User
New php-forum User
 
Posts: 21
Joined: Sun Feb 23, 2003 11:58 pm

Re: All variables echoing

Postby da9nlc » Wed Mar 12, 2003 2:42 am

[quote="da9nlc"]All variables are echoing and seem to be set ok. My only grievance at the moment is the fact that when I set the $pagelimit = 5 all the records I have in the database (4 at the moment) including images show fine on one page.

The problem occurs again when I drop the $pagelimit back down to 3 I get one record showing and the next= & previous links including page numbers showing. When I click on these any of these I get an error page come up with the Previous link and it seem to restart the query as I get "You have not filled in details" warning.
da9nlc
New php-forum User
New php-forum User
 
Posts: 21
Joined: Sun Feb 23, 2003 11:58 pm

Help Confussed

Postby da9nlc » Sat Mar 15, 2003 6:16 am

I have managed to find a number of page limit scripts in tutorals, but the one in next & previous timeout is the closest I have got to actually returning the results as I require.

When queries I sent to the database that I know only require the single page all is fine. The problem is when queries are sent to the database which I know there are more than $pagelimit hence requiring a second page the problems start. The result seems to go straight to the second page and the PREVIOUS link appears.

I have pulled the arguements apart countless times tried rearranging them all to no avail.

Could someone please tell me why the script wont return the two pages as expected please and if they could hi-light the area they believe the problem is.

Thanks
da9nlc
New php-forum User
New php-forum User
 
Posts: 21
Joined: Sun Feb 23, 2003 11:58 pm

Re: All variables echoing

Postby da9nlc » Sun Mar 16, 2003 9:14 am

[quote="da9nlc"]Its ok I sorted it
da9nlc
New php-forum User
New php-forum User
 
Posts: 21
Joined: Sun Feb 23, 2003 11:58 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.