-
Posts
24,604 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
You are not giving the "start" column a value in the INSERT statement so it will try to give it a null value. You must either Give a value in the insert query, or define a default non-null value in the table definition edit: Columns defined as NOT NULL should have a default value.
-
Create a gd image from the jpg image file $im = imagecreatefromjpg('pathToImageFile'); Add the text using imagettftext() or imagestring() Output the new image with imagejpg()
-
A luxury after using MS_SQL
- 7 replies
-
- select count
- date
-
(and 1 more)
Tagged with:
-
try <html> <head> <meta name="generator" content="PhpED 14.0 (Build 14039, 64bit)"> <title>Sample</title> <meta name="creation-date" content="05/27/2015"> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script> $(document).ready(function() { $(".view").hide(); // hide all $('#viewSelector').change(function() { // hide all $(".view").hide(); // show current $("#"+$(this).val()).show(); }); }); </script> </head> <body> Have you been part of any other VTC's before this application?<br> <select id="viewSelector"> <option value="0">---Select one---</option> <option value="YES">Yes</option> <option value="NO">No</option> </select> <div id="YES" class='view'> If so, which VTC's have you been in and what was your reason for quitting?<br> <input type="text" name="otherVTC" class="form-control" placeholder="Example: <vtc name>: reason, <vtc name>: reason, etc." required><br /> </div><br> <div id="NO" class='view'> <p>Visible if NO selected</p><br /> </div><br> </body> </html>
-
How would I remove an instance of a class inside a array
Barand replied to Supervan's topic in PHP Coding Help
Perhaps use the id as the key inside the array $item = new Item($result->id, $result->name); $_SESSION['cart'][$result->id] = $item; then unset($_SESSION['cart'][$id]; -
I don't see any element with class='viewMap'
-
I know I am stating the obvious, but if permissions haven't changed and the code hasn't changed then it has to be something else that changed. You need to put on your "detective" hat and figure out what has changed between the time it last worked and the time it stopped working.
-
In fact, as long as the date is in the correct format it works with VARCHAR datetimes too CREATE TABLE `test_date` ( `id` int(11) NOT NULL AUTO_INCREMENT, `date` datetime DEFAULT NULL, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `str_date` varchar(20) DEFAULT NULL, PRIMARY KEY (`id`) ) mysql> SELECT -> date -> , DATE(date) as date_only -> , timestamp -> , DATE(timestamp) as ts_date_only -> , str_date -> , DATE(str_date) as s_date_only -> FROM test_date; +---------------------+------------+---------------------+--------------+---------------------+-------------+ | date | date_only | timestamp | ts_date_only | str_date | s_date_only | +---------------------+------------+---------------------+--------------+---------------------+-------------+ | 2015-05-26 17:55:00 | 2015-05-26 | 2015-05-26 18:03:31 | 2015-05-26 | 2015-05-26 17:55:00 |2015-05-26 | +---------------------+------------+---------------------+--------------+---------------------+-------------+
- 7 replies
-
- select count
- date
-
(and 1 more)
Tagged with:
-
If it were stored as DATETIME then DATE(`history_date`) would work just the same.
- 7 replies
-
- select count
- date
-
(and 1 more)
Tagged with:
-
Timestamps have a date and time element (2015-05-26 16:53:30) so will not be equal to today's date (2015-05-26) which has 00:00:00 as its time element. You need to use DATE() function to extract the date portion. SELECT ... WHERE DATE(history_date) = CURDATE()
- 7 replies
-
- select count
- date
-
(and 1 more)
Tagged with:
-
'01-01-1970' is what you get when formatting an invalid or 0 date. As the error message states, the fetch_assoc is failing but you still try to output it. if(mysql_num_rows($note_query)!=0) { $note_rs=mysql_fetch_assoc(); } Above is where you call the first row, the function call is missing the argument
-
From your data +--------+--------+------+ | worker | client | main | +--------+--------+------+ | w1 | c1 | 1 | | w1 | c3 | 0 | | w1 | c4 | 0 | | w1 | c5 | 0 | | w2 | c1 | 0 | | w2 | c2 | 1 | | w2 | c4 | 0 | | w3 | c3 | 0 | | w3 | c4 | 0 | | w3 | c5 | 1 | | w4 | c1 | 0 | | w4 | c2 | 0 | | w4 | c4 | 0 | | w4 | c5 | 1 | | w5 | c1 | 0 | | w5 | c3 | 1 | | w5 | c4 | 0 | | w6 | c2 | 0 | | w6 | c3 | 1 | | w7 | c1 | 0 | | w7 | c2 | 1 | | w7 | c4 | 0 | +--------+--------+------+ I got this assessment schedule (which is as even as I can get it) c1 c2 c3 c4 c5 w1 M A w2 A M w3 A M w4 A M w5 M A w6 A M w7 A M The code $sql = "SELECT worker , client , main FROM worker_client"; $worker = []; // worker assessments $client = []; // client assessed by $res = $db->query($sql); while (list($w,$c,$m) = $res->fetch_row()) { $client[$c][$w] = 0; if ($m) { // allocate assessments of main clients first $worker[$w][] = $c; $client[$c][$w] = 1; } } // while still workers with < 2 assessments while (array_filter($worker, 'assess1')) { // sort to get clients with least assessments first uasort($client, function($a,$b){ return array_sum($a) - array_sum($b);}); foreach ($client as $c => $warr) { asort($warr); foreach ($warr as $w => $k) { if ($k==0) { // if worker has < 2 assessments, add client to their list if (count($worker[$w])<2) { $worker[$w][] = $c; $client[$c][$w]++; break; } } } } } echo '<pre>',print_r($worker, true),'</pre>'; // assessment schedule function assess1($var) // array filter function { return count($var) < 2; }
-
What attribute of an evaluation has to be proportional? To what should it be proportional? Perhaps the number of words in each evaluation should be proportional to the client's weight? Give us a clue.
-
Generate number and verify it's uniqeness in mysql or advance by 1
Barand replied to Jason89002's topic in PHP Coding Help
That what MySql gave us AUTO_INCREMENT function for. Define you work order number as the PRIMARY KEY with AUTO_INCREMENT -
Just in case anyone is tempted to use this "shuffle and pray" shortcut approach to this problem I checked out its validity. I took arrays of N drivers and shuffled them N! times, storing each combination. I then checked to see how many were unique. These are the results ACB BAC BAC BAC CBA CBA 3 drivers: 3 duplicate combinations out of 6 (50%) ABCD ACDB ADBC ADBC ADCB BADC BCAD BCDA BCDA BDCA CABD CABD CBAD CBDA DABC DACB DACB DACB DBAC DBCA DBCA DCAB DCAB DCBA 4 drivers: 7 duplicate combinations out of 24 (29%) ABDCE ABDEC ABECD ABECD ABEDC ABEDC ACBDE ACDBE ACDBE ACDEB ADBEC ADEBC ADECB AEBDC AECBD AECDB AEDCB BACED BADCE BADEC BADEC BCAED BCDEA BCDEA BCEAD BDACE BDACE BDAEC BDAEC BDCAE BDCAE BDEAC BDECA BEDAC BEDAC BEDCA CABDE CABED CABED CAEDB CAEDB CAEDB CBAED CBDAE CBEAD CBEDA CBEDA CDABE CDAEB CDBAE CDBEA CDEAB CDEBA CDEBA CDEBA CDEBA CDEBA CEABD CEADB CEADB CEADB CEBDA CEDAB CEDAB CEDAB CEDBA DABCE DABCE DABCE DAEBC DBAEC DBCAE DBEAC DCABE DCBAE DCBEA DCBEA DCBEA DCEAB DCEBA DCEBA DEACB DEACB DEBAC DEBAC DEBCA DECAB DECAB DECBA DECBA DECBA EADBC EADBC EADBC EADBC EBACD EBACD EBACD EBACD EBCDA EBDCA EBDCA ECABD ECBAD ECBAD ECBDA ECBDA ECDAB ECDBA ECDBA EDABC EDABC EDACB EDACB EDACB EDBCA EDBCA EDCAB EDCBA EDCBA 5 drivers: 46 duplicate combinations out of 120 (38%) 6 drivers: 265 duplicate combinations out of 720 (36%) 7 drivers: 1841 duplicate combinations out of 5040 (36%) 8 drivers: 14761 duplicate combinations out of 40320 (36%) 9 drivers: 327861 duplicate combinations out of 362880 (90%) Verdict: Not fit for purpose. The code used to test: <?php $drivers = ['A','B']; $extra = ['C','D','E','F','G','H','I']; $factorials = [ 3 => 6, 4 => 24, 5 => 120, 6 => 720, 7 => 5040, 8 => 40320, 9 => 362880 ]; foreach ($extra as $e) { $drivers[] = $e; // add to drivers echo countUnique($drivers, $factorials); // test with N drivers } function countUnique($d, $facts) { $combos = []; $k = count($d); $f = $facts[$k]; for ($i=0; $i<$f; $i++) { shuffle($d); // shuffles n! times $str = join('',$d); // and stores each $combos[] = $str; // random combination } // output the smaller shuffled combo arrays to view duplicates if ($k < 6) { sort($combos); $chunks = array_chunk($combos, 12); foreach($chunks as $coms) echo join(' ', $coms)."<br>"; echo '<br>'; } $n = count(array_unique($combos)); // count how many were unique $n1 = $f - $n; // number of duplicate values $n2 = count($combos); // to check that n! were generated return sprintf('%d drivers: %6d duplicate combinations out of %6d (%d%%)<br><br>', count($d), $n1, $n2, $n1*100/$n2 ); } ?>
-
Your code exits the function on the return statement so echo never called. Also those functions a very repetitive. Name your form inputs "qty[1]", "qty[2]" and "qty[3]" so they are posted as an array then your processing becomes a simple loop $prices = array ( 1 => 5.00, 2 => 3.00, 3 => 1.00 ); if (isset($_POST['qty'])) { $total = 0; foreach ($_POST['qty'] as $k => $qty) { $value = $qty * $prices[$k]; echo "Service $k : $value<br>"; $total += $value; // add value to the total } echo "Total : $total"; }
-
My car isn't working at the moment. I've posted a photo of the car, can you tell me why it's not working?
-
Trying to get a several rows and colums with data.
Barand replied to rvdveen27's topic in MySQL Help
Change the WHERE clause to WHERE status = 2 AND DATE_FORMAT(timestamp, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m') -
Trying to get a several rows and colums with data.
Barand replied to rvdveen27's topic in MySQL Help
Have you included the line that increments the rank inside the foreach loop? ++$rank; // increment rank -
select rows from right table based on a column in left table
Barand replied to straygrey's topic in MySQL Help
The second query should be "... FROM Accounts LEFT JOIN Transactions ..." Don't use "SELECT * ", specify the columns needed. You should be storing the Account IDs as foreign keys in the transactions table, not the account names. Are you sure the account names in the tables match exactly (no spelling errors or extra whitespace)? -
Trying to get a several rows and colums with data.
Barand replied to rvdveen27's topic in MySQL Help
I wondered if you were still running queries inside a loop but apparently not. However, your were looping twice through the results. I have put the code I gave you for the rank in its correct place and removed the superfluous loop. (See comments) <?php // ob_start(); REMOVE, not required require('extra/header.php'); if(empty($_SESSION['user'])) { header("Location: login.php"); exit; } if($_SESSION['verifypend'] == 1) { header("Location: verifypend.php"); exit; } ini_set('display_errors', 1); error_reporting(E_ALL); $query = " SELECT u.username ,SUM(price) as price ,SUM(costs) as costs ,SUM(cargodamage) as cargodamage ,SUM(price - costs - cargodamage) as profit ,COUNT(driver) as 'deliveries' ,SUM(distance) as 'distance' FROM drive_routes dr INNER JOIN users u ON u.id = dr.driver WHERE status = 2 GROUP BY driver ORDER BY profit DESC "; try { $stmt = $db->prepare($query); $result = $stmt->execute(); } catch(PDOException $ex) { die("Failed to run query: " . $ex->getMessage()); } $rows = $stmt->fetchAll(); $count = $stmt->rowcount(); //$rank = 1; REMOVE // while ($rows) REMOVE // { // output row with $rank REMOVE // ++$rank; // increment it REMOVE // } REMOVE ?> <center><img src="http://pro-quest.co.uk/ITRecruitmentAgencyImages/Under_Construction-section.jpg" width="15%"></center><br> <div class="container"> <h1>Current rankings</h1> <div class="table-responsive"> <table class="table table-striped"> <thead> <tr> <th>#</th> <th>Driver</th> <th>Profit</th> <th>Deliveries</th> <th>Distance</th> </tr> </thead> <?php // THIS SECTION BELOW IS WHERE THE REMOVED CODE SHOULD BE foreach($rows as $row): $rank = 1; ?> <tbody> <tr> <td><?php echo $rank; ?></td> // output rank <td><?php echo htmlentities($row['username'], ENT_QUOTES, 'UTF-8'); ?></td> <td>€<?php echo htmlentities($row['profit'], ENT_QUOTES, 'UTF-8'); ?></td> <td><?php echo $row['deliveries']; ?></td> <td><?php echo htmlentities($row['distance'], ENT_QUOTES, 'UTF-8'); ?> KM</td> </tr> </tbody> <?php ++$rank; // increment rank endforeach; ?> </table> </div> </div> <?php require('extra/footer.php'); ?> -
Trying to get a several rows and colums with data.
Barand replied to rvdveen27's topic in MySQL Help
Can we see the whole page. -
Do you mean the table would look like this, where user A is both Admin and Super User? mysql> SELECT * FROM permissions; +----+----------+------------+ | id | username | level | +----+----------+------------+ | 1 | A | Admin | * | 2 | B | Moderator | | 3 | C | Admin | | 4 | D | Super User | | 5 | E | Moderator | | 6 | A | Super User | * +----+----------+------------+ then WHERE level = 'Admin' AND level = 'Super User' will not find any records as there is no single record that has both values at the same time (impossible) mysql> SELECT username -> FROM permissions -> WHERE level = 'Admin' AND level = 'Super User'; Empty set (0.00 sec) Using OR instead of AND would produce mysql> SELECT username -> FROM permissions -> WHERE level = 'Admin' OR level = 'Super User'; +----------+ | username | +----------+ | A | | C | | D | | A | +----------+ However, to find only users with both mysql> SELECT A.username -> FROM permissions A -> INNER JOIN -> permissions B -> ON A.username = B.username -> AND A.level = 'Admin' -> AND B.level='Super User'; +----------+ | username | +----------+ | A | +----------+ Back to the original question. From the two arrays, $admins and $superusers, to find who is in both arrays use array_intersect() $admins = array ('A', 'C'); $superusers = array ('D', 'A'); $both = array_intersect($admins, $superusers); echo '<pre>',print_r($both, true),'</pre>'; /** RESULT ***** Array ( [0] => A ) ****************/
-
WHERE level = 'Admin' AND level = 'Super User' would require level to have 2 values at the same time ??? Perhaps you mean WHERE level = 'Admin' OR level = 'Super User'
-
$csv = fopen('my.csv', 'r'); $data = array(); while (list($contact_email, $contact_last, $contact_first) = fgetcsv($csv, 1024)) { $data[] = "('$contact_first', '$contact_last', '$contact_email')"; // order matches SQL INSERT order } fclose($csv); // use multiple insert $sql = "INSERT INTO contact (contact_first,contact_last, contact_email) VALUES "; $sql .= join(',', $data); $mysqli->query($sql);