rahul_puri20 Posted February 19, 2005 Posted February 19, 2005 Hi,I need some help. i have a page with a list box containing id. when i choose a id i have to show the info belongs to the id in the same page. the info are in the database with the id. I m using php and javascriptI think u understand the prob, if not, inform me.Thanks
Stalkie Posted February 25, 2005 Posted February 25, 2005 HiYou can try something like this. Now remember this is only a quick sketch to get you on the right track.<html-code-design><?// Connect to the databasemysql_connect('server', 'username', 'password');mysql_select_db('database');// Only when the form is submitted and id is number onlyif ($_SERVER['REQUEST_METHOD'] == 'POST' && preg_match('^[0-9]+$', $_POST['infoID']){ $result = mysql_query('SELECT infoTitle, infoText FROM infos WHERE infoID=$_POST['infoID'] LIMIT 1'); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); echo '<b>'.$row['infoTitle'].'</b><br />'; echo $row['infoText']; } else { echo 'Unknown ID'; }}?><form name="infoForm" action="" method="post"> <select name="infoID" size="1"> <? $result = mysql_query('SELECT infoID, infoTitle FROM infos ORDER BY infoTitle'); while ($row = mysql_fetch_assoc($result)) { echo '<option value="'.$row['infoID'].'">'.$row['infoTitle'].'</option>'; } ?> </select></form><?// Closes the databasemysql_close();?>I hope i've understood it correctly
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now