Jump to content

Barand

Moderators
  • Posts

    24,606
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. Seconds are optional <form> dt1 <input type='datetime-local' name='dt1' value='<?= date('Y-m-d\TH:i') ?>' > <br> dt2 <input type='datetime-local' name='dt2' value='<?= date('Y-m-d\TH:i:s') ?>' > <br> <input type='submit'> </form>
  2. One final comment - turn on PHP's and MySqli's error reporting. You and I aren't good enough to attempt development without them.
  3. I added one or two comments for you. <?php $username1=$_POST["text"] // ^^^^ there is no field named "text" $age=$_POST["number"] // ^^^^^^ there is no field named "number" $username="root"; $host="localhost"; $password=" "; $databasename="kemudb"; $conn=mysqli_connect($host, $username, $password, $databsename); // ^^ typo $sql_read="SELECT * FROM infokemu"; $result=mysqli_query($conn & $sql_read); // ^ WTF!? ?> <form method="POST" action=""> // ^^^^ as you are only getting data, your method should be GET, not POST USERNAME: <br> <input type="text" name="username1"/> <br> AGE <br> <input type="number" name="age"/> <br> <input type="submit" value="submit"/> </form> Lastly, what is the point of the query? You do nothing with the results (when you get any).
  4. If you look at the page source to see the code you are generating it should become obvious.
  5. If $id contains "Shooter" as a string value it need to be in quotes otherwise SQL thinks it is a column name $sql = "SELECT * FROM games WHERE genre = '$id' "; ^ ^
  6. I don't have your database table so I used the array to simulate the data that would be returned from a query so I could test the code. $data = $pdo->query("SELECT id , riflename , em , gm FROM rifles ORDER BY rifleName "); foreach ($data as $row) { echo "<option value={$row['id']} data-em='{$row['em']}' data-gm='{$row['gm']}'>" . htmlspecialchars( $row["rifleName"] ) . "</option>"; } Not so difficult, was it?
  7. Your script won't as it never refernces those database columns. I was under the impression that is exactly what my script is doing.
  8. When you process the query results, build an array with the required structure for your output. In this case something like $data = [ 'Kindred Coaching' => [ 2204 => [ 'Forecast' => '', 'Actual' => '' ], 2205 => [ 'Forecast' => '', 'Actual' => '' ]. 2206 => [ 'Forecast' => '345', 'Actual' => '345' ], 2207 => [ 'Forecast' => '345', 'Actual' => '' ], 2208 => [ 'Forecast' => '345', 'Actual' => '' ], 2209 => [ 'Forecast' => '345', 'Actual' => '' ], 2210 => [ 'Forecast' => '345', 'Actual' => '' ], 2211 => [ 'Forecast' => '345', 'Actual' => '' ] ] , 'Other Coaching' => [ 2204 => [ 'Forecast' => '', 'Actual' => '' ], 2205 => [ 'Forecast' => '', 'Actual' => '' ], 2206 => [ 'Forecast' => '123', 'Actual' => '234' ], 2207 => [ 'Forecast' => '123', 'Actual' => '' ], 2208 => [ 'Forecast' => '123', 'Actual' => '' ], 2209 => [ 'Forecast' => '123', 'Actual' => '' ], 2210 => [ 'Forecast' => '123', 'Actual' => '' ], 2211 => [ 'Forecast' => '123', 'Actual' => '' ] ] ]; then foreach ($data as $account => $accdata) { // start row // output account foreach ($accdata as $yrmnth => $values) { // output forecast and actual cells } // end row }
  9. Use data attributes for the options <?php $data = [ [ 'id' => 1, 'rifleName' => '.308 Bolt action', 'em' => '225', 'gm' => '1350' ], [ 'id' => 2, 'rifleName' => '7mm magnum', 'em' => '300', 'gm' => '1575' ], [ 'id' => 3, 'rifleName' => '.243 LeverAction', 'em' => '215', 'gm' => '8725' ] ]; ?> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script type='text/javascript'> $().ready(function() { $("#menu").change( function() { let em = $(this).find("option:selected").data("em") let gm = $(this).find("option:selected").data("gm") $("#em").val(em) $("#gm").val(gm) }) }) </script> <select class='nameItems' id="menu" name="selection"> <option value="">Choose a Rifle</option> <?php foreach ($data as $row) { echo "<option value={$row['id']} data-em='{$row['em']}' data-gm='{$row['gm']}'>" . htmlspecialchars( $row["rifleName"] ) . "</option>"; } ?> </select> em:<input type="text" class="charge-type" name="em" id="em" value="0" disabled size="5"/> gm: <input class="charge-type" name="gm" id="gm" value="0" disabled size="5"/>
  10. Correction to above - I screwed up the array rotation bit. The if (!$placed) section should be if (!$placed) { // if we have an unseatable guest if ($passes >= count($enemies)) return 'Failed'; ++$passes; $guests = array_keys($enemies); for ($p=0; $p<$passes; $p++) $guests[] = array_shift($guests); // rotate array and try again $plan = [array_shift($guests)]; }
  11. Challenge accepted. Instead of creating all combinations (3,628,800 fo 10 guests) then eliminating, I decided to attempt the construction of feasible combinations only. First, create a useable array of the enemies of each gust and use that to place each guest, if possible. <?php $guests = 7; $enemies = [ '1-2,4', '3-4,6', '2-5' ]; ########################################################## # # # create a usable array ($e) of the enemies of eah guest # # # ########################################################## $e = array_fill_keys(range(1, $guests), []); foreach ($enemies as $a) { list($b, $c) = explode('-', $a); foreach (explode(',', $c) as $d) { $e[$b][] = $d; $e[$d][] = $b; } } ############################################################### # sort the array so those with most ememies are seated first # ############################################################### uasort($e, fn($a, $b) => count($b)<=>count($a)); echo seatPlan($e); function seatPlan(&$enemies) { $passes = 0; $guests = array_keys($enemies); $plan = [array_shift($guests)]; while(count($guests)) { // loop until all guests seated $placed = 0; foreach ($guests as $k => $g) { $p = count($plan); // if next guest is a friend, seat them if (!in_array($plan[$p-1], $enemies[$g])) { $plan[] = $g; unset($guests[$k]); $placed = 1; } } if (!$placed) { // if we have an unseatable guest if ($passes >= count($enemies)) return 'Failed'; ++$passes; $guests[] = array_shift($guests); // rotate array and try again $guests = array_keys($enemies); $plan = [array_shift($guests)]; } } return join(', ', $plan); } ?>
  12. As you are having a problem with the retrieval and display it might be an idea to show that portion of the code. As an aside, you are overwriting your date created with the date updated (and wrong format). Define those fileds in your table as created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, the omit them from your insert and update queries - they will update automatically.
  13. Sorry, but there was guesswork involved as I don't know all the table structures - you only gave os the quote table..
  14. Return values from functions. And stop conneting inside your functions! Connect once at top of script and pass the connection to your functions. I'd structure it something like this... <?php require 'includes/dbconn.php'; ## HANDLE AJAX CALL if ( isset($_GET['itemId']) ) { // if it's an ajax request exit(getItemAttributesById($pdo, $_GET['itemId'])); } function getItemAttributesById($pdo, $itemId){ $sql = "SELECT id, name, type, price_uk, price_us, price_ca, price_au, price_eu, billing_freq from item where id = :itemId"; $stmt = $pdo->prepare($sql); $bindData = [ 'itemId' => $itemId ]; $stmt->execute($bindData); $item = $stmt->fetch(PDO::FETCH_ASSOC); return json_encode($item); } ?>
  15. You only need separate connections if you are working on multiple servers. One connection is suffucient to work with several database on the same server. The connection is to the server, the database name merely defines the default database. $con->query("SELECT username FROM user"); // if querying default db $con->query("SELECT username FROM DB2.user"); // if DB2 is not the default db. To copy a table from DB1 to DB2 $con->query("CREATE TABLE DB2.tablea LIKE DB1.tablea"); $con->query("INSERT INTO DB2.tablea SELECT * FROM DB1.tablea");
  16. It happened again. My notifications indicated a post 2 hours ago (just signed on). Again it appears in "Expanded" but not in "Condensed" activity lists. Condensed Expanded
  17. or something like this to find the max quoteIds to be matched SELECT mx.quoteId, job_id as jobId, job.name as jobName, job.client_id as clientId, client.name as clientName, quote.currency, quote.version from job inner join client on client.id = job.client_id inner join ( select job_id , max(id) as quoteId from quote where quote.closed != '1' group by job_id ) mx using (job_id) inner join quote on mx.quoteId = quote.id group by job_id
  18. Why are you passing the $version to the function but always setting the parameter for :version to 1 ?
  19. You are grouping by jobId so you will get one row for each job. The max(quoteId) should be OK (as that is a aggregation) and also jobName and clientId from the job record, but the remaining values (like version and currency) could be arbitrarily selected from from any quote record associated with jobId.
  20. I know the <select> dropdown looks fine and the options display correctly but view the page source code. The problem comes when the form is submitted and the value is wrong.
  21. Beware when enclosing a string attribute value with single quotes. If $myrow['cats'] = "O'Reilly books; echo "<option value='{$myrow['cat']}'>{$myrow['cat']}</option>"; then the generated HTML will be And the submitted GET value... Instead, echo "<option value=\"{$myrow['cat']}\">{$myrow['cat']}</option>"; ->
  22. Only out the maincat when it changes to a new value. set prevcat = maincat foreach record start new row if maincat != prevcat output maincat set prevcat = maincat else output blank endif output subcat end row end foreach
  23. Have you considered a common format such as ".csv" file EG First_Name,Last_Name,Sex,Fruits Scott,Chegg,male,"orange, berry" Laura,Norder,female,"apple, orange" code if($_SERVER['REQUEST_METHOD']=='POST'){ if (!file_exists('file.txt')) { file_put_contents('file.txt', "First_Name,Last_Name,Sex, Fruits\n"); // write header line } $file=fopen("file.txt", "a"); $record = [$_POST['firstName'], $_POST['lastName'], $_POST['sex'], join(',', $_POST['fruit'])]; fputcsv($file, $record); }
  24. $_POST['fruit'] is an array, so line 9 would need to be $fruit = "Fav Fruits:" . join(', ', $_POST['fruit']); then fwrite($file, $fruit); I don't know what you subsequently intend to do with the text file but the format you use makes it both difficult to read and to process. An improvent would be some form of delimiter character between fields and newlines at end of each record. eg First Name:Laura|Last Name:Norder|Sex:female|Fav fruit:Apple, Orange First Name:Scott|Last Name:Chegg|Sex:male|Fav fruit:Apple, Berry [EDIT] Ignore the above comment re format. I just noticed you are (subtly) outputting newlines - I was looking for more explicit "\n";
  25. A better way to handle multiple checkboxes like those is Fav Fruit<input type="checkbox" name="fruit[]" value="apple">Apple <input type="checkbox" name="fruit[]" value="orange">Orange <input type="checkbox" name="fruit[]" value="berry">Berry<br> so the checked ones are posted as an array $_POST = Array ( [firstName] => Scott [lastName] => Chegg [sex] => male [fruit] => Array ( [0] => apple [1] => berry ) ) When writing to the file fwrite($file, join(', ', $_POST['fruit']);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.