Read a Record from Merge

From: /web/includes/processAnInvoice_funcs.php

function midsForThis($srId_in) {
/*
This function takes a service record ID and returns an array containing all the
maintenance item labels associated with it.

BE AWARE: the array returned must be two dimensional in order for it to be compatible
with the function that displays tables. That is why it's neccessary to have the extra
[0] you see in the while statement below.

If there are no maintenance item labels
associated with it then the function will return an empty array. If the database query
fails then the script will abort. If no service record ID was passed to the
function it will abort.
*/
  $miArr = array();
  if (!isset($srId_in) OR $srId_in == "") {
    form_destroy();
    die('Error 47821346879. -Programmer.');
  }
  /*
  Query to find all maintenance item labels associated with service record ID.
  */
  $query = "SELECT maintenItems.label
            FROM servRecToMaintenItem INNER JOIN maintenItems
            ON servRecToMaintenItem.maintenItemId = maintenItems.id
            WHERE servRecToMaintenItem.servRecId = '$srId_in'";
  $result = mysql_query($query);
  if (!$result) {
    form_destroy();
    die('Query failed. Err: 367790875. May want sleep(). -Programmer.');
  }
  if ( mysql_num_rows($result) < 1) {
    return $miArr;
  }
  while ($row = mysql_fetch_row($result)) {
    $miArr[][0] = $row[0];
  }
  return $miArr;
}
Advertisements

About samehramzylabib

See About on https://samehramzylabib.wordpress.com
This entry was posted in Coding, Database and tagged , , , . Bookmark the permalink.