Msaada wa programing (php &mysql)

Ramso11

Member
Jun 5, 2011
62
22
Naomba msaada wa kupost matokeo ya Wanafunzi kama inavyoonekana hapo chini katika jedwali, stream ,sid ,student name nimevyitoa katika registration table. ambapo natakiwa niwajazie matokeo kisha nivitume katika somo husika baada ya kuclick save.


NUMBERFORMSTREAMSIDSTUDENT NAMETEST 1TEST 2MID TERMTERMINAL
1IA122Anna J Mollel
2IA333Juma H Hassan
3IA1222asmin a john
4IA5555Peter H Kelvin
 
Naomba msaada wa kupost matokeo ya Wanafunzi kama inavyoonekana hapo chini katika jedwali, stream ,sid ,student name nimevyitoa katika registration table. ambapo natakiwa niwajazie matokeo kisha nivitume katika somo husika baada ya kuclick save.


Yaani kwa lugha nyingine unataka tukuandikie code?
Wewe kwa nini usikae ukajaribu kitu kwanza kabla ya kuja huku alafu ukatuambia umeshindwa wapi ndio tukusaidie.
 
Nimejaribu kuandika lakini inatuma ya mwisho tu peke yake. Na bado naendelea kutafuta utatuzi zaidi sio kwamba nimebakia hapo hapo
 
Nimejaribu kuandika lakini inatuma ya mwisho tu peke yake. Na bado naendelea kutafuta utatuzi zaidi sio kwamba nimebakia hapo hapo
Kua realistic,Tuma codes,eleza tatizo watu watakusaidia,,mtu hawezi kukusaidia kwa staili hiyo utakayo,otherwise unataka msaada from the beginning.
 
page 1 : exams1
<?php
session_start();
include('conn.php');
isset($_POST['submit']);
$form = $_POST['form'];
$strm = $_POST['stream'];
$subject = $_POST['subject'];
$year = date('Y');
$month = date('m');
$date =date('d/m/Y');


if($month <7){
echo $term =1;
}else {
$term=2;
}
?>
<table border="1" align="center">
<form action="exam2.php" method="POST">
<th>NUMBER</th>
<th>FORM</th>
<th>STREAM</th>
<th>SID</th>
<th>STUDENT NAME</th>
<th>TEST 1 </th>
<th>TEST 2</th>
<th>MID TERM</th>
<th>TERMINAL </th>
<?php


$qry = "SELECT sid, fname, mname ,form ,sname, stream FROM reg WHERE form = '$form' AND stream = '$strm'";
$sql = mysqli_query($conn,$qry);
$i=1 ;
while($row = mysqli_fetch_array($sql)) {
$sid = $row['sid'];
$frm = $row['form'];
$str = $row['stream'];
$fname = $row['fname'];
$mname = $row['mname'];
$sname = $row['sname'];
?>
<tr>
<td><?php echo $i; ?></td>
<td align="center"><?php echo $frm; ?></td>
<td align="center"><?php echo $str; ?></td>
<td><?php echo $sid; ?></td>
<td><?php echo $fname ." ". $mname." ".$sname; ?></td>
<td><input type="number" name ="test1" size="3"></td>
<td><input type="number" name ="test2" size="3"></td>
<td><input type="number" name ="test3" size="3"></td>
<td><input type="number" name ="test4" size="3"></td>
</tr></br>
<?php

$_SESSION['sid'] = $sid;
$i++;
}
?>
<td><input type="submit" name ="submit" value="save"></td>
</form>
</table>
<?php
$i= $i -1;
$_SESSION['form'] = $form ;
$_SESSION['stream'] = $strm;
$_SESSION['subject'] = $subject;
$_SESSION['$i'] = $i;

?>

from nataka kuondoka na sid zote kwa njia ya array na session kwa ajili ya kuipost page 2

exams2
<?php
include('conn.php');
session_start();
$form = $_SESSION['form'];
$strm = $_SESSION['stream'] ;
$sid = $_SESSION['sid'] ;
$subject = $_SESSION['subject'] ;
$i = $_SESSION['$i'] ;
$year = date('Y');
$month = date('m');
$date =date('d/m/Y');

