How to dynamically create a PHP class name on the fly?

Php program. I need your help!?

  • So I am trying to create a dropdown list search to search my database in PHP and MySQL. But I dont like the result, here is the printscreen -->http://www.flickr.com/photos/xetness/6811407258/. When I click Search button on selected ID number, it displays all the records in my database. But I want to be able select an ID number and it displays only the information on selected ID number. I'm sorry I'm new in PHP and MySQL. Here is what I have so far: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Update Record</title> </head> <body> <table width="100%" border="0" cellpadding="0" cellspacing="5"> <form name="update category" method="GET" action="edit.php"> <tr> <td> </td> <td><strong>ID Number:</strong></td> </tr> <tr> <td> </td> <td > <?php include 'studentinfo_connect.php'; // Connect to server and select database. mysql_connect("$server", "$user", "$pass")or die("cannot connect"); mysql_select_db("$db")or die("cannot select DB"); $sql = mysql_query("SELECT ID FROM studentinfo_tbl ORDER BY ID"); $row = mysql_fetch_array($sql); ?> <select name="ID"> <?php do{ ?> <option value="<?php echo $row['ID']; ?>"><?php echo $row['ID']; ?> </option> <?php } while($row = mysql_fetch_array($sql));?> </select> </td> </tr> <tr> <td> </td> <td><input name="submit" type="submit" value="Search"></td> </tr> </table> <?php include('studentinfo_connect.php'); mysql_connect("$server", "$user", "$pass")or die("cannot connect"); mysql_select_db("$db")or die("cannot select DB"); //check if submit button was pressed if(isset($_GET['submit'])) { if (is_numeric($_GET['ID'])) { $ID = $_GET['ID']; // delete the entry $result = mysql_query("SELECT * FROM studentinfo_tbl") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { ?> <label>ID Number: </label><input type="text" name="ID" value="<?php echo $row['ID']; ?>"/> <label>First Name: </label><input type="text" name="FN" value="<?php echo $row['FirstName']; ?>"/> <label>Last Name: </label><input type="text" name="LN" value="<?php echo $row['LastName']; ?>"/> <label>Year: </label> <select name="Year" value="<?php echo $row['Year']; ?>"> <option value="1">First Year</option> <option value="2">Second Year</option> <option value="3">Third Year</option> <option value="4">Fourth Year</option> </select> <label>Course: </label> <select name="Course" value="<?php echo $row['Course']; ?>"> <option value="IT">BS Information Technology</option> <option value="HRM">BS Hotel and Restaurant Management</option> <option value="EDUC">BS Education</option> </select> <input type="submit" value="UPDATE" name="update"/> </form> </body> </html> <?php if($result) { echo("<br>Category Updated"); } else { echo("Failed to Update category"); } } } } ?> I Hope it made sense. I havent come across a solution for this yet and would appreciate any help. Thank you. :))

  • Answer:

    when you submit your form, you have to pass the value from drop down to your sql select so that it will filter it. to pass the value, you can use $_POST['valuefromform'] $result = mysql_query("SELECT * FROM studentinfo_tbl WHERE course = $_POST['Course'] ") haven't test it but it should select the student with the course selected

Kendall at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

its all in the SQL... well not all, but you need to select more than the ID. so SELECT * FROM tablename where ID = "id" or something like that

Neal

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.