javiqq Posted October 28, 2008 Share Posted October 28, 2008 I'm newbie to PHP and trying my best to learn on my own and take some courses online but currently I'm working on a website that stores information about students and their status. I need to create a link that goes to a PHP page with a script that generate the list of students with the ability to delete them if necessary. I've been trying to achieve this all morning by trying to first get the list generated but with no positive results. ??? ??? ???can anyone help?? This is the code I currently have (I don't even know if it's really doing what I'm aiming for): <?php $query = "SELECT re_first_name, re_last_name FROM rebels WHERE re_status_id_fk =3"; $result = mysql_query($query); if($_POST['list=1']){ while($re_first_name, $re_last_name) = $row = mysql_fetch_assoc($result) { echo "Name: ".$re_first_name, $re_last_name; } }else{ echo "The script isn't working properly"; } ?> The link to the page with the code above looks like this: a href="delete_graduate_students.php?list=1" Can anyone help please??? ??? ??? ??? Quote Link to comment Share on other sites More sharing options...
solon Posted October 28, 2008 Share Posted October 28, 2008 You should use something like: <?php $query = "SELECT re_first_name, re_last_name FROM rebels WHERE re_status_id_fk =3"; $result = mysql_query($query); if($_POST['list=1']) { while($row = mysql_fetch_assoc($result) { echo "Name: ".$row[re_first_name]." ". $row[re_last_name]." "; } } else{ echo "The script isn't working properly"; } ?> Quote Link to comment Share on other sites More sharing options...
javiqq Posted October 28, 2008 Author Share Posted October 28, 2008 Hey Solon, that worked nicely. Thanks! But after the list came up I noticed its too long. Is there a way I can have the names show up within a textarea field? Quote Link to comment Share on other sites More sharing options...
solon Posted October 29, 2008 Share Posted October 29, 2008 I think that something like the following should work(NOT TESTED): <?php $query = "SELECT re_first_name, re_last_name FROM rebels WHERE re_status_id_fk =3"; $result = mysql_query($query); if($_POST['list=1']) { echo "Names: "; echo"<textarea name='names' cols='' rows=''>"; while($row = mysql_fetch_assoc($result) { echo " ".$row[re_first_name]." ". $row[re_last_name]." "; } echo"</textarea>"; } else{ echo "The script isn't working properly"; } ?> Sorry for the delay Quote Link to comment Share on other sites More sharing options...
javiqq Posted October 29, 2008 Author Share Posted October 29, 2008 Solon don't worry about the delay. I appreciate the time you're taking to help me. Thank you very much. Unfortunately the code you posted didn't work. I tried the following but it didn't work either: :-\ <?php $query = "SELECT re_first_name, re_last_name FROM rebels WHERE re_status_id_fk =3"; $result = mysql_query($query); if($list=1){ while($row = mysql_fetch_assoc($result)) { echo " ".$row[re_first_name]." ". $row[re_last_name]." "; } }else{ echo "The script isn't working properly"; } ?> <form action="delete_selected_user.php" method="post" enctype="multipart/form-data"> <textarea cols="80" rows="7" name="list_rebels" wrap="virtual"><?php print $row[re_first_name]; print $row[re_last_name];?></textarea> <input type="submit" value="Delete selected users"> </form> Quote Link to comment Share on other sites More sharing options...
solon Posted October 29, 2008 Share Posted October 29, 2008 Ok let me understand something! What exactly do you want to do with the values that will show uo in the textarea? Quote Link to comment Share on other sites More sharing options...
javiqq Posted October 29, 2008 Author Share Posted October 29, 2008 Someone in the school will be incharge of deleting some, if not all, students that graduated highschool. The sql query and php script is bringing up the list of those graduates fine, however the list is way to long. To be efficient I'm trying to make that list populate inside a textarea field instead. Also the person incharge should have the ability to select from the list inside the textarea the student(s) they want to delete. Quote Link to comment Share on other sites More sharing options...
solon Posted October 29, 2008 Share Posted October 29, 2008 Ok then try this one it works on my computer. <?php $query = "SELECT re_first_name, re_last_name FROM rebels WHERE re_status_id_fk =3"; $result = mysql_query($query); if($list=1){ echo "Names: "; echo"<form action='' method='post'><select name='select'size='15' multiple"; while($row = mysql_fetch_assoc($result)) { echo" "; echo "<option value='{$row['re_last_name']}'>".{$row['re_last_name']}." " .{$row['re_first_name']}."</option></form>"; } echo "</select>"; } else{ echo "The script isn't working properly"; } ?> 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.