Adam77 Posted February 23, 2014 Share Posted February 23, 2014 hey guys please help me out here ! i did a time line which people fill their place in line with radio button ., now i want to make the radio button that already been picked to be disable for everyone else so it cant be picked twice . i have an sql database where i put(by php) the submitted picking. will appreciate any help !!! Adam Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 23, 2014 Share Posted February 23, 2014 (edited) uhhh - need a bit more direction here. When you say 'timeline' I envision a line on the page. Or a list of times. What is the granularity of this timeline? And how many radio buttons do you have to associate with this timeline? Removing a button s/b no problem. Simply create a session array var and make entries for each button value you output. When one is picked, tag that array element as used and then regenerate your button elements, disabling any that has already been picked, as indicated by the session array. Edited February 23, 2014 by ginerjm Quote Link to comment Share on other sites More sharing options...
Adam77 Posted February 23, 2014 Author Share Posted February 23, 2014 hey man, look i have a list of radio buttons as you said, im kind of new to this, what do you mean by session array ? if you can show me a little example .. this is my html form <form id= "line" name="line " action="index.php" method="post"> <input type="hidden" name="submitted" value="true"/> <ul> <li><input type="radio" name="placeInLine" id="choice3" value="3" onclick="toggle('show')"/>10:30-10:45</li> <li><input type="radio" name="placeInLine" id="choice4" value="4" onclick="toggle('show')"/>10:45-11:00</li> <li><input type="radio" name="placeInLine" id="choice5" value="5" onclick="toggle('show')"/>11:00-11:15</li> <li><input type="radio" name="placeInLine" id="choice6" value="6" onclick="toggle('show')"/>11:15-11:30</li> <li><input type="radio" name="placeInLine" id="choice7" value="7" onclick="toggle('show')"/>11:30-11:45</li> <li><input type="radio" name="placeInLine" id="choice8" value="8" onclick="toggle('show')"/>11:45-12:00</li> <br /> <input type="submit" value="Save my choice" class="button" /> </ul> </form> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 23, 2014 Share Posted February 23, 2014 Have you read any PHP resources? Quote Link to comment Share on other sites More sharing options...
Adam77 Posted February 23, 2014 Author Share Posted February 23, 2014 i read quickstart edition, i guess its not enogh but if you could still explain me the way i do that.. the array should look like that, but how do i add it to the specific button ,? $ch[1] = 'disabled'; $ch[2] = ''; $ch[3] = ''; $ch[4] = ' Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 23, 2014 Share Posted February 23, 2014 In your php code that outputs the radios, use a loop to output each one using a var to set the value clause of the button and to set an array value like this: $no_btns = 10; // how many buttons to output for ($I=1;$I<=$no_btns; $I++) { $val = 'radio'.$i; $disab = ''; if ( isset($_SESSION[$val]) && $_SESSION[$val) == "X") $disab = 'disabled'; // echo "<li><input type='radio' name='placeInLine' id='choice$i $disab value='$i' onclick="toggle('show')"/>11:15-11:30</li>"; } When your script retrieves the input from the client and determines the radio button that was selected, you set that session value as in if ($_POST['placeInLine'] <> ''){ $val = 'radio' . $_POST['placeInLine']; $_SESSION[$val] = "X";} Of course you need to validate the incoming post values before doing this. Quote Link to comment Share on other sites More sharing options...
Adam77 Posted February 25, 2014 Author Share Posted February 25, 2014 hey man, i was trying to make it a bit more simple but i have a syntax problem i cant solve , do you mind take a look ? <title>hairdresser</title> <?php include("connect.php"); ini_set('display_errors', 'Off'); if(isset($_POST['submitted'])){ $choice = $_POST['placeInLine']; $query = "SELECT `choice` FROM `placeinline`"; $result = mysql_query($query ); if($query_run = mysql_query($query) ){ echo 'good'; }else{ echo mysql_error(); } $disab = '' ; $row = mysql_fetch_row($result); if($choice==$row){ $disab = 'disabled'; } <form id= "line" name="line " action="test1.php" method="post"> echo "<li> <input type='radio' name='placeInLine' id='choice1' $disab value='1' /> 10:00-10:15 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice2' $disab value='2' /> 10:15-10:30 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice3' $disab value='3' /> 10:30-10:45 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice4' $disab value='4' /> 10:45-11:00 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice5' $disab value='5' /> 11:00-11:15 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice6' $disab value='6' /> 11:15-11:30 </li>"; </form> mysql_query("INSERT INTO $table(choice) VALUES ($choice)") or die(mysql_error()); $sqlinsert = "INSERT INTO placeinline (choice) VALUES ($choice)"; $newrecord = "1 choice added to the line"; echo $newrecord; } ?> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 25, 2014 Share Posted February 25, 2014 Where is the syntax error?? (Hint: if you turn display_errors back on, you will get a line number from PHP) Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 25, 2014 Share Posted February 25, 2014 Ps - looking at this code I get the impression that you don't know any php. Your coding skills and syntax errors are incredibly elementary. 1 - you are running the query twice - why? 2 - you are comparing a result row against the value of the radio button. Do you have any idea how impossibly wrong that is? 3 - you make reference to something called "$table(choice)" in your query statement. What is that supposed to be? 4 - you run the first insert query with nothing to capture the results. 5 - you create a query statement after #4 but you never run it Lastly you begin by running a query and capturing the results but you never use it. Plus I don't know what its relevance to the rest of the code is. Quote Link to comment Share on other sites More sharing options...
Adam77 Posted February 26, 2014 Author Share Posted February 26, 2014 got you .. ill study more of php Quote Link to comment Share on other sites More sharing options...
Adam77 Posted March 13, 2014 Author Share Posted March 13, 2014 hey guys, i managed to do i needed thank you all !! now i need to put the form i created in my html page and i have a problem with that .. i want to put the form in a div section . i added the php code ( test) <?php // include("connect.php"); $db_host = "localhost"; $db_username = "root"; $db_pass = "test123"; $db_name = "test_database"; $table="placeinline"; $dbcon = mysqli_connect("$db_host","$db_username","$db_pass", "$db_name" ) or die("could not connect to mysql"); @mysql_select_db("$db_name") or die ("no database"); //echo "successful Connection"; for($k=1; $k<=12;$k++){ $query= "SELECT * FROM placeinline WHERE choice = $k "; $result= mysql_query($query); if(mysql_fetch_array($result)){ switch($k) { case 1: $disab1= "disabled"; break; case 2: $disab2= "disabled"; break; case 3: $disab3= "disabled"; break; case 4: $disab4= "disabled"; break; case 5: $disab5= "disabled"; break; case 6: $disab= "disabled"; break; case 7: $disab7= "disabled"; break; case 8: $disab8= "disabled"; break; case 9: $disab9= "disabled"; break; case 10: $disab10= "disabled"; break; case 11: $disab11= "disabled"; break; case 12: $disab12= "disabled"; break; } } } echo '<form action="test.php" method="POST">'; echo '<input type="date" id= "linedate"><br/>'; echo "<li> <input type='radio' name='placeInLine' id='choice1' $disab1 value= '1' /> 10:00-10:15 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice2' $disab2 value= '2' /> 10:15-10:30 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice3' $disab3 value= '3' /> 10:30-10:45 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice4' $disab4 value= '4' /> 10:45-11:00 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice5' $disab5 value= '5' /> 11:00-11:15 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice6' $disab6 value= '6' /> 11:15-11:30 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice7' $disab7 value= '7' /> 11:30-11:45 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice8' $disab8 value= '8' /> 11:45-12:00 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice9' $disab9 value= '9' /> 12:00-12:15 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice10' $disab10 value= '10'/> 12:15-12:30 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice11' $disab11 value= '11'/> 12:30-12:45 </li>"; echo "<li> <input type='radio' name='placeInLine' id='choice12' $disab12 value= '12'/> 12:45-13:00 </li>"; echo '<input type="submit" value="Submit">'; echo "</form>"; $choice = $_POST['placeInLine']; echo $choice; $sqlinsert = "INSERT INTO placeinline (choice) VALUES ('$choice') "; if(!mysqli_query($dbcon,$sqlinsert)){ die('error insertin'); } $newrecord = " 1 choice added to the line"; echo $newrecord; ?> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 13, 2014 Share Posted March 13, 2014 You haven't learned much since your last post. So much wrong with your code. and your coding. 1 - you should not be doing a query inside of a loop. Look up the syntax for "where field in (....)" used in queries. 2 - you have to store the fetch'ed row into something, otherwise why do the fetch at all? It's like going to the well without a bucket. 3 - nice try to capture data from multiple rows by using the same name= value, but how do you recognize which row the input comes from? You probably want to use the format "name='placeinline[]' which will create an array of values in the POST array. You have a lot of catching up to do. Suggestion? Stop using upper- & lowercase in your var names. It's going to catch up to you one day. One mis-typed char and you're going to be searching for an error for a long time. Quote Link to comment Share on other sites More sharing options...
Adam77 Posted March 13, 2014 Author Share Posted March 13, 2014 im trying not to take you personally, but can you offer me some substitute solution because somehow the code is working so why is it a problem ? Quote Link to comment Share on other sites More sharing options...
Adam77 Posted March 13, 2014 Author Share Posted March 13, 2014 according to the fetch row, if the fetch do set the switch excute, otherwise it dont . Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 13, 2014 Share Posted March 13, 2014 If you're happy, I'm happy. Quote Link to comment Share on other sites More sharing options...
Adam77 Posted March 13, 2014 Author Share Posted March 13, 2014 THANKS BRAVE MAN Quote Link to comment 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.