Hey all,
Ill get straight to the point.
When run this php script, I get a table seven rows high, but only data in the first row.
I am not sure what is wrong, but I think mysql_fetch_row does not do what I want. I don't know what to use in its place.
Or maybe the problem is unrelated, I don't know
I am still learning PHP.. I don't totally know what I am doing yet
Also, if you have optimizations, go ahead and post them
Ill get straight to the point.
When run this php script, I get a table seven rows high, but only data in the first row.
I am not sure what is wrong, but I think mysql_fetch_row does not do what I want. I don't know what to use in its place.
Or maybe the problem is unrelated, I don't know
I am still learning PHP.. I don't totally know what I am doing yet
Also, if you have optimizations, go ahead and post them
PHP:
//Get how manny rows there are.
$Number_result = query("SELECT * from checkin", $WHD_DB);
$Number = mysql_num_rows($Number_result);
//Query for all other data
$Asset_result = query("SELECT `ASSET_NUMBER` from checkin ORDER BY `ASSET_NUMBER` ASC", $WHD_DB);
$Date_result = query("SELECT `DATE` from checkin ORDER BY `ASSET_NUMBER` ASC", $WHD_DB);
$Time_result = query("SELECT `TIME` from checkin ORDER BY `ASSET_NUMBER` ASC", $WHD_DB);
$Student_6D_Result = query("SELECT `STUDENT_6D` from checkin ORDER BY `ASSET_NUMBER` ASC", $WHD_DB);
$Student_first_name_result = query("SELECT `STUDENT_FRIST_NAME` from checkin ORDER BY `ASSET_NUMBER` ASC", $WHD_DB);
$Student_last_name_result = query("SELECT `STUDENT_LAST_NAME` from checkin ORDER BY `ASSET_NUMBER` ASC", $WHD_DB);
$Status_result = query("SELECT `STATUS` from checkin ORDER BY `ASSET_NUMBER` ASC", $WHD_DB);
$Charger_result = query("SELECT `Charger` from checkin ORDER BY `ASSET_NUMBER` ASC", $WHD_DB);
$Assessment_result = query("SELECT `ASSESSMENT` from checkin ORDER BY `ASSET_NUMBER` ASC", $WHD_DB);
$Ticket_number_result = query("SELECT `TICKET_NUMBER` from checkin ORDER BY `ASSET_NUMBER` ASC", $WHD_DB);
//Put into an array... I don't know what I am doing here...
$Asset = mysql_fetch_row($Asset_result);
$Date = mysql_fetch_row($Date_result);
$Time = mysql_fetch_row($Time_result);
$Student_6D = mysql_fetch_row($Student_6D_Result);
$Student_first_name = mysql_fetch_row($Student_first_name_result);
$Student_last_name = mysql_fetch_row($Student_last_name_result);
$Status = mysql_fetch_row($Status_result);
$Charger = mysql_fetch_row($Charger_result);
$Assessment = mysql_fetch_row($Assessment_result);
$Ticket_number = mysql_fetch_row($Ticket_number_result);
?>
<table border="1">
<tr>
<td>Asset #</td>
<td>Check-in Date</td>
<td>Check-in Time</td>
<td>Student's ID #</td>
<td>Student's First Name</td>
<td>Student's Last Name</td>
<td>Status</td>
<td>Charger checked in?</td>
<td>System assessment</td>
<td>Ticket number</td>
</tr>
<?php
$i = 0;
// Because the array starts at 0, this will work
while ($i < $Number) {
echo "\n<tr>";
echo "\n\t<td>" . $Asset[$i] . "</td>" ;
echo "\n\t<td>" . $Time[$i] . "</td>";
echo "\n\t<td>" . $Date[$i] . "</td>";
echo "\n\t<td>" . $Student_6D[$i] . "</td>";
echo "\n\t<td>" . $Student_first_name[$i] . "</td>";
echo "\n\t<td>" . $Student_last_name[$i] . "</td>";
switch($Status[$i]) {
default:
echo "\n\t<td>How the hell did this happen?</td>";
break;
case "0":
echo "\n\t<td>No status set</td>";
break;
case "1":
echo "\n\t<td>Acceptable</td>";
break;
case "2":
echo "\n\t<td>Dirty/Messy</td>";
break;
case "3":
echo "\n\t<td>Failure/Damage</td>";
break;
}
switch($Charger[$i]) {
default:
echo "\n\t<td>How the hell did this happen?</td>";
break;
case "0":
echo "\n\t<td>Charger status not set</td>";
break;
case "1":
echo "\n\t<td>Yes</td>";
break;
case "2":
echo "\n\t<td>No</td>";
break;
}
echo "\n\t<td>" . $Assessment[$i] . "</td>";
if ($Ticket_number[$i] == 0 ) {
echo "\n\t<td>No #</td>";
} else {
// Because we don't know the ticket number, lets assume if it is not zero, it has a valid number
echo "\n\t<td><a href=http://mattmckay.org:8081/helpdesk/WebObjects/Helpdesk.woa/wa/ticket?ticketId=" . $Ticket_number[$i] . ">" . $Ticket_number[$i] . "</td>";
}
echo "\n</tr>";
$i++;
}
echo "</table>\n";
PHP:
function query($query,$database) {
$result = mysql_query ($query, $database) or die("Query failed : " . mysql_error());
return $result;
}