Results 1 to 5 of 5

Thread: format and search

  1. #1

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    format and search

    For some reason i can not get my search box's to line up..

    Also, is there an easier way to make this? I have multiple fields i want to search. I was thinking maybe make a drop down box, and then just have 1 field where you enter text, then a drop down box with the different querys.

    I wanted to see if the results can be displayed on the same page, instead of posting it to a new page.

    Here is my layout:



    Here is my code.
    Thanks again.

    PHP Code:
    <?php
    //adding header.php
    $page_title "Enter New Model Information";
    include(
    '../php/header.php');
    ?>

    <?php
    //connection to database
    include('../db_conn/mysql_conn.php');
    ?>

    <table>
    <tr>
        <td rowspan="2">
        <fieldset>
        <table>
    <tr>
        <td><form action="Search.php?pasc_id=<?php $pasc_id?>" method="post"><input type="submit" name="submit" value="Search" align="right"/> <input type="text" name="pasc_id" size="20" maxlenght="20" /></td>
        <td valign="top"><font size="-1">Pasc ID</font></form></td></tr>
    <tr>
        <td><form action="Search.php" method="post"><input type="submit" name="submit" value="Search" align="right"/> <input type="text" name="return_po" size="20" maxlenght="20" /></form></td>
        <td valign="top"><font size="-1">PO Number</font></td></tr>
    <tr>
        <td><form action="Search.php" method="post"><input type="submit" name="submit" value="Search" align="right"/> <input type="text" name="part_number" size="20" maxlenght="20" /></form></td>
        <td valign="top"><font size="-1">Part Number</font></td></tr>
    <tr>
        <td><form action="Search.php" method="post"><input type="submit" name="submit" value="Search" align="right"/> <input type="text" name="dss_what_was_repaired" size="20" maxlenght="20" /></form></td>
        <td valign="top"><font size="-1">What was repaired</font></td></tr>
    <tr>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
    </tr>
    </table>


        </fieldset>

        </td>
    </tr>
    <tr>
    </tr>
    </table>

    <?php
    if($_SERVER['REQUEST_METHOD'] == "POST"){ 
      
    //do your error checking now 
      //--> check if each variable you want to use exists using isset(), and if it doesn't, make an error 
      
    $errors = array(); //the error variable 

        
    $pasc_id trim($_POST['pasc_id']);  
      
      
    //now, we won't do ANYTHING unless there are no errors 
      
    if(count($errors) == 0){ 
        
    //submit your stuff 
        
    mysql_query("UPDATE dss_returns SET part_number='$partnumber',return_po='$return_po',date_entered='$date_entered',part_notes='$part_notes',part_returned='$part_returned' WHERE pasc_id='$pasc_id'") or die(mysql_error());
        echo 
    'Your information has been successfully updated. Refreshing page' ' <img src="../images/working.gif">'
        
        echo 
    '<meta HTTP-EQUIV="refresh" content=2; url="Update.php">';
      }else{ 
        
    //there were errors, spit them all out 
        
    echo 'The following fields were left blank:' "\n\n"
        foreach(
    $error as $errors){ 
          echo 
    $error "\n"
        } 
        echo 
    "\n" 'Please fill out the form again'
      } 

    ?>

    <?php 
    //adding footer.php
    include('../php/footer.php');
    ?>

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: format and search

    this will submit to itself and do what you want to do.

    PHP Code:
    <form action="?" method="post">
      <input type="text" name="keyword" />
      <select name="type">
        <option value="pasc_id">Pasc ID</option>
        <option value="po_number">PO Number</option>
        <option value="part_no">Part Number</option>
        <option value="repaired">What was repaired</option>
      </select>
      <input type="submit" value="search" />
    </form>
    <pre>
    <?php
      
    if($_SERVER['REQUEST_METHOD'] == "POST"){
        switch(
    $_POST['type']){
          case 
    "pasc_id":
            
    //do your pasc_id search stuff here
            
    $sql "select blah from table where pasc_id='1'";
            break;
          case 
    "po_number":
            
    //po_number stuff
            
    $sql "select blah from table where po_number='234'";
            break;
          case 
    "part_no":
            
    //part_no stuff
            
    $sql "select blah from table where part_no='878'";
            break;
          case 
    "repaired":
            
    //repair stuff
            
    $sql "select blah from table where repaired='blah blah blah'";
            break;
        }
        
    $query mysql_query($sql);
        while(
    $arr mysql_fetch_array($query)){
          
    print_r($arr);
        }
      }
    ?>
    </pre>

  3. #3

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: format and search

    Kows

    How do i put the value selected in the query into the where xxxx='here' ?

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: format and search

    something like this should work
    PHP Code:
    <?php
      $keyword 
    mysql_real_escape_string($_POST['keyword']);
      switch(
    $_POST['type']){
        case 
    "pasc_id"$field "pasc_id"; break;
        case 
    "po_number"$field "po_number"; break;
        case 
    "part_no"$field "part_no"; break;
        default: die(
    "invalid input!");
      }
      
    $sql "SELECT blah FROM tablename WHERE $field LIKE '%$keyword%'";
      
    //....
    ?>

  5. #5

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: format and search

    thanks kows

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width