Changes between Version 6 and Version 7 of Docs/825gen2/Dev/Networking/PHP


Ignore:
Timestamp:
11/09/23 13:06:23 (12 months ago)
Author:
Don Wilson
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Docs/825gen2/Dev/Networking/PHP

    v6 v7  
    9393
    9494
     95Following is a more advanced demo. This reads from an ID storage transaction table and also displays vehicle images associated with transactions.
     96
     97{{{
     98<!DOCTYPE html>
     99<html lang="en">
     100<head>
     101  <title>825 ID Storage</title>
     102  <style type="text/css" media="screen">
     103  table tr td {
     104    text-align: right;
     105    padding: 0 15px;
     106  }
     107</style>
     108</head>
     109<body>
     110<?php
     111$conn = mysqli_connect('127.0.0.1', 'dbuser', '81440', 'test');
     112if(!$conn) {
     113  echo 'Connection error: ' . mysqli_connect_error();
     114} else {
     115  $sql = 'select * from trans;';
     116  $result = $conn->query($sql);
     117  if($result->num_rows > 0) {
     118    echo '<table><tr><th>Tran Num</th><th>date/time</th><th>Gross Wt</th><th>Tare Wt</th><th>Net Wt</th><th>Image</th></tr>';
     119    while($row = $result->fetch_assoc()) {
     120      $tkt_num = $row['tkt_num'];
     121      $datetime = $row['date'] . ' ' . $row['time'];
     122      $gross = $row['gross'];
     123      $tare = $row['tare'];
     124      $net = $row['net'];
     125      echo '<tr><td>' . $tkt_num . '</td><td>' . $datetime . '</td><td>' . $gross . '</td><td>' . $tare . '</td><td>'. $net  . '</td>';
     126      $imgfile = sprintf("v%06d_1.jpg", $tkt_num);
     127      $img = 'images/' . $imgfile;
     128      if(!file_exists($img)) {
     129        $imgfile = sprintf("v%06da_1.jpg", $tkt_num);
     130        $img = 'images/' . $imgfile;
     131      }
     132      if(file_exists($img)) {
     133        echo '<td><a href="' . $img . '"><img src="' . $img .'" width="128" height="96" ></a></td></tr>';
     134      } else {
     135        echo '<td>no image</td>';
     136      }
     137    }
     138    echo '</table>';
     139  }
     140}
     141?>
     142</body>
     143</html>
     144}}}
    95145
    96146
     147
     148
     149
     150