lioslios Posted January 3, 2012 Share Posted January 3, 2012 hello guys im beginer with php sory for my simple and first step questions i have create a page that reads some data from an sql table and displays them, this works but i have some questions 1st the mysql_select_db($db)or die(mysql_error()); means if some error ocoure the connection will close or the entire web pages closes?? 2st is some way to create for each record a dynamic submit button with button text the name of the record? eg id name 1 george 2 nick 3 liana so to create 3 submit buttons with names george nick liana and when i press any button to make an acion thanks Quote Link to comment https://forums.phpfreaks.com/topic/254237-php-beginer/ Share on other sites More sharing options...
AyKay47 Posted January 3, 2012 Share Posted January 3, 2012 1. die 2. Why not use a <select> and populate it with you do data, have the user select from the list. Quote Link to comment https://forums.phpfreaks.com/topic/254237-php-beginer/#findComment-1303509 Share on other sites More sharing options...
jackr1909 Posted January 3, 2012 Share Posted January 3, 2012 with the submit buttons, add a value to each of them, so your form might be: <form action='action.php' method='POST'> <input type="text" name="text"> <input type="submit" name="name" value="george"> <input type="submit" name="name" value="nick"> <input type="submit" name="name" value="liana"> </form> and your php would look like <?php if($_POST['name'] == "george"){ //execute this code } if($_POST['name'] == "nick"){ //execute this code } if($_POST['name'] == "liana"){ //execute this code } ?> However, if you want the names to be dynamically gotten from the mysql database, you must customize the commands to take that into consideration, for example if you wanted to delete the row, you would have the following code <?php //add link data mysql_query("DELETE FROM users WHERE username = '$_POST['name']'"); echo "{$_POST['name']} deleted"; If you want to get the usernames for the submit buttons dynamically also, you will need something like this $result = mysql_query("SELECT * from users WHERE max(`id`)"); while($row = mysql_fetch_array($result)){ $max = $row['id']; } //start submit buttons if($max > 1) mysql_query("SELECT * FROM users WHERE id = '1'"); while($row = mysql_fetch_array($result)){ echo "<input type='submit' name='name' value='$row[username]'>"; $newvalue = 2 } //include this in another file and require it as many times as necessary if($max > $newvalue) mysql_query("SELECT * FROM users WHERE id = '$newvalue'"); while($row = mysql_fetch_array($result)){ echo "<input type='submit' name='name' value='$row[username]'>"; } $n = $newvalue; $newvalue = $n+1; //require this several times ?> Quote Link to comment https://forums.phpfreaks.com/topic/254237-php-beginer/#findComment-1303510 Share on other sites More sharing options...
AyKay47 Posted January 3, 2012 Share Posted January 3, 2012 Depending on the number of names you are expecting, having too many submit buttons is not practical. A select drop down would be more user friendly. Quote Link to comment https://forums.phpfreaks.com/topic/254237-php-beginer/#findComment-1303516 Share on other sites More sharing options...
lioslios Posted January 3, 2012 Author Share Posted January 3, 2012 yes AyKay47 you write about drop down but this web application i wand to acsses from my android acer iconia a500 so i beleve the submint buttons ar more easy with the touch screen, if you have in mind some other control exept buttons but touch screen frienly please tellme!!! in the beginig of the post i have ask about mysql_select_db($db)or die(mysql_error()); i say this because when i reload the page some times the browser closes-crashes but this happens only in iconia , in my desktop dont have this problem, so im thinking for data loss from wireless or iconia browser bug, if you have any idea for this please help me many many thanks Quote Link to comment https://forums.phpfreaks.com/topic/254237-php-beginer/#findComment-1303590 Share on other sites More sharing options...
scootstah Posted January 3, 2012 Share Posted January 3, 2012 Drop downs work perfectly fine on my Android phone. Quote Link to comment https://forums.phpfreaks.com/topic/254237-php-beginer/#findComment-1303593 Share on other sites More sharing options...
AyKay47 Posted January 3, 2012 Share Posted January 3, 2012 yes AyKay47 you write about drop down but this web application i wand to acsses from my android acer iconia a500 so i beleve the submint buttons ar more easy with the touch screen, if you have in mind some other control exept buttons but touch screen frienly please tellme!!! in the beginig of the post i have ask about mysql_select_db($db)or die(mysql_error()); i say this because when i reload the page some times the browser closes-crashes but this happens only in iconia , in my desktop dont have this problem, so im thinking for data loss from wireless or iconia browser bug, if you have any idea for this please help me many many thanks I posted a link to the die() function documentation, everything you need to know about the function is there. Drop downs work fine on mobile devices. Quote Link to comment https://forums.phpfreaks.com/topic/254237-php-beginer/#findComment-1303660 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.