Zikula: A Flexible Open Source Content Management System
home | forum | international support | contact us

Support Forum

Start ::  Developers Corner ::  Module Development ::  Building a search function??

Moderated by: Support Team

Goto page : 1 | 2 Next Page
Bottom
Building a search function??

  • Link to this postingPosted: 11.01.2005, 21:48
    Profile
    sunadmn
    rank:
    Helper Helper
    registered:
     October 2004
    Status:
    offline
    last visit:
    01.03.06
    Posts:
    437
    Hey all I have my module just about done now ( all the standard functions work ) and now I need to add a search function to the pnuser & pnuserapi.php files and I am not quite sure how to do it, so I was wondering if you all could give me some pointers on the matter. Here is what I have built thus far:

    pnuser.php search function:
    Code
    function pnDiagram_user_search()
    {

        if (!pnSecAuthAction(0, 'pnDiagram::', '::', ACCESS_OVERVIEW)) {
            return pnVarPrepHTMLDisplay(_MODULENOAUTH);
        }

        $pnRender =& new pnRender('pnDiagram');

        $pnRender->caching = false;

        return $pnRender->fetch('pnDiagram_user_search.htm');

    }

    The above is called to from a link in the users menu.

    this is what I have in my template file now:
    Code
    <!--[$Id: pnDiagram_admin_modify.htm,v 1.9 2004/04/05 19:47:51 markwest exp $  *]-->
    <!--[include file="pnDiagram_user_menu.htm"]-->
    <br /><br />
    <div class="pn-title"><!--[pnml name="_pnDiagramSEARCH"]--></div>
    <br /><br />
    <form action="<!--[pnmodurl modname="pnDiagram" type="user" func="query"]-->" method="post" enctype="application/x-www-form-urlencoded">
    <div>
      <input type="hidden" name="authid" value="<!--[pnsecgenauthkey module="pnDiagram"]-->" />
      <input type="hidden" name="tid" value="<!--[$tid|pnvarprepfordisplay]-->" />
      <table border="1" cellpadding="5" cellspacing="1"><tbody>
        <tr>
          <td><label for="pnDiagram_name"><!--[pnml name="_pnDiagramNAME"]--></label></td>
          <td><input id="pnDiagram_name" name="itemname" type="text" size="32" maxlength="32" /></td>
        </tr>
        <tr>
          <td><label for="pnDiagram_site_type"><!--[pnml name="_pnDiagramSITETYPE"]--></label></td>
          <td><select name="Tsite" size="1" tabindex="3"><option value=""></option><option value="Master Headend">Master Headend</option><option value="Hub">Hub</option><option value="CoLocation">CoLocation</option><option value="Central Office">Central Office</option><option value="Aggregation Point">Aggregation Point</option></select></td>
        </tr>
        <tr>
          <td><label for="pnDiagram_city"><!--[pnml name="_pnDiagramCITY"]--></label></td>
          <td><input id="pnDiagram_city" name="city" type="text" size="32" maxlength="32" /></td>
        </tr>
        <tr>
          <td><label for="pnDiagram_state"><!--[pnml name="_pnDiagramSTATE"]--></label></td>
          <td><input id="pnDiagram_state" name="state" type="text" size="32" maxlength="32" /></td>
        </tr>
        <tr>
         <td><label for="pnDiagram_technology"><!--[pnml name="_pnDiagramTECHNOLOGY"]--></label></td>
         <td><label><input type="radio" name="tech1" value="PowerLink">PowerLink</label></td>
        </tr>
        <tr>
         <td><label for="pnDiagram_technology"><!--[pnml name="_pnDiagramTECHNOLOGY"]--></label></td>
         <td><label><input type="radio" name="tech2" value="Digital TV">Digital TV</label></td>
        </tr>
        <tr>
         <td><label for="pnDiagram_technology"><!--[pnml name="_pnDiagramTECHNOLOGY"]--></label></td>
         <td><label><input type="radio" name="tech3" value="Video on Demand">Video on Demand</label></td>
        </tr>
        <tr>
          <td><label for="pnDiagram_status"><!--[pnml name="_pnDiagramSTATUS"]--></label></td>
          <td><select name="status" size="1" tabindex="13"><option value=""></option><option value="Verified">Verified</option><option value="Unverified">Unverified</option><option value="Proposed">Proposed</option><option value="Acquisition">Acquisition</option></select></td>
        </tr>
        <tr>
          <td><label for="pnDiagram_diagram"><!--[pnml name="_pnDiagramDIAGRAM"]--></label></td>
          <td><select name="diagram" size="1" tabindex="11"><option value=""></option><option value="Port">Port</option><option value="Rack">Rack</option><option value="Vlan">Vlan</option><option value="Connectivity">Connectivity</option><option value="Overview">Overview</option></select></td>
        </tr>
        <tr>
          <td><label for="pnDiagram_author"><!--[pnml name="_pnDiagramAUTHOR"]--></label></td>
          <td><input id="pnDiagram_author" name="author" type="text" size="32" maxlength="32" /></td>
        </tr>
        <tr>
          <td><label for="pnDiagram_category"><!--[pnml name="_pnDiagramCATEGORY"]--></label></td>
          <td><select name="category" size="1" tabindex="11"><option value=""></option><option value="NorthEast">NorthEast</option><option value="SouthEast">SouthEast</option><option value="SoutherCal">SoutherCal</option><option value="Western">Western</option><option value="Central">Central</option></select></td>
        </tr>
      </table>
      <input name="submit" type="submit" value="<!--[pnml name="_pnDiagramSEARCH"]-->" />
    </div>
    </form>

    Now from this file I will call to a pnuser.php query function to run the API function to do the search, this is where I am having a bit of trouble I am not 100% sure what this function should look like since the Example module doesn't have a search function and every module I have loaded on my system does not make use of the pnrender engine.

    Any pointers anyone could provide would be awesome.


    Thanks
    -SUNADMN
  • Link to this postingPosted: 12.01.2005, 02:25
    Profile
    sunadmn
    rank:
    Helper Helper
    registered:
     October 2004
    Status:
    offline
    last visit:
    01.03.06
    Posts:
    437
    Ok so I have reached the point of trying to call to the API function but for some reason I have an issue with my SQL and am not sure how to adjust it to work correctly can anyone give me some advice please. Below is my API function:

    Code
    function pnDiagram_userapi_query()
    {

        $dbconn =& pnDBGetConn(true);
        $pntable =& pnDBGetTables();

        $pnDiagramtable = &$pntable['pnDiagram_data'];
        $pnDiagramcolumn = &$pntable['pnDiagram_data_column'];

        $sql = "SELECT $pnDiagramcolumn[site_name]       LIKE '".$itemname."'
                       OR $pnDiagramcolumn[site_type]    LIKE '"
    .$Tsite."'
                       OR $pnDiagramcolumn[city]         LIKE '"
    .$city."'
                       OR $pnDiagramcolumn[state]        LIKE '"
    .$state."'
                       OR $pnDiagramcolumn[tech1]        LIKE '"
    .$tech1."'
                       OR $pnDiagramcolumn[tech2]        LIKE '"
    .$tech2."'
                       OR $pnDiagramcolumn[tech3]        LIKE '"
    .$tech3."'
                       OR $pnDiagramcolumn[status]       LIKE '"
    .$status."'
                       OR $pnDiagramcolumn[diagram_type] LIKE '"
    .$diagram."'
                       OR $pnDiagramcolumn[author]       LIKE '"
    .$author."'
                       OR $pnDiagramcolumn[category]     LIKE '"
    .$category."');

        print_r($sql);
        die;

    }



    Thanks
    -SUNADMN
  • Link to this postingPosted: 12.01.2005, 04:09
    Profile
    jediping
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    12.03.07
    Posts:
    387
    I think you need something like SELECT * FROM table WHERE ...
  • Link to this postingPosted: 12.01.2005, 18:25
    Profile Homepage
    cyber_wolf
    rank:
    Helper Helper
    registered:
     June 2002
    Status:
    offline
    last visit:
    05.08.08
    Posts:
    286
    jediping is correct.

    You need to use either SELECT * FROM $pnDiagramtable WHERE ( {your LIKE statements from above} )

    or

    SELECT $pnDiagramcolumn[column1],$pnDiagramcolumn[column2],$pnDiagramcolumn[column3]... FROM $pnDiagramtable WHERE ( {your LIKE statements from above} )

    -----
    cyber_wolf
    http://www.bkbsolutions.com - My Zikula module development site.
  • Link to this postingPosted: 12.01.2005, 19:17
    Profile
    sunadmn
    rank:
    Helper Helper
    registered:
     October 2004
    Status:
    offline
    last visit:
    01.03.06
    Posts:
    437
  • Link to this postingPosted: 12.01.2005, 20:04
    Profile
    jediping
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    12.03.07
    Posts:
    387
    It looks like you're not passing any args to your query, as in function pnDiagram_userapi_query($args). icon_smile

    A question on the design of this search thing, though. Might it not be easier for the user to just enter one term in one box and then have the search function check that one term against all the columns? Or am I thinking too simplistically? Guess it depends on what you anticipating them searching for. The planning stages of programming always intrigue me. :D
  • Link to this postingPosted: 12.01.2005, 20:07
    Profile
    sunadmn
    rank:
    Helper Helper
    registered:
     October 2004
    Status:
    offline
    last visit:
    01.03.06
    Posts:
    437
    Yeah I just caught that myself about a minute ago, so now it's on to testiing.
  • Link to this postingPosted: 12.01.2005, 20:41
    Profile
    sunadmn
    rank:
    Helper Helper
    registered:
     October 2004
    Status:
    offline
    last visit:
    01.03.06
    Posts:
    437
    OK so I get my args passed now but for some stupid reason I am not getting any data in the vars in the SQL statement. Here is what I have now:

    API function:
    Code
    function pnDiagram_userapi_query($args)
    {

    //print_r($args);
    //die;

        $dbconn =& pnDBGetConn(true);
        $pntable =& pnDBGetTables();

        $pnDiagramtable = &$pntable['pnDiagram_data'];
        $pnDiagramcolumn = &$pntable['pnDiagram_data_column'];

        $sql = "SELECT * FROM $pnDiagramtable WHERE(
                       $pnDiagramcolumn[site_name]       LIKE '%$itemname%'
                       OR $pnDiagramcolumn[site_type]    LIKE '%$Tsite%'
                       OR $pnDiagramcolumn[city]         LIKE '%$city%'
                       OR $pnDiagramcolumn[state]        LIKE '%$state%'
                       OR $pnDiagramcolumn[tech1]        LIKE '%$tech1%'
                       OR $pnDiagramcolumn[tech2]        LIKE '%$tech2%'
                       OR $pnDiagramcolumn[tech3]        LIKE '%$tech3%'
                       OR $pnDiagramcolumn[status]       LIKE '%$status%'
                       OR $pnDiagramcolumn[diagram_type] LIKE '%$diagram%'
                       OR $pnDiagramcolumn[author]       LIKE '%$author%'
                       OR $pnDiagramcolumn[category]     LIKE '%$category%')"
    ;

        print_r($sql);
        die;

    }


    and when I print the SQL out I get this:
    Code
    SELECT * FROM nuke_pnDiagram_data WHERE( nuke_pnDiagram_data.site_name LIKE '%%' OR nuke_pnDiagram_data.site_type LIKE '%%' OR nuke_pnDiagram_data.city LIKE '%%' OR nuke_pnDiagram_data.state LIKE '%%' OR nuke_pnDiagram_data.tech1 LIKE '%%' OR nuke_pnDiagram_data.tech2 LIKE '%%' OR nuke_pnDiagram_data.tech3 LIKE '%%' OR nuke_pnDiagram_data.status LIKE '%%' OR nuke_pnDiagram_data.diagram_type LIKE '%%' OR nuke_pnDiagram_data.author LIKE '%%' OR nuke_pnDiagram_data.category LIKE '%%')


    I have tried building the vars in the statement in the above method and like this:
    Code
    '".$itemname."',


    Neither of these work, am I building this incorrectly???

    Thanks
    -SUNADMN
  • Link to this postingPosted: 12.01.2005, 21:11
    Profile
    jediping
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    12.03.07
    Posts:
    387
    I think you just need to do extract($args) and you should be okay.
  • Link to this postingPosted: 12.01.2005, 21:20
    Profile
    sunadmn
    rank:
    Helper Helper
    registered:
     October 2004
    Status:
    offline
    last visit:
    01.03.06
    Posts:
    437
    Yup jess that was it I keep overlooking the obvious here all the darn time. Ok so now I will work the rest.


    Thanks jedi

    -SUNADMN
  • Link to this postingPosted: 12.01.2005, 21:33
    Profile
    sunadmn
    rank:
    Helper Helper
    registered:
     October 2004
    Status:
    offline
    last visit:
    01.03.06
    Posts:
    437
    Ok so jedi do you have any idea how I would use the render engine to produce results from that quewry and I run the SQL??? I am a little lost here as this is a stand alone function and nothing in the module really looks like anything I would use her.



    Thanks
    -SUNADMN
  • Link to this postingPosted: 12.01.2005, 22:01
    Profile
    jediping
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    12.03.07
    Posts:
    387
    I think your best bet would be to use a similar function to the view/display combo. Print out a list of the sites as links to where they can see all the information about it.
  • Link to this postingPosted: 12.01.2005, 22:19
    Profile
    sunadmn
    rank:
    Helper Helper
    registered:
     October 2004
    Status:
    offline
    last visit:
    01.03.06
    Posts:
    437
    Ok kewl I will take a look there and get back with you and let you know my results.


    Thanks man
    -SUNADMN
  • Link to this postingPosted: 13.01.2005, 00:59
    Profile
    sunadmn
    rank:
    Helper Helper
    registered:
     October 2004
    Status:
    offline
    last visit:
    01.03.06
    Posts:
    437
    Ok so it has to be back to basics here as I can't figure out how to port the logic of the view/dispaly function to port to a search as the view/display functions dont really return a single item for a given match rather produce all items in the DB.

    So I am going to make a list here of what is needed and hope for some insite on what else I am missing:

    1st) a Menu link to a user function that produces a pntemplate file for a seach form ( done I have this part working )
    2nd) a query function for the pntemplate file to call to that will run the pnuserapi function to get the data ( for the most part this is done but I think I am missing some logic here )
    3rd) a userapi function that takes the form data from the pntemplate and runs a SQL query to produce a data set ( I believe I have this done, the part I am hung on is the display portion of code how do I translate the data returned from the API function to a pntemplate )

    I know this may sound trivial to some, but for the life of me I just can't grasp the logic behind it please please I need some help.


    Thanks
    -SUNADMN
  • Link to this postingPosted: 13.01.2005, 01:46
    Profile
    jediping
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    12.03.07
    Posts:
    387
    Are you sure the search function will return only one result? It seems possible that there would be more than one result, yes? For example, there's going to (probably) be more than one person with tech1, yes? The SQL result will be all the details about everyone who has tech1.

    Now you need to get the SQL result into something you can use. This is similar to what you use in the main view function, by putting the results into an $items variable, sending it to the pnuser file, which then gets it ready for display.

    Does that help?
Goto page : 1 | 2 Next Page

Start ::  Developers Corner ::  Module Development ::  Building a search function??

Main Menu

Extensions Database

Documentation

Development

Login





 


 Log in Problems?
 New User? Sign Up!

Donate to Zikula