Advertisement
wunude0011

Columns

Apr 6th, 2020
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.11 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>0802_Pass_Data_to_Select</title>
  4.  
  5. </head>
  6.  
  7. <body style="font-family: Arial, Helvetica, sans-serif; color: Blue; background-color:">
  8.    
  9.  
  10. <form id="myform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. <h2> Pass Data to a select statement</h2>
  18.  
  19. <p> Enter SSN Code to see by state:
  20. <input type='text' name='ssncode' size='2' />
  21. </p>
  22.  
  23. <?php
  24. //*************************************************
  25. //*
  26. //* Get SSN Code
  27. //*
  28. //**************************************************
  29.  
  30. if (isset($_POST['ssncode']))
  31. {
  32.     $ssncode = $_POST['ssncode'];
  33.  
  34.     if (empty($ssncode))
  35.     {
  36.        $ssncode = 'ALL';
  37.  
  38.     }
  39.  
  40.  } else {
  41.     $ssncode = 'ALL';
  42.  }
  43.  
  44.  
  45. //******************************************
  46. //* Connect to MYSQL and Database
  47. //*
  48. //******************************************
  49.  
  50.  $db = mysqli_connect('localhost','root','', 'working');
  51.  
  52.  if (!$db)
  53.  {
  54.  
  55.     echo "<h1>Unable to Connect to MySQL</h1>";
  56.  }
  57.  
  58.  
  59. //********************************************
  60. //*
  61. //*  SELECT from table and dislay Results
  62. //*
  63. //*********************************************
  64.  
  65.  $sql_statement = "SELECT Camera_Kits, Lighting_kits, Monitors_TriPods_Extras ";
  66.  $sql_statement .= "FROM equipment ";
  67.  
  68.  
  69.  if ($ssncode != 'ALL')
  70.  {
  71.  
  72.     $sql_statement .= "WHERE Camera_Kits = '".$ssncode."' ";
  73.  }
  74.  
  75.   $sql_statement .= "ORDER BY Camera_Kits ";
  76.  
  77.  $result = mysqli_query($db, $sql_statement); // Run SELECT
  78.  
  79.  $outputDisplay = "";
  80.  $myrowcount = 0;
  81.  
  82.  if (!$result) {
  83.     $outputDisplay .= "<p style='color: red;'>MYSQL No: ".mysqli_errno($db)."<br>";
  84.     $outputDisplay .= "MYSQL Error: ".mysqli_error($db)."<br>";
  85.     $outputDisplay .= "<br>SQL: ".$sql_statement."<br>";
  86. } else {
  87.  
  88.  
  89. if ($ssncode == 'ALL')
  90. {
  91.  
  92.     $outputDisplay = "<h3>SSN Codes for each person</h3>";
  93. }   else{
  94.  
  95.     $outputDisplay = "<h3>SSN Codes for each person lives </h3>";
  96. }
  97.  
  98. $outputDisplay .= '<table border=1 style="color: black;">';
  99.  $outputDisplay .= '<tr><th>Camera_Kits</th><th>Lighting_kits</th><th>Monitors_TriPods_Extras</th></tr>';
  100.  
  101.  $numresults = mysqli_num_rows($result);
  102.  
  103.  
  104.     for ($i = 0; $i < $numresults; $i++)
  105.     {
  106.         if (!($i % 2) == 0)
  107.         {
  108.             $outputDisplay .= "<tr style=\"background-color: #F5DEB3;\">";
  109.         }  else {
  110.             $outputDisplay .= "<tr style=\"background-color: white; cellpadding: 10;\">";
  111.         }
  112.        
  113.         $myrowcount++;
  114.  
  115.         $row = mysqli_fetch_array($result);
  116.  
  117.         $Camera_Kits = $row['Camera_Kits'];
  118.         $Lighting_kits = $row['Lighting_kits'];
  119.         $Monitors_TriPods_Extras = $row['Monitors_TriPods_Extras'];
  120.  
  121.         $outputDisplay .= "<td>".$Camera_Kits."</td>";
  122.         $outputDisplay .= "<td>".$Lighting_kits."</td>";
  123.         $outputDisplay .= "<td>".$Monitors_TriPods_Extras."</td>";
  124.  
  125.        
  126.       $outputDisplay .= "</tr>";
  127.  
  128.  
  129.        }
  130.    $outputDisplay .= "</table>";
  131.  
  132.  
  133.      }
  134.    ?>
  135.  
  136.  
  137.  <br /><br /><input type="submit" value="Submit SQL Statements" />
  138.  
  139.  <?php
  140.   $outputDisplay .= "<br /><br /><b>Number of Rows in Results: $myrowcount </b><br /><br />";
  141.   echo  $outputDisplay;
  142.   ?>
  143. </body>
  144.  
  145. </form>
  146. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement