PHP Login System with Admin Features

This forum was created to talk about the PHP Login System with admin features created by jpmaster77 on evolt's website


    Add "Search" functionality

    Share
    avatar
    mbrad

    Number of posts : 42
    Registration date : 2009-02-19

    Add "Search" functionality

    Post  mbrad on Mon Apr 27, 2009 10:21 am

    Thanks for taking the time to read my question.

    I have a page recipe.php that I'd like to add a Search to. The user would type in a word, then the search would look in the DB for recipes with that word in the recipe name.

    I've got something but it isn't working. I'm using the session.php page to try to return the values. I think I'm doing this correctly, but am not getting the results I'm needing. My sql query is ok, as it returns the proper results when run in phpMyAdmn, so it must be my php.

    session.php
    Code:
    var $RecipeSearchResults = array();

      function RecipeSearchResults($Name) {
      global $database;
      //$q = "Select `tblRecipeID` FROM `tblrecipe` WHERE `RecipeName` LIKE '%" .$_POST['TitleSearch']. "%';";
      $q = "SELECT `tblRecipeID` FROM `tblrecipe` WHERE `RecipeName` LIKE '%Brown%';";
      $this->RecipeSearchResults = $database->query($q);
      return $this->RecipeSearchResults["$Name"];
      }

    recipe.php
    Code:
    <?php   
    include("MainHeader.php");
    ?>
    <body onLoad="setFocus()">
    <?php   
    include("MainHeader2.php");
    ?>
    <div id="ContentContainer">
    <?php
    /**
     * User has already logged in, so display relavent links, including
     * a link to the admin center if the user is an administrator.
     */
    if($session->logged_in){

             $q = "SELECT * FROM `tblrecipe` WHERE `ActiveRecipe`=1";
               $result = mysql_query($q);
             
             $q3 = "SELECT `RecipeName`, `DateEdited` FROM `tblrecipe` WHERE `ActiveRecipe`=1";
               $result3 = mysql_query($q3);
          ?>
    <div id="NavContainer" style="width:100%;">
       <ul id="mainmenu">
                    <li><a href="new_recipe.php" onmouseover="MoveIconDown('new_messages')"; onmouseout="MoveIconUp('new_messages')";>New Recipe<img id="new_messages" class="menuicon" src="images/Post-It_Small.png" /></a></li>
                    <li><a href="recipe.php" onmouseover="MoveIconDown('all_messages')"; onmouseout="MoveIconUp('all_messages')";>Recipe<img id="all_messages" class="menuicon" src="images/Post-It_Small.png" /></a></li>
       </ul>
        <h3 class="SubTitle">Recipe(s)</h3><br /><h5>Click on a Recipe button below to view it. The date of last edit is shown under the recipe name.</h5>
    </div>
    <div id="SearchContainer" style="width:100%;">
    <p>Use a method to search for a recipe</p>
    <h5>Title</h5>
    <form action="recipe.php" method="POST">
    <table>
    <tr>
    <td><input id="TitleSearch" name="TitleSearch" /></td>
    <td><input type="hidden" id="subCreateRecipe" name="subTitleSearch" value="1" /></td>
    <td>&nbsp;</td><td>&nbsp;</td><td><input type="submit" value="Search" /></td>
    </tr>
    </table>
    </form>
    <h5>Ingredients</h5><h5>Meal</h5>
    </div>

    //***************This is where I'm testing to see if I'm getting anything from my function in session.php ***************************************

    <?php

    if ($session->RecipeSearchResults("tblRecipeID")!= Null) {

    echo "Something is there\n";
    echo $session->RecipeSearchResults("tblRecipeID") . "<br />";
    echo "Something is there 2\n";

    }
    else {

    echo "Equals Null";
    }

    while ($row = mysql_fetch_assoc($result)) {
       foreach($row as $key => $value) {
          if($key == 'RecipeName') {
          /*echo "<div class=\"BudgetNavCont\"><a class=\"BudgetButton\" href=\"budget.php#".$row['BudgetName']."\"><b>".$row['BudgetName']."</b><br />(".$row['DateEdited'].")</a></div>";*/
          //Make tblBudget table
          echo "<table width=\"800\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\"><a name=\"".$row['RecipeName']."\">&nbsp;</a>\n";
          echo "<tr>\n";
          echo "<td class=\"ThinBorderBudgetH BudgetName\">Recipe Name</td>\n";
          echo "<td class=\"ThinBorderBudgetH\">Category</td>\n";
          echo "<td class=\"ThinBorderBudgetH\">Sub Category</td>\n";
          echo "<td class=\"ThinBorderBudgetH\">From</td>\n";
          //echo "<td class=\"ThinBorderBudgetH\">Special Instructions</td>\n";
          echo "<td class=\"ThinBorderBudgetH\">Date Edited</td>\n";
          echo "<td class=\"ThinBorderBudgetH\">Active</td>\n";
          echo "<td><form action=\"edit_recipe.php\" method=\"POST\"><input type=\"hidden\" name=\"rowIDRecipe\" value=\"" . $row['tblRecipeID']. "\" /><input type=\"submit\" value=\"Edit\" /><span>&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"#top\" class=\"TopLink\">Top</a></span></form></td>";
          echo "</tr>\n";
          echo "<tr>\n";
          echo "<td class=\"ThinBorderBudget BudgetName\">".$row['RecipeName']."</td>";
          echo "<td class=\"ThinBorderBudget\">".$row['Category']."</td>";
          echo "<td class=\"ThinBorderBudget\">".$row['SubCategory']."</td>";
          echo "<td class=\"ThinBorderBudget\">".$row['Fromm']."</td>";
          //echo "<td class=\"ThinBorderBudget\">".nl2br($row['SpecialInstructionsMain'])."</td>";
          echo "<td class=\"ThinBorderBudget\">".$row['DateEdited']."</td>";
          echo "<td class=\"ThinBorderBudget\">".$row['ActiveRecipe']."</td>";
          echo "</tr>\n";
          echo "<tr>\n";
          echo "<td colspan=\"6\" class=\"ThinBorderBudgetH\">Instructions</td>\n";
          echo "</tr>\n";
          echo "<tr>\n";
          echo "<td colspan=\"6\" class=\"ThinBorderBudget\">".nl2br($row['SpecialInstructionsMain'])."</td>";
          echo "</tr>\n";
          echo "</table>\n";
          echo "<br />";
          //Make tblBudgetDetail table wth while and foreach. Need seperate query to generate this. Need tblBudgetID for the where in this query.

          echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\">\n";
          echo "<tr>\n";
          echo "<td class=\"ThinBorderBudgetDetailH\">Ingredients</td>\n";
          echo "<td class=\"ThinBorderBudgetDetailH\">Amount</td>\n";
          echo "<td class=\"ThinBorderBudgetDetailH\">Special Instructions</td>\n";
          echo "</tr>\n";
          
          $q2 = "SELECT `Ingredient`, `Amount`, `SpecialInstructions` FROM qryrecipeinfo WHERE `RecipeID`=".$row['tblRecipeID'].";";
          $result2 = mysql_query($q2);
             while ($row2 = mysql_fetch_assoc($result2)) {
                echo "<tr>\n";
                foreach($row2 as $key2 => $value2) {
                if ($key2<>'RecipeID'){
                //nl2br("Welcome\r\nThis is my HTML document", false);
                   if ($key2=='SpecialInstructions'){
                      echo "<td class=\"ThinBorderBudgetDetail\">";
                      echo nl2br($value2);
                      echo "</td>\n";
                   }
                   else {
                      echo "<td class=\"ThinBorderBudgetDetail\">";
                      echo $value2;
                      echo "</td>\n";
                   }
                }
                }
                echo "</tr>\n";
             }
          echo "</table>\n<br /><hr /><br />";            
          }
       }
    }
    ?>
    </div>
    <?php
    }
    else{
    if($form->num_errors > 0){
      echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>";
    }
    }
    ?>
    </div>
    </div>
    </body>
    </html>

    Any help would be great,

    Thanks,

    Brad
    avatar
    mbrad

    Number of posts : 42
    Registration date : 2009-02-19

    Re: Add "Search" functionality

    Post  mbrad on Mon Apr 27, 2009 11:11 am

    I got it figured out. I forgot to add the mysql_fetch_array function when returning the results.

    Works now.

      Current date/time is Sun Oct 22, 2017 4:55 pm