anf.etienne Posted February 7, 2009 Share Posted February 7, 2009 I have a php form with that has four radio buttons. Depending on which radio button is submitted i want php to get information from my db. the ID of the buttons are 1,2,3 and 4.....they correspond to row 1,2,3 and 4 of my db how do i retieve rows 1 if button 1 is selected? Ive been through a lot of websites to find out but they dont explain retrieving a specific row Quote Link to comment https://forums.phpfreaks.com/topic/144209-mysql-php/ Share on other sites More sharing options...
haku Posted February 8, 2009 Share Posted February 8, 2009 At the end of your query, add: LIMIT X, 1 Change X to the number of the database row you want. How this works is that it starts at row X, and gives you 1 row. And remember, X will start at 0, so if you want the first row, you will set X=0, and if you want the second row, you will set X=1 etc. Quote Link to comment https://forums.phpfreaks.com/topic/144209-mysql-php/#findComment-757147 Share on other sites More sharing options...
landavia Posted February 8, 2009 Share Posted February 8, 2009 are u try to create ajax? >>how do i retieve rows 1 if button 1 is selected? cmiiw.. Quote Link to comment https://forums.phpfreaks.com/topic/144209-mysql-php/#findComment-757194 Share on other sites More sharing options...
anf.etienne Posted February 8, 2009 Author Share Posted February 8, 2009 no i don't want to create anything as complicated as that yet. I just want to create a php form where a user selects either options 1, 2, 3 or 4 and when they click continue the php will retrieve the either row with the corresponding ID. I've not done php & mysql for a loooong time and went more into graphic design and ive forgotten a lot of things lol so now im back to being a php swl newbie......the joy. thanks in advance for anyone that recaps me on this lol Quote Link to comment https://forums.phpfreaks.com/topic/144209-mysql-php/#findComment-757671 Share on other sites More sharing options...
ferozsho Posted February 9, 2009 Share Posted February 9, 2009 hi! try this...Hope its work for you. <?php define("HOST", "localhost"); // Database user define("DBUSER", "root"); // Database password define("PASS", "******"); // Database name define("DB", "Database_Name"); //Database_Name ############## Make the mysql connection ########### $conn = mysql_connect(HOST, DBUSER, PASS); if (!$conn){ // the connection failed so quit the script die('Could not connect !<br />Please contact the site\'s administrator.'); } $db = mysql_select_db(DB); if (!$db){ // cannot connect to the database so quit the script die('Could not connect to database !<br />Please contact the site\'s administrator.'); } ?> <form id="form1" name="form1" method="post" action="test.php"> <p> <label> <input type="radio" name="radio1" id="r1" value="1" <?=($_POST['radio1'])==1?'checked':''?> />1</label> <label> <input type="radio" name="radio1" id="r2" value="2" <?=($_POST['radio1'])==2?'checked':''?> />2</label> <label> <input type="radio" name="radio1" id="r3" value="3" <?=($_POST['radio1'])==3?'checked':''?> />3</label> <label> <input type="radio" name="radio1" id="r4" value="4" <?=($_POST['radio1'])==4?'checked':''?> />4</label> </p> <p> <input type="submit" value="Get Row" /> </p> </form> <? if($_POST){ $sql = "select user_id,name,email from sys_user where user_id='".$_POST['radio1']."';"; $res = mysql_query($sql); while ($row = mysql_fetch_array($res)){ echo $row[0].' - '.$row[1].' - '.$row[2]."<br>"; } mysql_free_result($res); mysql_close(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/144209-mysql-php/#findComment-757967 Share on other sites More sharing options...
anf.etienne Posted February 17, 2009 Author Share Posted February 17, 2009 THANK YOU FOR ALL THE HELP Quote Link to comment https://forums.phpfreaks.com/topic/144209-mysql-php/#findComment-764393 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.