2 Replies - 130 Views - Last Post: 10 November 2013 - 02:45 PM Rate Topic: -----

#1 Hulu  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 51
  • Joined: 17-July 13

PHP Search Function using selece elements

Posted 10 November 2013 - 01:59 PM

I am trying to get the information from the database if someone selects the option "Attack Speed" it will give them all the rows that ANY column equals "Attack Speed". There are 8 select options that use the same options.

Here is the SQL Select statement I have so far:

$sql = "SELECT * FROM items_us_sc WHERE item_name = :item_name OR quality = :quality
            OR (attrib_1 = :prop1 OR attrib_2 = :prop1 OR attrib_3 = :prop1 OR attrib_4 = :prop1 OR attrib_5 = :prop1 OR attrib_6 = :prop1 OR attrib_7 = :prop1 OR attrib_8 = :prop1)
            OR (attrib_1 = :prop2 OR attrib_2 = :prop2 OR attrib_3 = :prop2 OR attrib_4 = :prop2 OR attrib_5 = :prop2 OR attrib_6 = :prop2 OR attrib_7 = :prop2 OR attrib_8 = :prop2)
            OR (attrib_1 = :prop3 OR attrib_2 = :prop3 OR attrib_3 = :prop3 OR attrib_4 = :prop3 OR attrib_5 = :prop3 OR attrib_6 = :prop3 OR attrib_7 = :prop3 OR attrib_8 = :prop3)
            OR (attrib_1 = :prop4 OR attrib_2 = :prop4 OR attrib_3 = :prop4 OR attrib_4 = :prop4 OR attrib_5 = :prop4 OR attrib_6 = :prop4 OR attrib_7 = :prop4 OR attrib_8 = :prop4)
            OR (attrib_1 = :prop5 OR attrib_2 = :prop5 OR attrib_3 = :prop5 OR attrib_4 = :prop5 OR attrib_5 = :prop5 OR attrib_6 = :prop5 OR attrib_7 = :prop5 OR attrib_8 = :prop5)
            OR (attrib_1 = :prop6 OR attrib_2 = :prop6 OR attrib_3 = :prop6 OR attrib_4 = :prop6 OR attrib_5 = :prop6 OR attrib_6 = :prop6 OR attrib_7 = :prop6 OR attrib_8 = :prop6)
            OR (attrib_1 = :prop7 OR attrib_2 = :prop7 OR attrib_3 = :prop7 OR attrib_4 = :prop7 OR attrib_5 = :prop7 OR attrib_6 = :prop7 OR attrib_7 = :prop7 OR attrib_8 = :prop7)
            OR (attrib_1 = :prop8 OR attrib_2 = :prop8 OR attrib_3 = :prop8 OR attrib_4 = :prop8 OR attrib_5 = :prop8 OR attrib_6 = :prop8 OR attrib_7 = :prop8 OR attrib_8 = :prop8)";
            $arr = array(":item_name" => $itemName, ":prop1" => $itemAttrib1, ":quality" => $Quality, ":prop2" => $itemAttrib2, ":prop3" => $itemAttrib3, ":prop4" => $itemAttrib4, ":prop5" => $itemAttrib5, ":prop6" => $itemAttrib6, ":prop7" => $itemAttrib7, ":prop8" => $itemAttrib8);
            $this->view->items = $this->database->DBQry($sql,$arr);


Am I on the right track or is there another way I should try?

Is This A Good Question/Topic? 0
  • +

Replies To: PHP Search Function using selece elements

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2890
  • View blog
  • Posts: 9,597
  • Joined: 12-December 12

Re: PHP Search Function using selece elements

Posted 10 November 2013 - 02:26 PM

I am more concerned about your database structure than the sql-statement. Repeated fields attrib_1, attrib_2, etc., breaks any attempt at data-normalization. These attributes should be in a separate, related, table.

This field in the new table could be named attrib. If, however, the attributes are distinct then this should be made clear by at least giving them distinct names - but I doubt that this is the case.

If you don't reconsider your database structure then your sql-statements will get bigger, more cumbersome, and more error-prone.

This post has been edited by andrewsw: 10 November 2013 - 02:29 PM

Was This Post Helpful? 1
  • +
  • -

#3 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2890
  • View blog
  • Posts: 9,597
  • Joined: 12-December 12

Re: PHP Search Function using selece elements

Posted 10 November 2013 - 02:45 PM

Here is a very good database tutorial.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1