Can help to check and correct my search engine code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sheau Wei
    New Member
    • Sep 2006
    • 34

    Can help to check and correct my search engine code?

    This is the search engine code that i create, but it was error and didnt come out the result. Cn u help me to check what wrong with my code?
    Thanks

    <Table cellspacing=1 cellPadding=1 align=center>
    <td colspan=4>
    <h2 align=center>Bo mba inventory searching system</h2>
    <tr>
    <td>
    <h4 Balai Bomba Inventory Searching System</H4>
    <form name="search" method="post" action="<?=$PHP _SELF?>">
    Search for:
    <br><input type="text" name="search">

    <br><Select NAME="field">
    <Option VALUE="Operasi" >Operasi</option>
    <Option VALUE="Balai">B alai</option>
    <Option VALUE="Komunika si">Komunikas i</option>
    </select>

    <br><input type="submit"na me="Submit"valu e="Submit"/>

    </form>

    <?
    //required file for database connection
    require("config .php");
    if (isset($_POST['search'])) {
    $search = mysql_real_esca pe_string($_POS T["search"]);
    $field=mysql_re al_escape_strin g($_POST["field"]);
    echo "<h2>Result s</h2><p>";

    //If they did not enter a search term we give them an error
    if ($search== "") {
    echo "<p>You forgot to enter a search term";
    }

    //Now we search for our search term, in the field the user specified
    $data ="SELECT * FROM listofitem ";
    if($field=='Ope rasi'){
    $data .="AND listofitem.Nama Peralatan LIKE'%search%'" ;}

    elseif($field== 'Balai'){
    $data .="AND listofitem.Nama Peralatan LIKE '%search%'";}

    elseif($field== 'Komunikasi'){
    $data .="AND listofitem.Nama Peralatan LIKE'%search%'" ;}

    $result=mysql_q uery($data);


    //echo "<tr><td bgcolor='#CCCCF F'>ID</th><td bgcolor='#CCCCF F'>NamaPeralata n</th><td bgcolor='#CCCCF F'>Jenama</td> </tr>";
    //And we display the results
    if($result && (mysql_num_rows ($result))>0){
    while($row = mysql_fetch_ass oc( $result )){
    echo "<tr><td><a href='Informati onPage.php?id={ $row['ID']}'>{$result['ID']}</a></td>
    <td><a href='Informati onPage.php?id={ $row['NamaPeralatan']}'>{$result['NamaPeralatan']} </td>
    <td>{$row['Jenama']}</td>
    </tr>";
    echo" <b>Searched For:</b> " .$search;
    }
    }
    //This counts the number or results - and if there wasn't any it gives them a little message explaining that
    $anymatches=mys ql_num_rows($re sult);
    if ($anymatches == 0)
    {
    echo "Sorry, but we can not find an entry to match your query<br><br>";
    }
    }
    //And we remind them what they searched for


    ?>

    <a href='AddNew(op erasi).php?id=S earch Again'>AddNew(O perasi)</a>
    <a href='AddNew(Ba lai).php?id=Sea rch Again'>AddNew(B alai)</a>
    <a href='AddNew(Ko munikasi).php?i d=Search Again'>AddNew(K omunikasi)</a>
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Firstly, it would be nice to your co members to display your approx 70 lines of code within code or php tags.
    Secondly
    but it was error and didnt come out the result. Cn u help me to check what wrong with my code?
    is not really giving any information on:
    • what the error was
    • what you have done to track the error (like echo traces)
    • how far in the code everything is still working as expected

    Please provide the members that information.

    Ronald :cool:

    Comment

    • Sheau Wei
      New Member
      • Sep 2006
      • 34

      #3
      Originally posted by ronverdonk
      Firstly, it would be nice to your co members to display your approx 70 lines of code within code or php tags.
      Secondly
      is not really giving any information on:
      • what the error was
      • what you have done to track the error (like echo traces)
      • how far in the code everything is still working as expected

      Please provide the members that information.

      Ronald :cool:
      my error is what ever the keyword i insert into ,it still come out with the same result even i option in field is different . The selection there seen ike did not function alt all. can u check for me?

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Originally posted by Sheau Wei
        my error is what ever the keyword i insert into ,it still come out with the same result even i option in field is different . The selection there seen ike did not function alt all. can u check for me?
        You have not answered the questions asked, you just keep on saying: "It does not work as expected". The questions were:
        - what the error was, you answered that: "It does not work at all"
        - what you have done to track the error (like echo traces)
        - how far in the code everything is still working as expected

        You have to do that before we go on chasing across your code.

        Ronald :cool:

        Comment

        Working...