SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Stuck in PHP

  1. #1
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Stuck in PHP

    Hi
    I have a situation i which I have a form say x.html
    that form has a text box for searching users with a keyword like software engineers

    when submit is pressed it will give the list of software engineers in USA

    now when the location tab in the result table is clicked I need to sort the results by location and the search keyword

    the problem

    when I click on the location i send the control to another php script that takes care of the location sorting but There is no way I can transfer the keyword as I cannot get a value from the first form ....
    any suggestions


    form (with keyword ) ->php script with keyword search -> select location > new script so sort results by location


    I need the form keyword from the 1 script to use in the selection location script


    kinda like monster search results when you get results of candidates you can select from the top bar by which one you want to sort by location ,city ,country ....etc

  2. #2
    SitePoint Addict ruby-lang's Avatar
    Join Date
    Aug 2007
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Add a parameter to your sorting links. Let's say you have a table header that you click to order the results. It will look like this:
    PHP Code:
    <TH><?php
    echo("<a href='sort_list.php?sort_by=location&keyword=");
    echo(
    urlencode($_POST["keyword"]));
    echo(
    "'>")
    ?>Location</a></TH>

  3. #3
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ruby-lang View Post
    Add a parameter to your sorting links. Let's say you have a table header that you click to order the results. It will look like this:
    PHP Code:
    <TH><?php
    echo("<a href='sort_list.php?sort_by=location&keyword=");
    echo(
    urlencode($_POST["keyword"]));
    echo(
    "'>")
    ?>Location</a></TH>
    Apologize I am a newbie to this stuff...my value for keyword is got from the form which calls this php file which displays the table .

    When I click the location heading on table it will call the sort_list.php according to above

    so in the url <a sort_list.php?sort_by=location&keyword="...> what is the value of 'location'.....and what should i mention in the sort.php file

    Also what does this mean echo(urlencode($_POST["keyword"])); ?

    How do i extract the keyword value in the sort_list.php file ....as this file does not care abt the location value

    Please explain in detail

  4. #4
    SitePoint Addict ruby-lang's Avatar
    Join Date
    Aug 2007
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, let's start by cutting this like an onion:
    echo(urlencode($_POST["keyword"]));

    I guess echo() is obvious to you, so let's move on to urlencode(). It makes strings suitable to be part of URLs, encoding invalid characters into entities that look like %3E.

    After you posted a form to this PHP page, %_POST will contain all the information in that form. $_POST["keyword"] will return the value of a field named "keyword," if it is available.

    There's much, much more you will have to learn, so check out php.net and W3C. Good luck!

  5. #5
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ruby-lang View Post
    Ok, let's start by cutting this like an onion:
    echo(urlencode($_POST["keyword"]));

    I guess echo() is obvious to you, so let's move on to urlencode(). It makes strings suitable to be part of URLs, encoding invalid characters into entities that look like %3E.

    After you posted a form to this PHP page, %_POST will contain all the information in that form. $_POST["keyword"] will return the value of a field named "keyword," if it is available.

    There's much, much more you will have to learn, so check out php.net and W3C. Good luck!



    Wait a min
    so when i do

    <TH><?php

    echo("<a href='sort_list.php?sort_by=location&keyword=");

    echo(urlencode($_POST["keyword"]));

    echo("'>")

    ?>Location</a></TH>


    and it goes to the sort_list.php file how do i decode the url .....?

    in the sort_list.php file I have

    $result = mysql_query("SELECT *
    FROM `jobseeker`
    ORDER BY `location` ASC
    LIMIT 0 , 30");


    I would also like to add the keyword=engineer in result above


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
  •