Jump to content

Displaying values of database


javiqq

Recommended Posts

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???  ??? ??? ???

 

Link to comment
https://forums.phpfreaks.com/topic/130464-displaying-values-of-database/
Share on other sites

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";
}
?>

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 ;)

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>

 

 

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.

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";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.