#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Canada
    Posts
    35
    Rep Power
    15
    I am having problems passing an array from one page to another using the following script:
    ($position is an array from multiple checkboxes in html):

    <?php

    $count=count($position);
    //get the check box selection count.

    $nb=$count-1;

    $query="select * from $usertable_jobs where (";
    //your query

    for($a=0;$a<$nb;$a++){
    //use a loop for creating like statement
    $query.="location LIKE '$location' AND field LIKE '$field' AND position LIKE '$position[$a]'";

    if($a!=$nb-1){
    //skip OR if it is last item.
    $query.= " OR ";
    }
    else{
    //
    $query.= ") ORDER BY date_posting DESC";
    }
    }
    $result=MYSQL_QUERY($query);

    /* How many jobs are available?*/
    $number=MYSQL_NUM_ROWS($result);

    IF ($number==0)
    {PRINT "No results.";}

    ELSE
    {
    .
    .
    //then I have a limit statement to display only 15 results per page//
    .
    .
    .
    $limit=15;

    IF(empty($page)) /* first query*/
    {$page=1;}

    $start=($page-1)*$limit;
    $first=$start+1;
    $last=$start + $limit;
    IF ($last>$number)
    {$last=$number;}
    .
    .
    .
    //and at the end of the page I have links to the different pages


    for($b = 1;$b <= $nbpages;$b ++)
    {
    if ($page==$b){ //current page

    echo "Page ".$b;

    }else{
    PRINT " <a href='$PHP_SELF?location=$location&position=$position&field=$field&page=$b&number=$number'>Page $b</a> n n"; }

    }

    ?>
    My problem is:
    it works fine for the first 15 results, but when I try to go to page 2 I get the message 'No results' because the variable $position, passed by the 'a href' line, is 'array' and I don't go through the 1st loop...so the query in SQL returns no results.
    I tried with implode/explode, but same problem...
    Is there a way to fix this???
    Thanks
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Bucharest, Romania
    Posts
    18
    Rep Power
    0
    Of course it doesn't work, you can't transmit an array through get method because an array doesn't have value, only his components do.
    Here is my advice: put the parameters of the query ($position, $field etc) in a cookie, or use php sessions; so you will not have to worry about them any more. Besides, I think it is not very effective to make the same query every time you enter one of the pages with results. Maybe you should make different queries according to the variabile $page, using something like "select... limit 15($page-1),15*$page".
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Washington, USA
    Posts
    52
    Rep Power
    14
    You can also use the POST method to move arrays from one page to the next.

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <form method=POST action="nextpage.php">
    <input type=HIDDEN name="position[]" value="<? echo($position); ?>">
    <input type=SUBMIT value="Next Page">
    </form>
    [/code]

    Hope this helps

    ------------------
    <UL TYPE=SQUARE>
    <LI> TD Scripts
    <LI> Script School
    <LI>php-scripts
    </UL>

Similar Threads

  1. Passing an array into a Oracle PreparedStatement
    By hurricane850 in forum Oracle Development
    Replies: 1
    Last Post: February 13th, 2004, 09:17 AM
  2. Web service array problem
    By dreamstring in forum PHP Development
    Replies: 4
    Last Post: February 4th, 2004, 11:25 AM
  3. passing array from page to page...
    By apek in forum PHP Development
    Replies: 3
    Last Post: January 30th, 2004, 02:47 PM
  4. Replies: 0
    Last Post: January 27th, 2004, 12:42 PM
  5. an intricate little array problem
    By glennn1137 in forum PHP Development
    Replies: 3
    Last Post: January 22nd, 2004, 08:08 AM

IMN logo majestic logo threadwatch logo seochat tools logo