Search Results

Discussion in 'PHP' started by majidk, Jul 21, 2009.

  1. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #21
    It is in the correct place. I don't know why you're not seeing it in dreamweaver. Is dreamweaver compatible with JavaScript? I'm really not sure if it is or not as I said I don't use it, if you're seeing it in your browser the most likely thing is that dreamweaver does not view it.
     
    scottlpool2003, Jul 22, 2009 IP
  2. majidk

    majidk Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #22
    Hello friend. How are you, hope everythign is ok. Sorry to bother you, but I just put in the code that you gave me but its not working. When I enter a search and click search, I just get "Please enter a search".

    This is the code:

    <title>Learoyd Packaging&gt;&gt;&gt;</title><div id="search_box">
    <div>
    <form action="test_search.php" method="get">
    <input type="text" name="query" id="query" size="40" value="" action="test_search.php" columns="2" autocomplete="off" delay="1500" />
    <input type="submit" value="Search">
    <input type="hidden" name="search" value="1">
    </form>
    <center></center>
    </div>
    <p>&nbsp;</p>

    <?
    //connect to your database ** EDIT REQUIRED HERE **
    mssql_connect("***","****","****"); //(host, username, password)

    //specify database ** EDIT REQUIRED HERE **
    mssql_select_db("CompanyL") or die("Unable to select database"); //select which database we're using;
    ?><?
    // Get the search variable from URL
    $s = @$_GET['s'];
    $var = @$_GET['q'] ;
    $trimmed = trim($var); //trim whitespace from the stored variable
    $str = strtoupper($title);
    $title=$_GET['q'];


    ?>


    <?php

    // Get the search variable from URL
    $s = @$_GET['s'];
    $var = @$_GET['q'] ;
    $trimmed = trim($var); //trim whitespace from the stored variable

    // rows to return
    $limit=10;

    // check for an empty string and display a message.
    if ($trimmed == "")
    {
    echo "<p>Please enter a search...</p>";
    exit;
    }

    // check for a search parameter
    if (!isset($var))
    {
    echo "<p>We dont seem to have a search parameter!</p>";
    exit;
    }


    // Build SQL Query

    $query = "SELECT * FROM CompanyL.dbo.DesignControl WHERE id"; // EDIT HERE and specify your table and field names for the SQL query

    $numresults=mysql_query($query);
    $numrows=mysql_num_rows($numresults);
    // Build SQL Query
    $query = "SELECT * FROM films WHERE SpecRef LIKE \"%$trimmed%\""; // EDIT HERE and specify your table and field names for the SQL query
    $numresults=mysql_query($query);
    $numrows=mysql_num_rows($numresults);

    // If we have no results, offer a google search as an alternative

    if ($numrows == 0)
    {
    echo "<h4>Results</h4>";

    echo "<p>Sorry, your search: &quot;" . $trimmed . "&quot; returned zero results</p>";

    // google
    echo "<p><a href=\"http://www.google.com/search?q="
    . $trimmed . "\" target=\"_blank\" title=\"Look up
    " . $trimmed . " on Google\">Click here</a> to try the
    search on google</p>";
    }

    // next determine if s has been passed to script, if not use 0
    if (empty($s)) {
    $s=0;
    }

    // get results
    $query .= " limit $s,$limit";
    $result = mysql_query($query) or die("Couldn't execute query");

    // display what the person searched for
    echo "<p>You searched for: &quote;" . $var . "&quote;</p>";

    // begin to show results set
    //echo "Results";
    $count = 1 + $s ;

    // now you can display the results returned
    while ($row= mysql_fetch_array($result)) {
    $PrePressDate = $row["Pre_Press_Date"];
    $JobDescription = $row["Job_Description"];
    $SpecRef = $row["Spec_Ref"];
    $ReproHouseDesignAgency = $row["Repro_House_Design_Agency"];
    $EndUserFamily = $row["End_User_Family"];
    $XRef = $row["X_Ref"];
    $CustRef = $row["Cust_Ref"];

    echo "<textarea>$PrePressDate</textarea>";
    echo "<textarea>$JobDescription</textarea>";
    echo "<textarea>$SpecRef</textarea>";
    echo "<textarea>$ReproHouseDesignAgency</textarea>";
    echo "<textarea>$EndUserFamily</textarea>";
    echo "<textarea>$XRef</textarea>";
    echo "<textarea>$</textarea>";
    $count++ ;
    }


    ?>
     
    majidk, Jul 23, 2009 IP
  3. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #23
    Have you got an URL to show me so I can see what it's doing?
     
    scottlpool2003, Jul 24, 2009 IP
  4. majidk

    majidk Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #24
    Hi scott, how are you. i just need abit of help.

    Ive got the followng two tables and i cant get the calculation working so that the total is automatically displayed, what am i doing wrong. Below is my code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript">
    function calcTotal(){
    var q = document.getElementById("RPT Length");
    var r = document.getElementById("No Round");
    var total = (q.value*1) + (r.value*1) + (s.value*1)
    var a = document.getElementById("Total");
    a.value = total;
    }
    </script>
    </head>


    <body>
    <table border="1" cellpadding="0" cellspacing="0">
    <tr>
    <td colspan="2" valign="top"><p align="center"><strong>Single Impression / Pack detail</strong></p></td>
    </tr>
    <tr>
    <td width="59" valign="top"><p>Pack width</p></td>
    <td width="79" valign="top"><p>
    <input name="textfield" type="text" id="textfield7" size="10" />
    </p></td>
    </tr>
    <tr>
    <td width="59" valign="top"><p>RPT Length</p></td>
    <td width="79" valign="top"><p>
    <input type="text" id="RPT Length" size="1" onKeyPress="calcTotal()"/>
    </p></td>
    </tr>
    <tr>
    <td width="59" valign="top"><p>No Across</p></td>
    <td width="79" valign="top"><p>
    <input name="textfield" type="text" id="textfield9" size="10" />
    </p></td>
    </tr>
    <tr>
    <td width="59" valign="top"><p>No Round</p></td>
    <td width="79" valign="top"><p>
    <input type="text" id="RPT Length" size="1" onKeyPress="calcTotal()"/>id="Total" />
    </p></td>
    </tr>
    <tr>
    <td width="59" valign="top"><p>Shrink Tol</p></td>
    <td width="79" valign="top"><p>
    <input name="textfield" type="text" id="textfield11" size="10" />
    </p></td>
    </tr>
    <tr>
    <td width="59" valign="top"><p>Trim Allowance</p></td>
    <td width="79" valign="top"><p>
    <input name="textfield" type="text" id="textfield12" size="10" />
    </p></td>
    </tr>
    </table>
    <table width="201" border="1" cellpadding="0" cellspacing="0">
    <tr>
    <th height="0" colspan="2" scope="col">Print</th>
    </tr>
    <tr>
    <td width="83" height="0" scope="row">Plate Thickness </td>
    <td width="112" height="0"><form id="form3" name="form1" method="post" action="">
    <label>
    <select name="select4" id="select4">
    <option>45</option>
    <option>67</option>
    <option>100</option>
    <option>112</option>
    </select>
    </label>
    </form></td>
    </tr>
    <tr>
    <td width="83" height="0" scope="row">Barcode Colour </td>
    <td width="112" height="0"><input name="textfield4" type="text" id="textfield5" size="8" /></td>
    </tr>
    <tr>
    <td width="83" height="0" scope="row">Eyemark size/colour </td>
    <td width="112" height="0"><input type="checkbox" name="checkbox2" id="checkbox2" />
    Black</td>
    </tr>
    <tr>
    <td width="83" height="0" scope="row">Print Orientation </td>
    <td width="112" height="0"><form id="form5" name="form2" method="post" action="">
    <p>
    <label for="label"></label>
    <select name="select4" id="label">
    <option>Surface</option>
    <option>Reverse</option>
    </select>
    </p>
    </form></td>
    </tr>
    <tr>
    <td width="83" height="0" scope="row">Cylinder/sleeve size </td>
    <td width="112" height="0"><input type="text" disabled="disabled" style="width:70px;" size="1" id="Total" /></td>
    </tr>
    <tr>
    <td width="83" height="0" scope="row">Gear Size </td>
    <td width="112" height="0"><input name="textfield4" type="text" id="textfield7" size="8" /></td>
    </tr>
    <tr>
    <td width="83" height="0" scope="row">LAM Sleeve size </td>
    <td width="112" height="0"><input name="textfield4" type="text" id="textfield10" size="8" /></td>
    </tr>
    <tr>
    <th height="0" colspan="2" scope="row">Production</th>
    </tr>
    <tr>
    <td width="83" height="0" scope="row">Process control complete </td>
    <td width="112" height="0"><form id="form6" name="form4" method="post" action="">
    <label>
    <select name="select4" id="select5">
    <option>Yes</option>
    <option>No</option>
    </select>
    </label>
    </form></td>
    </tr>
    </table>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    </body>

    </html>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    <!--
    body,td,th {
    font-size: 9px;
    }
    -->
    </style></head>

    <body>
    <table width="198" border="1" cellpadding="0" cellspacing="0">
    <tr>
    <th height="0" colspan="2" scope="col">Print</th>
    </tr>
    <tr>
    <td width="83" height="0" scope="row">Plate Thickness </td>
    <td width="109" height="0"><form id="form1" name="form1" method="post" action="">
    <label>
    <select name="select" id="select">
    <option>45</option>
    <option>67</option>
    <option>100</option>
    <option>112</option>
    </select>
    </label>
    </form></td>
    </tr>
    <tr>
    <td width="83" height="0" scope="row">Barcode Colour </td>
    <td width="109" height="0"><input name="textfield11" type="text" id="textfield" size="8" /></td>
    </tr>
    <tr>
    <td width="83" height="0" scope="row">Eyemark size/colour </td>
    <td width="109" height="0"><input type="checkbox" name="checkbox" id="checkbox" />
    Black</td>
    </tr>
    <tr>
    <td width="83" height="0" scope="row">Print Orientation </td>
    <td width="109" height="0"><form id="form2" name="form2" method="post" action="">
    <p>
    <label for="select3"></label>
    <select name="select3" id="select3">
    <option>Surface</option>
    <option>Reverse</option>
    </select>
    </p>
    </form></td>
    </tr>
    <tr>
    <td width="83" height="0" scope="row">Cylinder/sleeve size </td>
    <td width="109" height="0"><input name="textfield2" type="text" id="textfield2" size="8" /></td>
    </tr>
    <tr>
    <td width="83" height="0" scope="row">Gear Size </td>
    <td width="109" height="0"><input name="textfield2" type="text" id="textfield3" size="8" /></td>
    </tr>
    <tr>
    <td width="83" height="0" scope="row">LAM Sleeve size </td>
    <td width="109" height="0"><input name="textfield3" type="text" id="textfield4" size="8" /></td>
    </tr>
    <tr>
    <th height="0" colspan="2" scope="row">Production</th>
    </tr>
    <tr>
    <td width="83" height="0" scope="row">Process control complete </td>
    <td width="109" height="0"><form id="form4" name="form4" method="post" action="">
    <label>
    <select name="select2" id="select2">
    <option>Yes</option>
    <option>No</option>
    </select>
    </label>
    </form></td>
    </tr>
    </table>
    </body>
    </html>


    I want the total to be displayed in the Cylinder/sleeve size

    Thanks
     
    majidk, Jul 27, 2009 IP
  5. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #25
    Hiya mate, for a start you're integrating 2 websites into one there. Bad move.

    Other than that I can't really do anything as I have no online domains available for testing.
     
    scottlpool2003, Jul 28, 2009 IP
  6. majidk

    majidk Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #26
    Hi Friend, How are you.

    I need abit of help on a button i wanting to create. I want to create a button in which by clicking it, a dialogue button appears and allows you to save as the page.
     
    majidk, Jul 31, 2009 IP
  7. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #27
    Hey, just search for javascript save as buttons on Google :D
     
    scottlpool2003, Jul 31, 2009 IP
  8. majidk

    majidk Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #28
    Hi firend, how are you.Your going to kill me what im going to say, but im sorry. abit of help would be appreciated. Yesterday night at work, whilst trying to clear my files, i accidently deleted my search so unfortunately have to start over again which is a disapointing.

    Ive created the search box, but when I click search I get an empty screen, why?

    Here is the code:

    php.php

    <form action="search.php" method="post">
    <input type="text" name="query" id="query" size="40" value="" action="Search.php" columns="2" autocomplete="off" delay="1500">
    <input type="submit" value="Search">
    <input type="hidden" name="Search" value="1">
    </form>

    Search.php

    <html>
    <body>
    <?
    session_start();
    $myServer = '****';
    $myUser = '****';
    $myPass = '***';
    $myDB = '*****';
    $SpecRef = $_GET['query'];
    print ("$SpecRef");



    //connection to the database
    $dbhandle = mssql_connect($myServer, $myUser, $myPass)
    or die("Couldn't connect to SQL Server on $myServer");



    //select a database to work with
    $selected = mssql_select_db($myDB, $dbhandle)
    or die("Couldn't open database $myDB");
    //error message (not found message)begins
    $XX = "No Matches Found";
    //query details table begins
    $query = ("SELECT * FROM dbo.DesignControl WHERE Spec_Ref LIKE'$SpecRef%' ");
    // $query = ("SELECT * FROM dbo.DesignProcess");

    print(' is what you searched for:');


    //execute the SQL query and return records
    $result = mssql_query($query);

    $numRows = mssql_num_rows($result);
    echo "<h1>" . $numRows . " Record" . ($numRows == 1 ? "" : "s") . " Found </h1>";

    //display the results
    echo '<textarea>';
    while($row = mssql_fetch_array($result))
    {
    echo $row["Spec_Ref"] . "\n"; }
    echo '</textarea>';
    //close the connection
    mssql_close($dbhandle);
    //display the results
    while($row = mssql_fetch_array($result))
    {
    echo $row["Spec_Ref"] . "\n"; }
    echo '</textarea>';
    //close the connection
    mssql_close($dbhandle);
    //display the results
    while($row = mssql_fetch_array($result))
    {
    echo "<li>" . $row["Spec_Ref"] . "</li>";
    }
    //close the connection
    mssql_close($dbhandle);

    //textareaContent = "";

    //while ($row = @mysql_fetch_array($query))
    //{
    //$var1=$row["Player"];
    //$var2=$row["Avg"];
    //$var3=$row["HR"];
    //$var4=$row["RBI"];

    $textareaContent .= "Spec Ref: $var1 Avg: $var2 HR: $var3 RBI $var4 <br/>";
    //}

    //if (!isset($var1) || $var1=="") {
    //echo $XX;
    //}



    ?>
    </body>
    </html>
     
    majidk, Aug 3, 2009 IP
  9. majidk

    majidk Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #29
    If I created an FTP Account, would you be kind enough to do it for me plz...
     
    majidk, Aug 3, 2009 IP
  10. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #30
    er, don't confuse him, you need to understand the difference between PHP and JS here...

    'total' above is defined as the sum of all colour elements as a javascript variable. there's an element with id="Total" that gets the value of total assigned to its value.

    the js itself is rather shite - it should use parseInt() and not multiply the value by 1 to convert to integer...

    but in any case, the equivalent php for this would be something like this after the submission:
    // w/o casting data types / cleaning vars:
    $total = $_GET['colour 1'] + $_GET['colour 2'] + ... $_GET['colour nn'];
    
    PHP:
    obviously, since this bit the problem has kind of avalanched into something else (as you do) - good luck to you both :D
     
    Last edited: Aug 3, 2009
    dimitar christoff, Aug 3, 2009 IP