Jump to content

view/update data already in the database


frankoj

Recommended Posts

I have a page that lists the available records in the database and has links that allow one to view details, edit existing details and delete the data. when i click the view details link, i dont get the correct details for the person but for another person in the database . the link to edit existing details is also not working. following is my code. help!!!!

 

//list available records

<?
$CONTENT="
<form name=\"form1\" method=\"post\" action=\"\">
  <table width=\"100%\" border=\"0\">
    <tr>
      <td width=\"19%\" align=\"right\"><font size='-1px'>Search for  :  </font></td>
      <td width=\"61%\" colspan=\"2\"><label>
        <select name=\"select\" id=\"select\">
          <option value=\"std\">Student Name</option>
          <option value=\"class\">Class Name</option>
          <option value=\"std_id\">Student ID</option>
        </select>
      </label>
        <label>
        <input type=\"text\" name=\"textfield\" id=\"textfield\">
        <input type=\"submit\" name=\"button\" id=\"button\" value=\"Submit\">
      </label></td>
      <td width=\"10%\"> </td>
    </tr>
  </table>
  <table width=\"100%\" border=\"0\">
    <tr bgcolor=\"#666666\">
      <td align=\"center\"> </td>
      <td align=\"center\"> </td>
      <td colspan=\"2\" align=\"center\"><font size='-1px'>Pages x of xn</font></td>
      <td align=\"center\"> </td>
      <td align=\"center\"> </td>
      <td align=\"center\"> </td>
      <td colspan=\"3\" align=\"center\"> </td>
    </tr>
    <tr bgcolor=\"#999999\">
      <td align=\"center\" width='2%'> </td>
      <td align=\"center\" width='2%'><font size='-1px'>#</font></td>
      <td align=\"center\" width='11%'><font size='-1px'>Class</font></td>
      <td align=\"center\" width='23%'><font size='-1px'>Names</font></td>
      <td align=\"center\" width='13%'><font size='-1px'>Fees Status</font></td>
      <td align=\"center\" width='21%'><font size='-1px'>Guardian</font></td>
      <td align=\"center\" width='18%'><font size='-1px'>Teacher</font></td>
      <td colspan=\"3\" align=\"center\"> </td>
    </tr>";
/*$query = "SELECT * FROM `student`, `payment`, `class`, `parent_details`, `teacher` WHERE `payment`.`student_id`=`student`.`student_id` and 
		`student`.`class_id` = `class`.`class_id` and `student`.`guardian_id`=`parent_details`.`parent_id` and 
		`teacher`.`class_id` = `class`.`class_id`";*/
//$student_id = $_GET['std_id'];
/* $query= "SELECT `student`.`student_id` FROM `student` 
FULL JOIN `payment` ON `student`.`student_id` = `payment`.`student_id`
ORDER BY `student`.`student_id`";*/
$query = "select * from `student`, `payment`, `class`, `parent_details`, `teacher` where payment.student_id = student.student_id and student.class_id = class.class_id and student.guardian_id = parent_details.parent_id";
$result = mysql_query($query);
//$numstudents = mysql_num_rows($result);
$count=1;
//if($count = 0; $count<=$num_students; $count++)
//{
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{	

	$CONTENT.="<tr bgcolor=\"#CCFFFF\">
	  <td><label>
		<input type=\"checkbox\" name=\"checkbox\" id=\"checkbox\">
	  </label></td>
	  <td><font size='-1px'>".$count."</font></td>
	  <td><font size='-1px'>".$row["class_name"]."</font></td>
	  <td><font size='-1px'>".$row["first_name"]." ".$row["last_name"]."</font></td>
	  <td><font size='-1px'>".$row["amount"]."</font></td>
	  <td><font size='-1px'>".$row["fname"]."</font></td>
	  <td><font size='-1px'>".$row["tr_name"]."</font></td>		
	  <td width=\"2%\"><a href=\"student_details.php?std_id=".$row["student_id"]."\"><img src=\"images/b_browse.png\"  height=\"12\" alt=\"Details\"></a></td>
	  <td width=\"2%\"><a href=\"student_edit.php?action=edit&std_id=".$row["student_id"]."\"><img src=\"images/b_edit.png\"  height=\"12\" alt=\"Edit\"></a></td>
	  <td width=\"2%\"><a href=\"student_edit.php?action=del&std_id=".$row["student_id"]."\"><img src=\"images/b_drop.png\" height=\"12\" alt=\"Delete\"></a></td>
	</tr>
	";
			  $count++;
}
  $CONTENT.="</table>
</form>";
?>	
//view details
<?

$query = "SELECT * FROM `student`, `academic_background`, `class` WHERE `academic_background`.`student_id`=`student`.`student_id` ";
//and `student`.`class_id` = `class`.`class_id`";
//`academic_background`.`student_id`=`student`.`student_id` and `student`.`class_id` = `class`.`class_id`";
$result = mysql_query($query);
//$count = 0;
//$num_students = mysql_num_rows($result);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{	
//$student_id = $_GET['std_id'];
//$bg_id = $_GET['bg_id'];

$CONTENT="
<form> 
<table width=\"100%\" border=\"0\">
  <tr>
    <td width=\"38%\"><img src=\"images/images1.jpg\" /></td>
    <td width=\"62%\"></td>
  </tr>
  <tr>
    <td><font size='+2px'>Student ID:</font></td>
    <td><font size='+2px'>".$row["student_id"]."</font></td>
  </tr>
  <tr>
    <td><font size='+2px'>Student Name:</font></td>
    <td><font size='+2px'>".$row["first_name"]." ".$row["last_name"]."</font></td>
  </tr>
  <tr>
    <td><font size='+2px'>Date of Birth:</font></td>
    <td><font size='+2px'>".$row["dob"]."</font></td>
  </tr>
  <tr>
    <td><font size='+2px'>Current Class:</font></td>
    <td><font size='+2px'>".$row["class_name"]."</font></td>
  </tr>
  <tr>
    <td><font size='+2px'>Primary School:</font></td>
    <td><font size='+2px'>".$row["pschool"]."</font></td>
  </tr>
  <tr>
    <td><font size='+2px'>K.C.P.E Marks:</font></td>
    <td><font size='+2px'>".$row["total_marks"]."</font></td>
  </tr>

</table>
</form>	
";
//	$count += 1;
}
?>
edit details
<?
if($_GET['action']=="edit")
{
$std_id = $_GET['std_id'];

$query= "SELECT * FROM `mackenzie`.`student` WHERE std_id = '$student_id'"; 
$result= mysql_query($query);

//assign student info to variablea
list($student_id, $first_name,$last_name,$date_of_birth,$class_id,$picture,$home,$guardian_id) = mysql_fetch_array($result, MYSQL_ASSOC);

include("/modify.php");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/222900-viewupdate-data-already-in-the-database/
Share on other sites

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.