techker Posted October 13, 2008 Share Posted October 13, 2008 hey guys i got to the part were it populates my select box.but i need to echo what i select? <? // Connect database mysql_connect("localhost","techker_","o"); mysql_select_db("o_test"); ?> <select name="categoryID"> <? $sql = "SELECT name FROM authuser ". "ORDER BY name"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<option value=\"".$row['name']."\">".$row['name']."\n "; } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/ Share on other sites More sharing options...
Lamez Posted October 13, 2008 Share Posted October 13, 2008 you mean like it shows suggestions and you click on it, and it does not add it to the input box? If so look at Ajax or JS Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-664542 Share on other sites More sharing options...
techker Posted October 13, 2008 Author Share Posted October 13, 2008 i just need to retreive the user from my database Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-664544 Share on other sites More sharing options...
Lamez Posted October 14, 2008 Share Posted October 14, 2008 ah! <?php $username = "john_awesome68"; $q = mysql_query("SELECT * FROM `users` WHERE `username`='".$username."'") $r = mysql_fetch_array($q); echo $r['username']; ?> mess around with that! Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-664549 Share on other sites More sharing options...
techker Posted October 14, 2008 Author Share Posted October 14, 2008 its good but i need the part were it gets the select name? Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-664563 Share on other sites More sharing options...
grim1208 Posted October 14, 2008 Share Posted October 14, 2008 its good but i need the part were it gets the select name? You need to be more clear on what it is you are trying to do. a) are you trying to pass the variable from the page where you created the select box to the next page? b) user selects option then in a random spot populates what they selected (alert w/ js) or what? Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-664587 Share on other sites More sharing options...
techker Posted October 14, 2008 Author Share Posted October 14, 2008 in the select box it is populated with user name in my db.now i want to when i select a user it show his profile. Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-664589 Share on other sites More sharing options...
Lamez Posted October 14, 2008 Share Posted October 14, 2008 would a IF statement do the job? Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-664592 Share on other sites More sharing options...
techker Posted October 14, 2008 Author Share Posted October 14, 2008 i guess?but where i bug is how would i do it so it can get the selected user Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-664593 Share on other sites More sharing options...
CroNiX Posted October 14, 2008 Share Posted October 14, 2008 Well, your select isn't in a form (that I can see from the code you posted) and you need a submit button. Then the person selects the username and clicks submit to send it somewhere for processing. During that processing you select the user info from the db. <form name="myform" action="<?php echo $_SERVER['php_self']; ?>" method="post"> <?php // Connect database mysql_connect("localhost","techker_","o"); mysql_select_db("o_test"); $username = isset($_POST['categoryID']) ? mysql_real_escape_string($_POST['categoryID']) : ""; ?> <select name="categoryID"> <?php $sql = "SELECT name FROM authuser ". "ORDER BY name"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<option value=\"".$row['name']."\">".$row['name']."\n "; } ?> </select> <input type="submit" /> </form> <?php if(!empty($username)) { $q = mysql_query("SELECT * FROM `users` WHERE `username`='".$username."'") $r = mysql_fetch_array($q); echo $r['username']; //rest of your user data.... } ?> Didn't test it but hopefully you can see whats going on... Also, if you are selecting the username, Im not sure why you are calling it categoryID in this line: <select name="categoryID"> Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-664600 Share on other sites More sharing options...
techker Posted October 14, 2008 Author Share Posted October 14, 2008 hey thanks dude i just got to debug it..the select box part works fine but the las part <?php if(!empty($username)) { $q = mysql_query("SELECT * FROM `authuser` WHERE `username`='".$username."'") $r = mysql_fetch_array($q); echo $r['username']; //rest of your user data.... } ?> gives me errors Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-664908 Share on other sites More sharing options...
Lamez Posted October 14, 2008 Share Posted October 14, 2008 if the topic is solved then press the Topic Solved button Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-664977 Share on other sites More sharing options...
techker Posted October 14, 2008 Author Share Posted October 14, 2008 not really its not working .. Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-664979 Share on other sites More sharing options...
grim1208 Posted October 14, 2008 Share Posted October 14, 2008 <?php if(!empty($username)) { $q = mysql_query("SELECT * FROM `authuser` WHERE `username`='".$username."'") $r = mysql_fetch_array($q); echo $r['username']; //rest of your user data.... } ?> why would you want to echo $r['username'] from the db when you already have the usersname from you select box ('categoryID')? Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-665002 Share on other sites More sharing options...
grim1208 Posted October 14, 2008 Share Posted October 14, 2008 not sure if this will help, but if you want to see the value you are getting from the select box put in a javascript function & call like this: <form name="myform" action="<?php echo $_SERVER['php_self']; ?>" method="post"> <?php // Connect database mysql_connect("localhost","techker_","o"); mysql_select_db("o_test"); $username = isset($_POST['categoryID']) ? mysql_real_escape_string($_POST['categoryID']) : ""; ?> <select name="categoryID" id="categoryID" onChange="testSelect();"> <?php $sql = "SELECT name FROM authuser ". "ORDER BY name"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<option value=\"".$row['name']."\">".$row['name']."\n "; } ?> </select> <input type="submit" /> </form> <script> function testSelect() { alert(document.getElementById('categoryID').value); } </script> Notice I added id="categoryID" to you select and onChange="testSelect();" I use js to help debug a lot to make sure I am getting the output I want Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-665017 Share on other sites More sharing options...
techker Posted October 14, 2008 Author Share Posted October 14, 2008 it works a pop up apears and show the user i select. but what i need is to grab the user selected profile in my database. Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-665023 Share on other sites More sharing options...
CroNiX Posted October 14, 2008 Share Posted October 14, 2008 So adjust your query and do something like you did at the top of your code using a where statement. Are you trying to get us to do it all for you? Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-665037 Share on other sites More sharing options...
techker Posted October 14, 2008 Author Share Posted October 14, 2008 lol im just asking for help.cause i freez on that part.thx Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-665076 Share on other sites More sharing options...
grim1208 Posted October 14, 2008 Share Posted October 14, 2008 GOOGLE is your best friend Quote Link to comment https://forums.phpfreaks.com/topic/128291-select-box-help/#findComment-665221 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.