Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. Database search function in php

Database search function in php

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
tutorialphpdatabasehelp
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    offroaderdan
    wrote on last edited by
    #1

    Experts, I have a table in php which displays all serial numbers in the program. What i would like to do is when the user for example wants to find serial number ABCDEF123 they will type it in the text box and then press submit. I would then like all the other serial numbers to dissapear/hide and then just show tht serial number. I have created the text box and button in php but dont know how to do the above. If anybody could help that would be great Many thanks Dan

    C L enhzflepE 3 Replies Last reply
    0
    • O offroaderdan

      Experts, I have a table in php which displays all serial numbers in the program. What i would like to do is when the user for example wants to find serial number ABCDEF123 they will type it in the text box and then press submit. I would then like all the other serial numbers to dissapear/hide and then just show tht serial number. I have created the text box and button in php but dont know how to do the above. If anybody could help that would be great Many thanks Dan

      C Offline
      C Offline
      cjoki
      wrote on last edited by
      #2

      the simple way would be to make a form and have the page post to itself. At the top of the page in php

      <?php ... ?>

      check to see if the field has been submitted using isset() and if so run a sql query and output the info below the form in a table. Be extra careful with checking the input value before you run it in a query. I run a scrubber function that only permits valid characters to be used. Also read up on mysql_escape_string(), add_slashes() and related function and the user comments. A lot of good info in there.

      1 Reply Last reply
      0
      • O offroaderdan

        Experts, I have a table in php which displays all serial numbers in the program. What i would like to do is when the user for example wants to find serial number ABCDEF123 they will type it in the text box and then press submit. I would then like all the other serial numbers to dissapear/hide and then just show tht serial number. I have created the text box and button in php but dont know how to do the above. If anybody could help that would be great Many thanks Dan

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        The W3Schools have a page explaining how[^] to filter the data from a database using PHP, might be a good starting point :)

        I are Troll :suss:

        1 Reply Last reply
        0
        • O offroaderdan

          Experts, I have a table in php which displays all serial numbers in the program. What i would like to do is when the user for example wants to find serial number ABCDEF123 they will type it in the text box and then press submit. I would then like all the other serial numbers to dissapear/hide and then just show tht serial number. I have created the text box and button in php but dont know how to do the above. If anybody could help that would be great Many thanks Dan

          enhzflepE Offline
          enhzflepE Offline
          enhzflep
          wrote on last edited by
          #4

          I note that you'd like the other numbers to disappear/hide - implying that they're already visible on the page. If that's the case, then why use php for that I wonder? Surely the approach to use is one of JavaScript? I'd achieve what I understand as the aim with code resembling the following:

          <!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">
          .style1 {
          font-size: 24px;
          font-weight: bold;
          }
          .hiddenTxt {
          display: none;
          }
          </style>
          <script type="text/javascript">
          function byId(e){return document.getElementById(e)}
          function doFind()
          {
          var table = byId("table1");
          var row , x, y
          var searchStr

          searchStr = byId("serialInput").value
          for (y=0; y<5; y++)
          {
          	row = table.rows\[y\]
          	for (x=0; x<5; x++)
          	{
          		if (row.cells\[x\].innerHTML != searchStr)
          			row.cells\[x\].className = "hiddenTxt" 
          		else
          			row.cells\[x\].className = ""
          	}
          }
          

          }

          function doReset()
          {
          var table = byId("table1"), row , cell, x, y

          for (y=0; y<5; y++)
          {
          	row = table.rows\[y\]
          	for (x=0; x<5; x++)
          	{
          		cell = row.cells\[x\]
          		cell.className = ""
          	}
          }
          

          }
          </script>
          </head>

          <body>
          <table width="300" border="2" bordercolor="#333333" id="table1">
          <caption>
          <span class="style1">Serial Numbers</span>
          </caption>
          <tr>
          <td>1234</td>
          <td>5678</td>
          <td>9012</td>
          <td>3456</td>
          <td>8901</td>
          </tr>
          <tr>
          <td>abcd</td>
          <td>efgh</td>
          <td>ijkl</td>
          <td>mnop</td>
          <td>qrst</td>
          </tr>
          <tr>
          <td>uvwx</td>
          <td>yz</td>
          <td>a</td>
          <td>b</td>
          <td>c</td>
          </tr>
          <tr>
          <td>d</td>
          <td>e</td>
          <td>f</td>
          <td>g</td>
          <td>h</td>
          </tr>
          <tr>
          <td>i</td>
          <td>j</td>
          <td>k</td>
          <td>l</td>
          <td>m</td>
          </tr>
          </table>
          <p>Search for
          <

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups