Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 11.30 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Pulling data from MySql into an array, then comparing the array's data to an existing variable
  2. <?php require_once('Connections/customer.php'); ?><?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7. $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12. switch ($theType) {
  13. case "text":
  14.   $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.   break;    
  16. case "long":
  17. case "int":
  18.   $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.   break;
  20. case "double":
  21.   $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.   break;
  23. case "date":
  24.   $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.   break;
  26. case "defined":
  27.   $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.   break;
  29. }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. $maxRows_DetailRS1 = 30;
  35. $pageNum_DetailRS1 = 0;
  36. if (isset($_GET['pageNum_DetailRS1'])) {
  37. $pageNum_DetailRS1 = $_GET['pageNum_DetailRS1'];
  38. }
  39. $startRow_DetailRS1 = $pageNum_DetailRS1 * $maxRows_DetailRS1;
  40.  
  41. $colname_DetailRS1 = "-1";
  42. if (isset($_GET['recordID'])) {
  43.   $colname_DetailRS1 = $_GET['recordID'];
  44.    }
  45.      mysql_select_db($database_customer, $customer);
  46.      $query_DetailRS1 = sprintf("SELECT * FROM customer WHERE id = %s", GetSQLValueString          ($colname_DetailRS1, "int"));
  47.   $query_limit_DetailRS1 = sprintf("%s LIMIT %d, %d", $query_DetailRS1, $startRow_DetailRS1,         $maxRows_DetailRS1);
  48.    $DetailRS1 = mysql_query($query_limit_DetailRS1, $customer) or die(mysql_error());
  49.    $row_DetailRS1 = mysql_fetch_assoc($DetailRS1);
  50.  
  51.    if (isset($_GET['totalRows_DetailRS1'])) {
  52.    $totalRows_DetailRS1 = $_GET['totalRows_DetailRS1'];
  53.    } else {
  54.     $all_DetailRS1 = mysql_query($query_DetailRS1);
  55.     $totalRows_DetailRS1 = mysql_num_rows($all_DetailRS1);
  56.  }
  57.    $totalPages_DetailRS1 = ceil($totalRows_DetailRS1/$maxRows_DetailRS1)-1;
  58.  
  59.    $query = "SELECT id, state_abbr FROM state WHERE id =".$row_DetailRS1['state']."";
  60.  
  61.    $result = mysql_select_db($database_customer, $customer)
  62.    or die($query."<br/><br/>".mysql_error());
  63.  
  64. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0     Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  65. <html xmlns="http://www.w3.org/1999/xhtml">
  66. <head>
  67. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  68. <title>Untitled Document</title>
  69. <link href="css/style.css" rel="stylesheet" type="text/css" />
  70. </head>
  71.  
  72. <body>
  73.  
  74. <table width="41%" border="0" align="center" cellpadding="2" cellspacing="5">
  75.   <tr>
  76.   <td width="157">Id</td>
  77.   <td width="469"><?php echo $row_DetailRS1['id']; ?></td>
  78. </tr>
  79. <tr>
  80.   <td>Prefix</td>
  81.   <td><?php if($row_DetailRS1['prefix']==1) {
  82.     echo 'Mr.';}
  83.     else if($row_DetailRS1['prefix']==2) {
  84.         echo 'Mrs.'; }
  85.         else if($row_DetailRS1['prefix']==3) {
  86.             echo 'Ms.'; }
  87.             else if($row_DetailRS1['prefix']==4) {
  88.                 echo 'Mr. & Mrs.'; }
  89.                 else if($row_DetailRS1['prefix']==5) {
  90.                     echo 'Dr.'; }
  91.                     else if($row_DetailRS1['prefix']==6) {
  92.                         echo 'Dr. & Mrs.'; }
  93.                         else if($row_DetailRS1['prefix']==7) {
  94.                             echo 'Mr. & Dr.'; }
  95.                             else if($row_DetailRS1['prefix']==8) {
  96.                                 echo 'Drs.'; }
  97.                                 else if($row_DetailRS1['prefix']==9) {
  98.                                     echo 'Hon.';}
  99.                                     else if($row_DetailRS1['prefix']==10) {
  100.                                         echo 'Hon. & Mrs.'; }
  101.                                         else if($row_DetailRS1['prefix']==11) {
  102.                                             echo 'Mr. & Hon.'; }
  103.                                             else if($row_DetailRS1['prefix']==12) {
  104.                                                 echo 'Hons.'; }
  105.                                                 else if($row_DetailRS1['prefix']==13) {
  106.                                                     echo 'Rev.'; }
  107.                                                     else if($row_DetailRS1['prefix']==14) {
  108.                                                         echo 'Rev. & Mrs.'; }
  109.                                                         else if($row_DetailRS1['prefix']==15) {
  110.                                                             echo 'Atty.'; }
  111.                                                             else if($row_DetailRS1['prefix']==16) {
  112.                                                                 echo 'Atty. & Mrs.'; }
  113.                                                                 else if($row_DetailRS1['prefix']==17) {
  114.                                                                     echo 'Mr. & Atty.'; }
  115.                                                                     else if($row_DetailRS1['prefix']==18) {
  116.                                                                         echo 'Attys.'; }
  117.                                                                         else if($row_DetailRS1['prefix']==19) {
  118.                                                                             echo 'Sen.'; }
  119.                                                                             else if($row_DetailRS1['prefix']==20) {
  120.                                                                                 echo 'Sen & Mrs.'; }
  121.                                                                                 else if($row_DetailRS1['prefix']==21) {
  122.                                                                                     echo 'Mrs. & Sen.'; }
  123.                                                                                     else if($row_DetailRS1['prefix']==22) {
  124.                                                                                         echo 'Sens.'; }
  125.                                                                                         else if($row_DetailRS1['prefix']==23) {
  126.                                                                                             echo 'Rep.'; }
  127.                                                                                             else if($row_DetailRS1['prefix']==24) {
  128.                                                                                                 echo 'Rep. & Mrs.'; }
  129.                                                                                                 else if($row_DetailRS1['prefix']==25) {
  130.                                                                                                     echo 'Mr. & Rep.'; }
  131.                                                                                                     else if($row_DetailRS1['prefix']==26) {
  132.                                                                                                         echo 'Reps.'; }
  133.                                                                                                         else if($row_DetailRS1['prefix']==27) {
  134.                                                                                                             echo 'Mayor'; }
  135.                                                                                                             else if($row_DetailRS1['prefix']==28) {
  136.                                                                                                                 echo 'Admin'; }; ?></td>
  137.   </tr>
  138.   <tr>
  139.    <td>Business Name</td>
  140.    <td><?php echo $row_DetailRS1['businessName']; ?></td>
  141.  </tr>
  142.  <tr>
  143. <td>First Name</td>
  144. <td><?php echo $row_DetailRS1['firstName']; ?></td>
  145.  </tr>
  146.  <tr>
  147. <td>Spouse Name</td>
  148. <td><?php echo $row_DetailRS1['spouseName']; ?></td>
  149. </tr>
  150. <tr>
  151. <td>Last Name</td>
  152. <td><?php echo $row_DetailRS1['lastName']; ?></td>
  153.  </tr>
  154. <tr>
  155. <td>Suffix</td>
  156. <td><?php if($row_DetailRS1['suffix']==1) {
  157.     echo 'Sr.';}
  158.     else if($row_DetailRS1['suffix']==2) {
  159.         echo 'Jr.'; }
  160.         else if($row_DetailRS1['suffix']==3) {
  161.             echo 'I'; }
  162.             else if($row_DetailRS1['suffix']==4) {
  163.                 echo 'II' ; }
  164.                 else if($row_DetailRS1['suffix']==5) {
  165.                     echo 'III'; }
  166.                     else if($row_DetailRS1['suffix']==6) {
  167.                         echo 'IV'; }
  168.                         else if($row_DetailRS1['suffix']==7) {
  169.                             echo 'V'; }
  170.                             else if($row_DetailRS1['suffix']==8) {
  171.                                 echo 'Esq.'; }; ?></td>
  172.   </tr>
  173.   <tr>
  174.   <td>Address</td>
  175.   <td><?php echo $row_DetailRS1['address']; ?></td>
  176. </tr>
  177. <tr>
  178. <td>Address Continued</td>
  179. <td><?php echo $row_DetailRS1['addressCont']; ?></td>
  180. </tr>
  181. <tr>
  182. <td>City</td>
  183. <td><?php echo $row_DetailRS1['city']; ?></td>
  184. </tr>
  185. <tr>
  186. <td>State</td>
  187. <td><?php  while($row = mysql_fetch_assoc($customer, $result)) {
  188.     if($row_DetailRS1['state'] == $row) {
  189.         echo '$row';}} ?></td>
  190. </tr>
  191. <tr>
  192. <td>Zip Code</td>
  193. <td><?php echo $row_DetailRS1['zipCode']; ?></td>
  194. </tr>
  195. <tr>
  196. <td>Phone Number</td>
  197. <td><?php echo $row_DetailRS1['phoneNum']; ?></td>
  198. </tr>
  199. <tr>
  200. <td>Alt. Phone Number</td>
  201. <td><?php echo $row_DetailRS1['altPhoneNum']; ?></td>
  202. </tr>
  203. <tr>
  204. <td>E-mail</td>
  205. <td><?php echo $row_DetailRS1['email']; ?></td>
  206. </tr>
  207. <tr>
  208. <td>Board Member</td>
  209. <td><?php echo $row_DetailRS1['boardMember']; ?></td>
  210. </tr>
  211. <tr>
  212. <td>Trustee</td>
  213. <td><?php echo $row_DetailRS1['trustee']; ?></td>
  214. </tr>
  215. <tr>
  216. <td>Musician</td>
  217. <td><?php echo $row_DetailRS1['musician']; ?></td>
  218. </tr>
  219. <tr>
  220.   <td>Support Staff</td>
  221. <td><?php echo $row_DetailRS1['supportStaff']; ?></td>
  222. </tr>
  223. <tr>
  224. <td>Active</td>
  225. <td><?php echo $row_DetailRS1['active']; ?></td>
  226. </tr>
  227. <tr>
  228. <td>Deceased</td>
  229. <td><?php echo $row_DetailRS1['deceased']; ?></td>
  230. </tr>
  231. <tr>
  232. <td>Comments</td>
  233. <td><?php echo $row_DetailRS1['comments']; ?></td>
  234. </tr>
  235. </table>
  236. </body>
  237. </html><?php
  238. mysql_free_result($DetailRS1); ?>
  239.        
  240. create table prefixes (
  241.    prefix_id integer primary key,
  242.    prefix_string varchar(20)
  243. );
  244.  
  245. insert into prefixes (prefix_id, prefix_string) values (1, 'Mr.');
  246. insert into prefixes (prefix_id, prefix_string) values (2, 'Mrs.');
  247. ... etc ...
  248.        
  249. select c.*, p.prefix_string
  250.   from customer c, prefixes p
  251.   where c.prefix = p.prefix_id;
  252.        
  253. $aPrefixMap = array(
  254.     1       => 'Mr.',
  255.     2       => 'Mrs.',
  256.     3       => 'Ms.',
  257.     4       => 'Mr. & Mrs.',
  258.     5       => 'Dr.',
  259.     6       => 'Dr. & Mrs.',
  260.     7       => 'Mr. & Dr.',
  261.     8       => 'Drs.',
  262.     9       => 'Hon.',
  263.     10      => 'Hon. & Mrs.',
  264.     11      => 'Mr. & Hon.',
  265.     12      => 'Hons.',
  266.     13      => 'Rev.',
  267.     14      => 'Rev. & Mrs.',
  268.     15      => 'Atty.',
  269.     16      => 'Atty. & Mrs.',
  270.     17      => 'Mr. & Atty.',
  271.     18      => 'Attys.',
  272.     19      => 'Sen.',
  273.     20      => 'Sen & Mrs.',
  274.     21      => 'Mrs. & Sen.',
  275.     22      => 'Sens.',
  276.     23      => 'Rep.',
  277.     24      => 'Rep. & Mrs.',
  278.     25      => 'Mr. & Rep.',
  279.     26      => 'Reps.',
  280.     27      => 'Mayor',
  281.     28      => 'Admin'
  282. );
  283.  
  284. $iPrefix = $row_DetailRS1['prefix'];
  285. if(array_key_exists($iPrefix, $aPrefixMap))
  286.     echo $aPrefixMap[$iPrefix];
  287.        
  288. $aRowDetailMap = array(
  289.     1 => 'Sr.',
  290.     2 => 'Jr.',
  291.     3 => 'I',
  292.     4 => 'II',
  293.     5 => 'III',
  294.     6 => 'IV',
  295.     7 => 'V',
  296.     8 => 'Esq.'
  297. );
  298.  
  299. $iDetailSuffix = $row_DetailRS1['suffix'];
  300. if(array_key_exists($iDetailSuffix, $aRowDetailMap))
  301.     echo $aRowDetailMap[$iDetailSuffix];