SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot Mr Chocolate's Avatar
    Join Date
    May 2002
    Location
    Australia
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation php multiple select stress :(

    Howdy guys,

    I'm really stuck I keep getting and error message because of an array with no value. I'm using a select box that allows multiple selections

    <select name="extra[]" size="6" multiple class="selectbox">

    When i do a search and don't select any values i get a pass error in my Mysql syntax

    Warning: Supplied argument is not a valid MySQL result resource in /home/test/www/result.php on line 71

    but when i select one value from the select box no error occurs which is what i want and i get all the correct results. Do i have to implode the array $extra so i wont get this error? if so how do i do this?

    is it something like this

    PHP Code:
    if ($extra <1) {
    (
    ".implode(',',$extra).");

    I'm using a lookup table for extras if that helps. When i select more than one value i dont get any results even when Properties have more than one extra. this is how i'm sorting through multiple selects.


    PHP Code:
    if ($extra !="") {
    $from  .= ", PropertyExtras"
    foreach (
    $extra as $extraId) {
    echo 
    "$extras";
    $where .= " AND Properties.ID=PID AND EID=$extraId"

    I'm really stuck and i would pull my hair out if i had any.

  2. #2
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just check if the array is empty - i.e. no selections and is so alter your query to suit, guessing that this will be along the right lines ?

    PHP Code:
    <?
    if(count($extra)>=) {
      
    $from  .= ", PropertyExtras"
      
    $where .= " AND Properties.ID=PID";
      foreach (
    $extra as $extraId) {
        
    $where .= " AND EID=$extraId"
      } 
    }
    ?>

  3. #3
    SitePoint Evangelist
    Join Date
    Nov 2001
    Location
    UK
    Posts
    466
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    with multiple $extras you would eventually get a self defeating query

    WHERE EID=arg1 AND EID=arg2 AND EID=arg3

    which would always be false as EID couldn't be arg1, arg2 and arg3 all at once.

    you might have to test $extra as above and then build an array and use mysqls WHERE x IN (arg1, arg2, arg3) method.
    teckis - that's news to me.

  4. #4
    SitePoint Member
    Join Date
    Sep 2002
    Location
    Buenos Aires, Argentina
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, one way to do it:
    PHP Code:
    if(count($extra)>=) {
      
    $from  .= ", PropertyExtras"
      
    $where .= " AND Properties.ID=PID";
      
    $where .= '(' implode(','$extra) . ')';

    Last edited by lovecraft; Mar 22, 2003 at 08:36.

  5. #5
    SitePoint Zealot Mr Chocolate's Avatar
    Join Date
    May 2002
    Location
    Australia
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help guys! I've decided to only allow one select i tried your code but it did'nt work. thanks for responding


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
  •