if($month <7){
echo $term =1;
}else {
$term=2;
}
isset($_POST['submit']);
$test1 = $_POST['test1'];
$test2 = $_POST['test2'];
$test3 = $_POST['test3'];
$test4 = $_POST['test4'];
for( $row= 0 ; $row < $i ; $row++)
echo $test1;
echo $sid;
{
//insert marks into database acccording to sid and subject and exams type
$query=mysqli_query( $conn, "INSERT INTO `school`.`bio`
(`eid`, `sid`, `cl`, `str`, `yr`, `date`, `tm`, `extype`, `test1`, `test2`, `test3`, `test4`)
VALUES
(NULL, '$sid', '$form', '$strm', '$year', '$date', '$term', '$subject', '$test1', '$test2', '$test3', '$test4')");
}

?>
na hapo nafikiria kuchukua sid ,test1 ,tes2 ,test3 na test 4 zote kwa multidemensional array
kila nikijaribu inagoma na inachukua ya mwish peke yake.
naombeni msaada bado nitumie jia ipi,
 
You have not declared the multi array anywhere. Your exam2 will definitely take the last values that you entered. Worse still Your exam2 script does not show any looping. I would suggest that you create the multi array that you will save the values that you enter and your exam2 script must must include a loop. Alternatively, why not create a temporary table to which you will add the Sid and tests at the bottom of the while loop. After that read the values from the temporary table to populate the the school table and at end delete the temporary table values
 
thanks for your Idea but:
the first problem I face is how to move with sid for those students from exam1 to exam2 page. I tried by multi array in session but bring error, and when I printoff sid in while loop it give all sid , but after while gives the last only.
 
katika exams1 nimejaribu kuprint result chini ila tatizo kuba nimwgundua nimeshindwa jinsi ya kuweka data katika array, maana za juu zimekubali kutoa line zote ila chini inarudia ya mwisho tu,
<?php
session_start();
include('conn.php');
isset($_POST['submit']);
$form = $_POST['form'];
$strm = $_POST['stream'];
$subject = $_POST['subject'];
$year = date('Y');
$month = date('m');
$date =date('d/m/Y');


if($month <7){
echo $term =1;
}else {
$term=2;
}
?>
<table border="1" align="center">
<form action="exam2.php" method="POST">
<th>NUMBER</th>
<th>FORM</th>
<th>STREAM</th>
<th>SID</th>
<th>STUDENT NAME</th>
<th>TEST 1 </th>
<th>TEST 2</th>
<th>MID TERM</th>
<th>TERMINAL </th>
<?php


$qry = "SELECT sid, fname, mname ,form ,sname, stream FROM reg WHERE form = '$form' AND stream = '$strm'";
$sql = mysqli_query($conn,$qry);
$i=1 ;
while($row = mysqli_fetch_array($sql)) {
$sid = $row['sid'];
$frm = $row['form'];
$str = $row['stream'];
$fname = $row['fname'];
$mname = $row['mname'];
$sname = $row['sname'];
?>
<tr>
<td><?php echo $i; ?></td>
<td align="center"><?php echo $frm; ?></td>
<td align="center"><?php echo $str; ?></td>
<td><?php echo $sid; ?></td>
<td><?php echo $fname ." ". $mname." ".$sname; ?></td>
<td><input type="number" name ="test1[$i]" size="3"></td>
<td><input type="number" name ="test2[$i]" size="3"></td>
<td><input type="number" name ="test3[$i]" size="3"></td>
<td><input type="number" name ="test4[$i]" size="3"></td>
</tr></br>
<?php

$_SESSION['sid'] = $sid;
echo $sid . " , " . "test1[$i]" ." , ". "test2[$i] ". " , "."test3[$i]" ." , ". "test4[$i] <br/> " ;
$i++;
}
?>
<td><input type="submit" name ="submit" value="save"></td>
</form>
</table>
<?php
$i= $i -1;
$_SESSION['form'] = $form ;
$_SESSION['stream'] = $strm;
$_SESSION['subject'] = $subject;
$_SESSION['$i'] = $i;
?>
<?php
$j=0;
for($j ; $j<$i ; $j++){
echo $sid . " , " . "test1[$i]" ." , ". "test2[$i] ". " , "."test3[$i]" ." , ". "test4[$i] <br/> " ;

}
?>
 
Unfortunately I'm on leave and I cannot test your code. I will try to do that after Xmas if I get Internet access to my laptop.
 
ok nashukuru sana, ntutawasiliana baada ya xmas. na bado najaribu kila njia ili niweze maana bado nipo najifunza kode.
 
It has been a tough job, reading the code as it is hapa JF kwenye mobile app. I advised you to use pastebins. I insist.

As far as I have examined this code na posts zako, it seems the problem you are having is how to submit multiple students' entered marks in the form to the other script. Try this idea:

Append or prepend a unique incrementing integer kwenye name ya fields zako. Kisha kwenye receiving script, run through a loop that retrieves the data since you know the format and number of text boxes.

Labda nikuonyeshe a simple implementation kwa level yako. Kwenye first script where the user gets to snter the marks in the table kwenye while loop, iwe hivi:

$sn = 0;
while(whatever)
{
$sn++;
//show the student data as usual
//i am interested in the input fields
<input type=hidden name=$sn.name>
<input type=text name=$sn.test1>
<input type=text name=$sn.test2>
<input type=text name=$sn.test3>
<input type=text name=$sn.test4>
}

//the goal is to have something like
1.sid, 1.test1, 1.test2, 1.test3, 1.test4
2.sid, 2.test1, ....
3.sid, ...

All these will be submitted to the second script independently.

Pia kabla hujaclose form, ongeza hidden input nyingine ya kupass the max value of $sn to the second script. We will use it.

Sasa twende kwenye script ya pili. How do we get the different marks and their respective student ids? Using the $sn of course!

for($i =1, $i <= POST[$sn], $i++)
{
$sid = $_POST[$i.sid]
$test1 = $_POST[$i.test1]
// the same for test 2, 3 and 4
//do whatever you want with the students data in this loop
//db insertion is also possible here
}

I hope you are getting the idea. Don't replay my pseudocode. Understand it.

And note that I haven't misused the session superglobal as you were.
 
Back
Top Bottom