Jump to content

Refactor Multidimensional Disaster?


jmaccs64

Recommended Posts

Can someone please tell me the right way to do this?

 

$q =  "SELECT * FROM scores WHERE student_id = {$student_id} ORDER BY test_type ASC";
$r = mysql_query($q) or die();

$r2 = mysql_fetch_array($r);

$data[$r2['student_id']] = array(
'last_name' => $r2['last_name'],
'first_name' => $r2['first_name'],
'grad_year' => $r2['grad_year']
);

mysql_data_seek($r, 0);

while($row=mysql_fetch_assoc($r))
{
$data[testName($row['test_type'])] = 
                 array(
	'eng' => $row['eng'], 
	'math' => $row['math'],
	'read' => $row['read'],
	'sci' => $row['sci'],
	'comp' => round(($row['eng'] + $row['math'] + $row['read'] + $row['sci'])/4 )
	);
}

 

My Database Structure - All the different test-scores are in the same table, labeled with the test type &test-id..

id-student_id-last_name-first_name-eng-math-read-sci-grad_year-test_id-test_type
1-99999-smith-john-12-12-12-12-2012-1-3

 

I hope this makes sense!

Thanks-In-Advance

Link to comment
https://forums.phpfreaks.com/topic/232920-refactor-multidimensional-disaster/
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.