SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    basic search engine limit to user options

    Hi,
    I'm trying to develop a basic search in cms admin area with user options like category and or administrator and or containing text to which article belongs.
    Based on selected category or author show only this articles.
    Now I 'm stuck somewhere although I think I have solution 90% ready. I will ask you to look out my code and see what can be a problem.
    Whatever category or administrator or containing text is choose result is empty.
    But when I testing with print_r($_POST) I have on processing page ok array like this
    PHP Code:
    Array
    (
        [
    pretrazitekst] => google
        
    [cid] => 3
        
    [aid] => 4

    PHP Code:
    <?php
        
    include("../includes/init.php");
        
    $autori Users::find_all(); 
        
    $kategorije Category::find_all();

    ?>

                <?php

                $form 
    = new form();
                
    $form->setAttributes(array(
                    
    //"map" => array(2, 3, 2, 3),
                    
    "map" => array(3),
                    
    "tableAttributes" => array("width" => "500")
                ));
                
    ?>
                <form action="inc_searchContent.php" method="post">
                <?php
                    
    //$form->addHidden("cmd", "submit");
                    
    $form->addTextbox("Contain text""pretrazitekst");
                    
                    
    $catArr = array();
                    foreach(
    $kategorije as $row)
                    
    $catArr[$row->id] = $row->name;
                    
    $form->addSelectbox("Category""cid"""$catArr, array("required" => 1"class" => "actions","style" => "width: 100%;"));
        
                    
    $adminArr = array();
                    foreach(
    $autori as $row)
                    
    $adminArr[$row->id] = $row->username;            
                    
    $form->addSelectbox("Administrator""aid"""$adminArr, array("required" => 1"class" => "actions","style" => "width: 100%;"));    
                    
                    
    //$form->addTextbox("Field 3", "field3");
                    //$form->addTextbox("Field 4", "field4");
        
                    
    $form->addButton();
                    
    $form->render();
                
    ?>
                </form>
    and processing.php
    PHP Code:
    <?php
    require_once '../includes/init.php';
        
    $select "SELECT DISTINCT ID, LEFT(Title,60), Updated, Content";
        
    $from   " FROM page";
        
    $where  " WHERE 1=1";
        
        
    $aid $_POST['aid'];
        if (
    $aid != '') { // subcategory is selected
          
    $where .= " AND UserID='$aid'";
        }
        
        
    $cid $_POST['cid'];
        if (
    $cid != '') { // category is selected
          
    $from  .= ', page2category';
          
    $where .= " AND id = page_id AND p_category_id = '$cid'";
        }
        
        
    $pretrazitekst $_POST['pretrazitekst'];
        if (
    $pretrazitekst != '') { //  search text is set
          
    $where .= " AND Content LIKE '%$pretrazitekst%'";
        }
        
        
    $datum $_POST['datum'];
        if (
    $datum != '') { //  date is set
          
    $where .= " AND Updated LIKE '%$datum%'";
        }
    ?>


    <table width="100%" border="0">
      <tr> 
        <td><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Date</b></font></div></td>
        <td><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Title</b></font></div></td>
        <td><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Option</b></font></div></td>
      </tr>

    <?php
    $vijesti 
    = @mysql_query($select $from $where);
    if (!
    $vijesti) {
      echo(
    '</table>');
      die(
    '<p>Query error <br />'.
          
    'Error: ' mysql_error() . '</p>');
    }

    while (
    $vijest mysql_fetch_array($vijesti)) {

      echo(
    "<tr>\n");
      
      
    $id       $vijest['ID'];
      
    $date $vijest['formated_date'];
      
    $naslov  $vijest['LEFT(Title,60)'];
      
    $text  $vijest['Content'];
      
        if (
    strlen($naslov) == 60$naslov .= "...";
      
      echo 
    $naslov;
      echo 
    "<hr>";
      echo 
    $text


    }

    ?>
    </table>

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    solved !.

  3. #3
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jovalex View Post
    solved !.
    Let us know:
    what was the problem and what's the solution?

  4. #4
    SitePoint Evangelist Dave Morton's Avatar
    Join Date
    Sep 2003
    Location
    Carson City, NV
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We have but 2 paths here: Learning from our own mistakes, and learning from those of others. Please don't take away our 2nd path!
    Making a difference, one little psychotic episode at a time
    Geek Cave Creations
    Beta testers needed for pChat
    Dave's Gallery

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have to disappoint you guys, problem was realy obvious but it's not in the code I posted. Somewhere in code before this which I've posted another <FORM> was open and not closed where it should be.

    Thanks you for you interest.


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
  •