URL Syntax - I be stumped!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

AaronSmith
Forum Commoner
Posts: 32
Joined: Fri Mar 28, 2003 3:14 pm

Post by AaronSmith »

Look towards the end of my code...

Code: Select all

function class_search($cat,$pagelimit) 
{ 
    global $query_string; 
    
$table = "classifieds"; 
$pagelimit = "2"; 
$strSQL = mysql_query("SELECT * FROM $table"); 
$totalrows = mysql_num_rows($strSQL); 
$pagenums = ceil ($totalrows/$pagelimit); 

if ($page==''){ 
$page='1'; 
} 

$start = ($page-1) * $pagelimit; 

$starting_no = $start + 1; 
$space = " "; 



    return snarf_array('classifieds','ID','ID', 
   " WHERE (Category=$cat OR Category2=$cat OR Category3=$cat) " 
   . " AND Expires>" . time() 
   . " ORDER BY Created DESC LIMIT $start,$pagelimit" ); 
}
In the "function class_search($cat,$pagelimit)" part, shouldn't I have $start in there somehow? If I change LIMIT $start,$pagelimit to LIMIT 3,$pagelimit, the page starts at the third item. Is in just not being passed dynamically?
AaronSmith
Forum Commoner
Posts: 32
Joined: Fri Mar 28, 2003 3:14 pm

Post by AaronSmith »

I took out the start and pagelimit in the function heading completely, both there and where it is called.

The problem is this, it will not show the next items in the database; regardless of what page I am on, it displays the last two items (since I am in DESC order).

I believe the code is correct but perhaps it just isn't in the right place. Your thoughts?

Did this cease to be fun? lol
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Just wondering what wrong with it.
If you right after the function heading makes a 'echo $start;', what will that give you?
Perhaps you need to global $start also (as similiar to the $query_string)
AaronSmith
Forum Commoner
Posts: 32
Joined: Fri Mar 28, 2003 3:14 pm

Post by AaronSmith »

It gives me nothing - not an error nor a response.
AaronSmith
Forum Commoner
Posts: 32
Joined: Fri Mar 28, 2003 3:14 pm

Post by AaronSmith »

As it were, this began as a URL question - could there possibly still be something wrong with the link itself....

browse.php?id=217&page=4

?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

No, it is correct.

Code: Select all

// index.php contains:
<pre>
<a href="index.php?id=217&page=4">Test Link</a>
<?php
show_source(__FILE__);
print_r($_GET);
?>

Array
(
    [id] => 217
    [page] => 4
)
Did you try global $start; ?
AaronSmith
Forum Commoner
Posts: 32
Joined: Fri Mar 28, 2003 3:14 pm

Post by AaronSmith »

Yes, have tried Global Start - same results.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Code: Select all

if ($page==''){ 
$page='1'; 
} 
// and looking at:
if ($page==''){ 
$page=1; 
}
You are using $page = '1';. Would that make $page a string, not an integer? What would a string do in the LIMIT clause?
AaronSmith
Forum Commoner
Posts: 32
Joined: Fri Mar 28, 2003 3:14 pm

Post by AaronSmith »

I fixed the problem!!!!!!!!!!!!!!!!!!!

The start was simply in the wrong place!
Post Reply