Page 1 of 2

URL Syntax - I be stumped!

Posted: Tue Sep 09, 2003 9:20 am
by AaronSmith
I am calling two things in one URL, and have no idea what this sort of thing is termed.

Here is the URL I am using, and it isn't working. My code is fine, but this URL is wrong - I just know it!

browse.php?id=217 page=3

What punctuation do I stick between "?id=217" and "page=3" ?

I appreciate any help with this...

Posted: Tue Sep 09, 2003 9:24 am
by liljester
browse.php?id=217&page=3

Posted: Tue Sep 09, 2003 9:27 am
by AaronSmith
I was just trying that... and getting the same two items over and over regardless of the page. I must have something else wrong too.

I've written pagination before, but this two variable question of category and page is stumping me. Any common mistakes I should look at?

Posted: Tue Sep 09, 2003 9:37 am
by liljester
could you show some of your code?

Posted: Tue Sep 09, 2003 9:50 am
by AaronSmith
This is the page being called...

Code: Select all

<?

class classified
&#123;
    var $ID;
    var $Created;
    var $Expires;
    var $AuthorID;
    var $title;
    var $description;
	var $filename;
    var $pictureID;
    var $iquantity;
    var $asking_price;
    var $duration;
    var $phonenumber;
    var $city;
    var $state;
    var $shipping;
    var $international;
    var $payment;
    var $category;
    var $category2;
    var $category3;
    var $suggested_category;

    function classified()
    &#123;
	$this->AuthorID = $_SESSION&#1111;'PHPAUCTION_LOGGED_IN'];
	$this->iquantity = 1;
	$this->shipping = 'buyer';
	$this->payment = array();
	$this->category = 0;
	$this->category2 = 0;
	$this->category3 = 0;
    &#125;

    function save()
    &#123;
	if ( empty($this->ID) )
	&#123;
	    $query = "INSERT INTO classifieds SET ";
	    $this->Created = time();
	    $this->Expires = $this->Created + $this->duration*24*60*60;
	&#125;
	else 
	    $query = "UPDATE classifieds SET ";

	$query .= safe_pair("AuthorID=",$this->AuthorID);
	$query .= safe_pair(", Category=",$this->category);
	$query .= safe_pair(", Category2=",$this->category2);
	$query .= safe_pair(", Category3=",$this->category3);
	$query .= safe_pair(", Created=",$this->Created);
	$query .= safe_pair(", Expires=",$this->Expires);
	$query .= safe_pair(", object=",serialize($this));

	if ( !empty($this->ID) )
	&#123;
	    $query .= safe_pair(" WHERE ID=",$this->ID);
	&#125;

	$q = mysql_query($query) or class_error(mysql_error());
	$id = mysql_insert_id();
	if ( empty($this->ID) && $id > 0 )
	&#123;
	    $this->ID =  $id;
	&#125;
	return $this->ID;
    &#125;

    function scan_form($a,$payment)
    &#123;
	$errors = array();

	if ( $this->ID != $a&#1111;'ID'] )
	&#123;
	    class_error("Intruder alert!  ID mismatch.");
	&#125;
	unset($a&#1111;'ID']);

	foreach ( $a as $k => $v )
	&#123;
	     $a&#1111;$k] = strtr($a&#1111;$k],array("\''"=>"'","&quote;"=>"""));
	&#125;

	if ( empty($a&#1111;'title']) )
	&#123;
	    $errors&#1111;'title'] = "You must provide an item title.";
	&#125;

	if ( empty($a&#1111;'description']) )
	&#123;
	    $errors&#1111;'description'] = "A description is required!";
	&#125;



	if ( empty($a&#1111;'asking_price']) )
	&#123;
	    $errors&#1111;'asking_price'] = "Did you forget an asking price or comment?";
	&#125;

	global $class_duration_table;
	if ( !isset($class_duration_table&#1111;$a&#1111;'duration']]) )
	&#123;
	    $errors&#1111;'duration'] = "Choose a standard duration.";
	&#125;

	if ( empty($a&#1111;'city']) )
	&#123;
	    $errors&#1111;'city'] = "City where goods are located.";
	&#125;

	if ( empty($a&#1111;'state']) )
	&#123;
	    $errors&#1111;'state'] = "State (or country) where goods are located.";
	&#125;

	global $shipping_table;
	if ( !isset($shipping_table&#1111;$a&#1111;'shipping']]) )
	&#123;
	    $errors&#1111;'shipping'] = "Select a shipping option.";
	&#125;

	global $payment_table;
	$this->payment = array();
	unset($a&#1111;'payment']);
	if ( isset($payment) )
	&#123;
	    foreach ( $payment as $key => $val )
	    &#123;
		if ( isset($payment_table&#1111;$val]) )
		&#123;
		    $this->payment&#1111;$val] = true;
		&#125;
		else
		&#123;
		    $errors&#1111;'payment'] = "Internal error: unknown payment";
		    unset($payment&#1111;$key]);
		&#125;
	    &#125;
	&#125;
	if ( empty($payment) && !isset($errors&#1111;'payment']) )
	&#123;
	    $errors&#1111;'payment'] = "Select at least one payment option.";
	&#125;

	if ( empty($a&#1111;'category']) || $a&#1111;'category'] < 1 )
	&#123;
	    $errors&#1111;'category'] = "You must select a primary category.";
	    $a&#1111;'category'] = 0;
	&#125;

	if ( !empty($a&#1111;'category2']) && $a&#1111;'category2'] > 0 )
	&#123;
	    if ( $a&#1111;'category2'] == $a&#1111;'category'] )
	    &#123;
		$errors&#1111;'category2'] = "Duplicate category";
	    &#125;
	&#125;
	else $a&#1111;'category2'] = 0;

	if ( !empty($a&#1111;'category3']) && $a&#1111;'category3'] > 0 )
	&#123;
	    if ( $a&#1111;'category3'] == $a&#1111;'category']
	      || $a&#1111;'category3'] == $a&#1111;'category2'] )
	    &#123;
		$errors&#1111;'category3'] = "Duplicate category";
	    &#125;
	&#125;
	else $a&#1111;'category3'] = 0;

	foreach ( get_class_vars('classified') as $k => $v )
	&#123;
	    if ( isset($a&#1111;$k]) )
		$this->$k = $a&#1111;$k];
	&#125;

	return $errors;
    &#125;
&#125;


$class_duration_table = array(
	10 => "10 days",
	30 => "1 month",
	365 => "1 year"
);


function get_classified($search_id)
&#123;
	global $query_string;
	$q = safe_query("select * from classifieds"
		. " where ID =", $search_id)
		or class_error(mysql_error() . "<br><pre>" . $query_string . "</pre>");

	if ( mysql_num_rows($q) != 1 )
		class_error("Internal error: row not unique");

	$row = mysql_fetch_assoc($q);
	$obj = unserialize($row&#1111;'object']);
	$obj->ID = $row&#1111;'ID']; // may not be assigned when INSERTed
	return $obj;
&#125;

function class_search($cat,$pagelimit)
&#123;
    global $query_string;
	


$table = "classifieds"; 
$pagelimit = "2"; 
$strSQL = mysql_query("SELECT * FROM $table"); 
$totalrows = mysql_num_rows($strSQL); 
$pagenums = ceil ($totalrows/$pagelimit); 

if ($page=='')&#123; 
$page='1'; 
&#125; 

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

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



    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" );
&#125;

function class_textsearch($key,$limit)
&#123;
    global $query_string;
    return snarf_array('classifieds','ID','ID',
	" WHERE UPPER(object) LIKE UPPER('%". mysql_escape_string($key) . "%')"
	. " AND Expires>" . time()
	. " ORDER BY Created DESC $limit" );
&#125;

Posted: Tue Sep 09, 2003 9:55 am
by AaronSmith
When I change $start to 3 directly in the code, it does indeed start at the third item. Logic tells me that I am not passing the $start variable through to the page.

Posted: Tue Sep 09, 2003 10:02 am
by liljester
AaronSmith wrote:I was just trying that... and getting the same two items over and over regardless of the page. I must have something else wrong too.

I've written pagination before, but this two variable question of category and page is stumping me. Any common mistakes I should look at?
what values are you getting?

Posted: Tue Sep 09, 2003 10:07 am
by JAM

Code: Select all

if ($page==''){ 
$page='1'; 
}
...makes it not working if you have your register_globals = off.
If youre register_globals = ON, ignore this post. ;)

Read the last link in my signature.

Posted: Tue Sep 09, 2003 10:15 am
by m3rajk
JAM wrote:

Code: Select all

if ($page==''){ 
$page='1'; 
}
...makes it not working if you have your register_globals = off.
If youre register_globals = ON, ignore this post. ;)

Read the last link in my signature.
register gobals should be off for security reasons.
assuming 4.1.0 or higher, he shoudl get the get variables like this:

Code: Select all

if(isset($_GET['variable']){ // if it was passed in the GET string
  $variable=$_GET['variable'];
}else{ // it wasn't passed, what's the default?
  $variable='default value';
}

Posted: Tue Sep 09, 2003 10:17 am
by AaronSmith
My globals are [extremely] turned on. :oops: I mean, yes, I have my globals on.

Posted: Tue Sep 09, 2003 10:22 am
by m3rajk
http://www.php.net

go look up register globals. you might decide you want them OFF.


it's a security risk. expect that any place that has 4.1.0 or higher (when it was turned off by default) has it off and most likely wont turn it on.

coding in a dev env is good as long as you know the dev env is more restrictive than a possible deployment environment.

means you know it will work.

Posted: Tue Sep 09, 2003 10:24 am
by AaronSmith
I appreciate the advice. I will look into it per your suggestion.

How do I find what values are being passed? At one time, I had a file I could access that would tell me - but do not know the contents of such a thing. I've only been doing this for a short while.

Posted: Tue Sep 09, 2003 10:27 am
by JAM
You could add this on pages you are testing...

Code: Select all

<?php
 phpinfo();
?>
or perhaps only

Code: Select all

<?php
phpinfo(32);
?>

Posted: Tue Sep 09, 2003 10:28 am
by m3rajk
AaronSmith wrote:I appreciate the advice. I will look into it per your suggestion.

How do I find what values are being passed? At one time, I had a file I could access that would tell me - but do not know the contents of such a thing. I've only been doing this for a short while.
printr($_GET);

(i might have the call a bit off)

Posted: Tue Sep 09, 2003 10:44 am
by AaronSmith
Ok, that I have... I thought you folks were referencing soemthing else.

What value(s) should I post, specifically?