PHP - filter database with drop down menus and return

Mike_twMike_tw Member Posts: 20 ■□□□□□□□□□
Hey,

I really need some tips on how to make something similar/better than this:

http://www.jewson.co.uk/en/templates/bricklibrary/main.jsp?_requestid=1837060

Thats an example of what i want. How can i do this? Anyone with ideas?:)

Or if theres a script already outthere that will do this for me can someonel link it please

Thanks

Comments

  • PashPash Member Posts: 1,600 ■■■■■□□□□□
    what type of database...mysql?

    If so its easy as pie...plenty of guides on how to do this sort of thing. I would do something like this:

    1. Build the html forms with the fancy drop down menus.

    2. Create a .php page to process the results from the forms and then query the information required from your database.

    Really not very difficult if you are willing to read up.
    DevOps Engineer and Security Champion. https://blog.pash.by - I am trying to find my writing style, so please bear with me.
  • Mike_twMike_tw Member Posts: 20 ■□□□□□□□□□
    yes, mysql

    I'm not an expert at this stuff, i can read php + mysql but not so good at writing it all out.

    How would i add a picture to the result row like on that website i showed you. On that website, is near exact what i want but using php+mysql instead of java servlets.

    If you can point me to some good guides on this stuff i'd be thankful.
  • Mike_twMike_tw Member Posts: 20 ■□□□□□□□□□
    <center>
    <table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000">
    <tr>
    <td width="60">[b]Manufacturer[/b]</td>
    <td width="100">[b]Colour[/b]</td>
    <td width="70">[b]Texture[/b]</td>
    <td width="70">[b]Manufacturing Process[/b]</td>
    </tr>
    <tr>
    <td>
    <? $hostname = "l"; // The Thinkhost DB server.
    $username = "t"; // The username you created for this database.
    $password = "t; // The password you created for the username.
    $usertable = "t"; // The name of the table you made.
    $dbName = "tt"; // This is the name of the database you made.
    
    MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
    @mysql_select_db( "$dbName") or die( "Unable to select database");
    ?>
    <?
    $XX = "No Record Found, to search again please close this window";
    $query ="SELECT * FROM bricks WHERE";
    if ($Manufacturer != "SelectManufacturer") //The Default select value
    {
    
    switch ($Manufacturer) {
    case Manufacturer1:
    "SELECT * FROM mytable
    WHERE Manufacturer='Manufacturer1'";
    case Manufacturer2:
    "SELECT * FROM mytable
    WHERE Manufacturer='Manufacturer2'";
    break;
    case Manufacturer3:
    "SELECT * FROM mytable
    WHERE Manufacturer='Manufacturer3'";
    break;
    }
    }
    ?>
    $variable1=$row["Manufacturer"];
    $variable2=$row["Colour"];
    $variable3=$row["Texture"];
    $variable4=$row["Manufacturing Process"];
    
    print ("<tr>");
    print ("<td>$variable1</td>");
    print ("<td>$variable2</td>");
    print ("<td>$variable3</td>");
    print ("<td>$variable4</td>");
    print ("</tr>");
    }
    if (!$variable1)
    {
    print ("$XX");
    }
    ?>
    

    Is this heading on the right track?
  • TechJunkyTechJunky Member Posts: 881
    why not use DHTML to accomplish this?
  • Mike_twMike_tw Member Posts: 20 ■□□□□□□□□□
    TechJunky wrote:
    why not use DHTML to accomplish this?

    because im still learning all of this stuff. Can DHTML give me a similar feature to the websit e i show u
  • TechJunkyTechJunky Member Posts: 881
    Yes, DHTML is vastly used. It can create rolling images, buttons etc. If you are decent with HTML DHTML isnt that much different. There is also free resources everyone with coding to help you acomplish what you want.
  • Mike_twMike_tw Member Posts: 20 ■□□□□□□□□□
    MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
    @mysql_select_db( "$dbName") or die( "Unable to select database");
    
    function secured($val)
     {
      $val = strip_tags(trim(($val))) ;
      $val = escapeshellcmd($val);
      return stripslashes($val);
      }
       if (get_magic_quotes_gpc()) 
       {
        $Manufacturer = $_POST['Manufacturer'];
       } 
        else
        {
        $Manufacturer = addslashes($_POST['Manufacturer']);
        }
        secured($Manufacturer);
    
    if ($Manufacturer != "SelectManufacturer") 
    {
    
    $query  = "SELECT * FROM bricks WHERE Manufacturer=".$Manufacturer;  $result = mysql_query($query);
     $num_rows = mysql_num_rows($result);
           if(!$num_rows)
            {
                echo "<table><tr><td align='center'>No data found 0 record returned</td></tr></table>";
             }
             else
                 {
                            echo "<table align='center'><tr>";
                            echo "<td align='center'>[b]Manufacturer[/b]</td>";
                            echo "<td align='center'>[b]Colour[/b]</td>";
                            echo "<td align='center'>[b]Texture[/b]</td>";
                            echo "<td align='center'>[b]Manufacturing Process[/b]</td>";
                            echo "</tr>";
                            
                            while($row = mysql_fetch_array($result, MYSQL_ASSOC))
                            echo "<tr><td align='center'>".$row["Manufacturer"]."</td>";
                            echo "<td align='center'>".$row["Colour"]."</td>";
                            echo "<td align='center'>".$row["Texture"]."</td>";
                            echo "<td align='center'>".$row["Manufacturing Process"]."</td>";
                             echo "</tr>";
    
                          }
                     echo "</table>";
          }
    ?>
    

    brings up Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/thetdco/public_html/brick/results.php on line 30
    No data found 0 record returned

    I dont see where the error is, can anyone ?
  • TechJunkyTechJunky Member Posts: 881
    $query = "SELECT * FROM bricks WHERE Manufacturer=".$Manufacturer; $result = mysql_query($query);
    $num_rows = mysql_num_rows($result);
    if(!$num_rows)
    {
    echo "<table><tr><td align='center'>No data found 0 record returned</td></tr></table>";
  • Mike_twMike_tw Member Posts: 20 ■□□□□□□□□□
    $query = "SELECT * FROM bricks WHERE Manufacturer=".$Manufacturer1; $result = mysql_query($query)OR DIE("DB connection unavailable");
    $num_rows = mysql_num_rows($result);


    I added an OR DIE part after it to check. It brings up connection unavailableicon_sad.gif

    What's wrong ?icon_sad.gif
Sign In or Register to comment.