Results 1 to 6 of 6

Thread: pass the (&) character

  1. #1
    the_sandking's Avatar
    the_sandking is offline hadron remnant - Moderation Fachmann
    Join Date
    Apr 2003
    Location
    Nullspace
    Posts
    5,289

    Default

    All this talk about (&amp had me thinking..Which is dangerous at best because it always creates more work.

    Whenever I do a search with listingsearch.php the listings that are displayed are always arranged by OR's ID number for the listing. I want them to be arranged by price..

    Easy right? Just create a hidden value on the form, something like:

    Code:
    <input type="hidden" name="sortby" value="price" >
    And this will work great for the first page of listings you get back from listing_browse, but if you have more than 1 page of listings, and then try to view the other pages by clicking on "Next Page" or one of the page numbers, you will receive the error "Your search returned no results"

    Why? Well, because "sortby=price" is now buried inside the url of the request string...

    Code:
    http&#58;//yourdomain.com/listing_browse.php?cur_page=1&amp;sortby=priceimagesOnly=yes&amp;
    Notice how there is no "&amp;" character between "sortby=price" and "imagesOnly=yes"

    So, we need to pass it a "&amp;" character, by just adding it to the hidden field right?

    Code:
    <input type="hidden" name="sortby" value="price&amp;" >
    Nope, because the browser will turn the "&amp;" into "%26"

    So, I've used "&amp;amp;", I've created a string "$price_str" and <urlencoded> it, <rawurlencoded> it, before sending it, all with no luck.. This is about as bad as creating regular expressions..

    Sure, I can hack listing_browse to always sort by price, but that will likely interfere with other things the user might want to override later..


    Any ideas folks?
    "Much of what looks like rudeness in hacker circles is not intended to give offense. Rather, it's the product of the direct, cut-through-the-BS communications style that is natural to people who are more concerned about solving problems than making others feel warm and fuzzy."

    "We gotta' go to the crappy town where I'm a hero!"
    -Hoban 'Wash' Washburne 2485-2519


    "When you’re born you get a ticket to the freak show. When you’re born in America, you get a front-row seat.."
    -George Carlin 1937-2008

    New to Open-Realty® and need help? Check the:
    -OR DOCUMENTATION -

    Important: Read this at least once in your lifetime
    How To Ask Questions The Smart Way

  2. #2
    Join Date
    Jun 2004
    Posts
    1,067

    Default

    Didn't this fix from your other thread take care of that?

    Code:
    // Save GET
       foreach &#40;$_GET as $k => $v&#41;
       &#123;
          if &#40;$v &amp;&amp; $k != 'cur_page' &amp;&amp; $k != 'PHPSESSID' &amp;&amp; $k != 'sortby' &amp;&amp; $k != 'sorttype' &amp;&amp; $k != 'imagesOnly'&#41;
          &#123;
             if &#40;is_array&#40;$v&#41;&#41;
             &#123;
                foreach &#40;$v as $vitem&#41;
                &#123;
                $guidestring .= '&amp;amp;' . urlencode&#40;"$k"&#41; . '&#91;&#93;=' . urlencode&#40;"$vitem"&#41;.'&amp;amp;';
                &#125;
             &#125;
             else
             &#123;
                $guidestring .= '&amp;amp;' . urlencode&#40;"$k"&#41; . '=' . urlencode&#40;"$v"&#41;.'&amp;amp;';
             &#125;
          &#125;
       &#125;

  3. #3
    the_sandking's Avatar
    the_sandking is offline hadron remnant - Moderation Fachmann
    Join Date
    Apr 2003
    Location
    Nullspace
    Posts
    5,289

    Default

    O.K. I found a way to do this, sort of....


    Instead of using the hidden form field (which I could never get to pass a "&amp;" character) I went after the <form> itself.

    I changed the <form> and added "?sortby=price%26" to the action=

    Code:
    <form name="listingsearch" action="./listing_browse.php?sortby=price%26" method="get">
    This successfully passes, and gives me the desired result, the first page of the listings sorted by price. But... the Page 1 of X links break as well as the "Next Page" link, and we're back to not having a "&amp;" where it needs to be..

    Code:
    http&#58;//yourdomain.com/listing_browse.php?cur_page=1&amp;sortby=priceimagesOnly=yes&amp;
    Note to Ryan: NONE of the other sort links contain "&amp;&amp;" anymore with just this one change.
    "Much of what looks like rudeness in hacker circles is not intended to give offense. Rather, it's the product of the direct, cut-through-the-BS communications style that is natural to people who are more concerned about solving problems than making others feel warm and fuzzy."

    "We gotta' go to the crappy town where I'm a hero!"
    -Hoban 'Wash' Washburne 2485-2519


    "When you’re born you get a ticket to the freak show. When you’re born in America, you get a front-row seat.."
    -George Carlin 1937-2008

    New to Open-Realty® and need help? Check the:
    -OR DOCUMENTATION -

    Important: Read this at least once in your lifetime
    How To Ask Questions The Smart Way

  4. #4
    the_sandking's Avatar
    the_sandking is offline hadron remnant - Moderation Fachmann
    Join Date
    Apr 2003
    Location
    Nullspace
    Posts
    5,289

    Default

    Quote Originally Posted by greengiant
    Didn't this fix from your other thread take care of that?

    Code:
    // Save GET
       foreach &#40;$_GET as $k => $v&#41;
       &#123;
          if &#40;$v &amp;&amp; $k != 'cur_page' &amp;&amp; $k != 'PHPSESSID' &amp;&amp; $k != 'sortby' &amp;&amp; $k != 'sorttype' &amp;&amp; $k != 'imagesOnly'&#41;
          &#123;
             if &#40;is_array&#40;$v&#41;&#41;
             &#123;
                foreach &#40;$v as $vitem&#41;
                &#123;
                $guidestring .= '&amp;amp;' . urlencode&#40;"$k"&#41; . '&#91;&#93;=' . urlencode&#40;"$vitem"&#41;.'&amp;amp;';
                &#125;
             &#125;
             else
             &#123;
                $guidestring .= '&amp;amp;' . urlencode&#40;"$k"&#41; . '=' . urlencode&#40;"$v"&#41;.'&amp;amp;';
             &#125;
          &#125;
       &#125;
    Yes!

    But this is a different problem. Check my last post.. I am loading the listingsearch page with a variable "sortby=price&amp;" that gets tacked-on to whatever the user selects from the search page. I don't want to give the user a choice here.
    "Much of what looks like rudeness in hacker circles is not intended to give offense. Rather, it's the product of the direct, cut-through-the-BS communications style that is natural to people who are more concerned about solving problems than making others feel warm and fuzzy."

    "We gotta' go to the crappy town where I'm a hero!"
    -Hoban 'Wash' Washburne 2485-2519


    "When you’re born you get a ticket to the freak show. When you’re born in America, you get a front-row seat.."
    -George Carlin 1937-2008

    New to Open-Realty® and need help? Check the:
    -OR DOCUMENTATION -

    Important: Read this at least once in your lifetime
    How To Ask Questions The Smart Way

  5. #5
    Join Date
    Jun 2004
    Posts
    1,067

    Default

    you could just change teh default sortby in the listing browse code.... line 379 or so in teh listing_browse.php file
    Code:
    	if &#40;$sortby == ""&#41;
    		&#123;
    			$sort_text = "";
    			$order_text = "ORDER BY ID DESC";
    		&#125;

  6. #6
    the_sandking's Avatar
    the_sandking is offline hadron remnant - Moderation Fachmann
    Join Date
    Apr 2003
    Location
    Nullspace
    Posts
    5,289

    Default

    Quote Originally Posted by greengiant
    you could just change teh default sortby in the listing browse code.... line 379 or so in teh listing_browse.php file
    Code:
    	if &#40;$sortby == ""&#41;
    		&#123;
    			$sort_text = "";
    			$order_text = "ORDER BY ID DESC";
    		&#125;

    That's exactly what I did...

    if ($sortby == "")
    {
    $sort_text = "WHERE (field_name = 'price')";
    $order_text = "ORDER BY field_value +0 $sorttype";
    }

    I didn't want to do it that way, but.. It does what I want now... as a positive side-effect none of the other links have "&amp;&amp;" anywhere in them

    The other way I wanted to do it is still a good puzzle, my head is hurting just like the time I learned to pass variables from HTML <--> Javascript <--> PHP

    Looks like my performance issues with listing_browse are also related to the load on the server. Since about 2:00AM and all day today, searches take less than 8 seconds, some have happened in 3 or less. I suppose that's the breaks when you're on a shared server..

    Thanks!
    "Much of what looks like rudeness in hacker circles is not intended to give offense. Rather, it's the product of the direct, cut-through-the-BS communications style that is natural to people who are more concerned about solving problems than making others feel warm and fuzzy."

    "We gotta' go to the crappy town where I'm a hero!"
    -Hoban 'Wash' Washburne 2485-2519


    "When you’re born you get a ticket to the freak show. When you’re born in America, you get a front-row seat.."
    -George Carlin 1937-2008

    New to Open-Realty® and need help? Check the:
    -OR DOCUMENTATION -

    Important: Read this at least once in your lifetime
    How To Ask Questions The Smart Way

Similar Threads

  1. how to pass the date field to dd/mm/yyyy ??
    By franklaval in forum HELP (CLOSED)
    Replies: 7
    Last Post: 04-29-2005, 11:54 AM
  2. Edit Listings Template in the admin "user name and pass
    By CaseyJay in forum HELP (CLOSED)
    Replies: 0
    Last Post: 04-28-2004, 04:00 PM
  3. Full Description Field character limitations
    By dbprgrmr in forum HELP (CLOSED)
    Replies: 1
    Last Post: 02-28-2004, 05:12 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •