hi i have some data in mysql db and i need to create a page where i have a dropdown down box with different categories. when a user select a category from a the drop down it will show data form the mysql table from that category.

so how can i do that but i need as soon as they select the drop down the result is loaded and doesnt have to load result on another page.

thanks

ok i managed to do it but the only problem i geteing now is display a pdf that i stored its file name in mysql and the file on a folder on the server.

i want the pdf file to show allong with my other result and if the click on it they can download it. can anyone help me with that?

Member Avatar for diafol

Perhaps if you showed your code?

// check if form has been submitted:
if(isset($_GET['submit'])) {

    // establish a DB connection (assuming mysql)
    ...

    // check if the appropriate category has been selected
    // and escape it
    $category = mysql_real_escape_string($_GET['category'])

    // construct the query
    $q = "SELECT * FROM theTable WHERE category='$category'";

    // get the result
    ...

    // do whatever else is neccessary (handle errors, redirect?)
    ...
}

// put the html here including the form code
// decide what the action is (GET in this example)

To make form autosubmit google for form autosubmit. This is one link.

OK, while typing the answer to your post, your question changed, so never mind my post above.

maybe and <iframe> such as:

<html>
  <head>
    <script language="JavaScript" type="text/javascript">
    <!--
      function changeFrame(newPage){
        document.getElementById('myframe').src = "results.php?category=" + newPage;
      }
    //-->
    </script>
  </head>
  <body>
    <div align="center">
      <select id="menu">
        <option id="category1" onClick="changeFrame(this.id)">Home</option>
        <option id="category2" onClick="changeFrame(this.id)">About</option>
        <option id="category3" onClick="changeFrame(this.id)">Contact</option>
      </span>
      <br><br>
      <iframe src="default.html" id="myframe"></iframe>
    </div>
  </body>
</html>

ok so here is my code to display the data.where its displaying the file i want it to display the acctual pdf file not just the name

<html>
<header>
<link rel="stylesheet" type="text/css" href="style.css">
</header>

<body>

<form name="filter" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">

<select name="catselect">
<option value="engineering">Engineering</option> 
<option value="law">Law</option> 
<option value="audit">Audit</option> 
<option value="marine time">Marine Time</option> 
</select>

<input type="Submit" value="search" name="search">
</form>


<?php
mysql_connect("localhost","xxxxx","xxxxxx");//database connection
mysql_select_db("xxxxxxxx");


if (isset($_POST["catselect"])) { 
$cat = mysql_real_escape_string ($_POST["catselect"]); 
$Query = "SELECT * FROM data WHERE apptype='$cat'"; 





//RUN THE QUERY
$result = mysql_query($Query) or die (mysql_error());
echo "<table cellpadding=10 border=1>"; 
while ($row = mysql_fetch_array($result)) {
echo "<tr>"; 
 echo "<td>" . $row['name']."</td>"; 
 echo "<td >" . $row['email']."</td>"; 
 echo "<td >" . $row['apptype']."</td>"; 
 echo "<td >" . $row['description']."</td>"; 
 echo "<td >" . $row['file']."</td>"; 
echo "</tr>"; 

}
echo "</table>";
}

?>

<body>

</html>

and here is my code i use to insert the data into the data base

<?

//the example of inserting data with variable from HTML form
//input.php
mysql_connect("localhost","xxxxx","xxxxxxx");//database connection
mysql_select_db("xxxxxxx");

 //This is the directory where images will be saved 

 $target = "upload/".basename($_FILES['pdffile']['name']) ;


$name=$_POST['name'];
$email=$_POST['email'];
$apptype=$_POST['apptype'];
$description=$_POST['description'];
$pdf=($_FILES['pdffile']['name']); 


//inserting data order
$apply = "INSERT INTO data
            (name, email, apptype, description, file)
            VALUES
            ('$name','$email','$apptype','$description','$pdf')";

            //Writes the pdf to the server 
 if(move_uploaded_file($_FILES['pdffile']['tmp_name'], $target)) 
 { 

 //Tells you if its all ok 
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
 } 
 else { 

 //Gives and error if its not 
 echo "Sorry, there was a problem uploading your file."; 
 } 


?>

i dont want the user to view the pdf.i want that when the form return the result it has the pdf name displayed with the pdf icon.if the click on it the i gets download on thier pc.

all im getting now is just the name of the pdf showing as text its not linking to the file on the server.

i dont know if i should have store the pdf path in mysql insted of the pdf name

You construct links to files when displaying the table.

// path to pdf files (including backslash/slash)
$path = 'whatever/';

// the icon
$icon = '<img src="pathtotheicon" alt="PDF File">';

while ($row = mysql_fetch_array($result)) {

    $file = $row['file'];

    echo "<tr>";
    echo "<td>" . $row['name']."</td>";
    echo "<td >" . $row['email']."</td>";
    echo "<td >" . $row['apptype']."</td>";
    echo "<td >" . $row['description']."</td>";
    echo "<td >$icon <a href=\"$path{$file}\">" . $file . "</a></td>";
    echo "</tr>";
}

By clicking a link the user will be able to download (or open) the file.

Member Avatar for diafol

i dont want the user to view the pdf.i want that when the form return the result it has the pdf name displayed with the pdf icon.if the click on it the i gets download on thier pc

Please explain yourself better, as you stated:

i want it to display the acctual pdf file not just the name

broj1 you are the best it work like a charm man. that was my problem coundt figure out how to inclued the path to it.

thanks a million

diafol im sorry i didnt explain my self clearly. but thank all for the great help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.