-
Posts
24,603 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
PHP function to convert Hex to HSL (Not HSL to Hex)
Barand replied to thara's topic in PHP Coding Help
Not quite. var_dump($delta) gives float(0), therefore the first branch needs to be either if ($delta === 0.0) { or if ($delta == 0) { -
PHP function to convert Hex to HSL (Not HSL to Hex)
Barand replied to thara's topic in PHP Coding Help
$templatePrimaryColor = '555555'; echo '<pre>',print_r(hexToHsl($templatePrimaryColor)).'</pre>'; -> Warning: Division by zero in C:\inetpub\wwwroot\test\winuser\noname3.php on line 14 -
PHP function to convert Hex to HSL (Not HSL to Hex)
Barand replied to thara's topic in PHP Coding Help
Yes, if all 3 components are equal then $delta is zero, giving a division by zero error. -
PHP function to convert Hex to HSL (Not HSL to Hex)
Barand replied to thara's topic in PHP Coding Help
Your method has a fatal problem with greys (ie when R = G = B) -
A php function - retrieval ban for present and future?
Barand replied to samanj's topic in PHP Coding Help
Restrict your db query with a where clause so you only retrieve the records you want SELECT ... WHERE datecol BETWEEN input_date AND CURDATE() - INTERVAL 1 DAY -
Change your query to retrieve the extra item and restructure the $data array to store it. $data = []; $res = $conn->prepare("SELECT name , email -- extra item , month(month) as mno , paid FROM fee WHERE month >= ? ORDER BY name, month "); $res->execute([$start]); foreach ($res as $row) { if (!isset($data[$row['name']])) { $data[$row['name']] = [ 'email' => $row['email'], 'pays' => $empty_array ]; } $data[$row['name']]['pays'][$row['mno']] = $row['paid']; }
-
Was This A Php Issue Or An Html5 Drop Down Issue ?
Barand replied to 2020's topic in PHP Coding Help
It's neither a PHP thing nor a HTML5 thing - it's a plain, old HTML <select> thing. By default, if none of the options have their selected attribute set, the first option is shown as selected. -
So the user doesn't have to guess which radio button is for "Male" and which is for "Female" of course.
-
No. \ is the escape character so needs to be \\ in a dir path. The final \ also needs to be \\ as it is currently escaping the quote at the end of the string. Easier is to use / in paths (even on windows)
-
When you use <label for="xxx"> then the xxx should be the id of the object being labelled. This is useful with radio buttons or checkboxes and enables the user to click either the object or the label to check or uncheck. In your examples, <label for="yes"> is wrong since "yes" is not an id of anything.
-
When you get a keyboard that adds indenting and line breaks I'll read your code.
-
I prefer option 4. EG mysqli_report(MYSQLI_REPORT_ALL|MYSQLI_REPORT_STRICT); $conn = mysqli_connect('localhost', 'someuser', 'wrong_password', 'test');
-
Upgrading my webpages tot PHP 7.4.2
Barand replied to Yann63's topic in PHP Installation and Configuration
You actually have choice of mysqli or PDO to replace your mysql.* functions. Don't be fooled into thinking the easier route must mysqli because it's spelt almost the same. PDO is the simpler of the two interfaces. -
Statement with multiple joins and field with CSV in it
Barand replied to mongoose00318's topic in MySQL Help
DATA TABLE: mongoose +----+---------+ | id | testcol | +----+---------+ | 1 | 1 | | 2 | 2 | | 3 | 3 | | 4 | 2,3 | | 5 | 1,4 | | 6 | 2,5 | | 7 | 1,3 | | 8 | 2,4 | +----+---------+ Find records in mongoose where testcol contains 1 or 3 ... mysql> SELECT DISTINCT id, testcol -> FROM mongoose -> JOIN ( -> SELECT 1 as n -> UNION SELECT 3 -> ) nums ON FIND_IN_SET(n, testcol) -> ; +----+---------+ | id | testcol | +----+---------+ | 1 | 1 | | 3 | 3 | | 4 | 2,3 | | 5 | 1,4 | | 7 | 1,3 | +----+---------+ edit: The subquery effectively gives you a temporary table "nums" ... TABLE: nums +---+ | n | +---+ | 1 | | 3 | +---+ -
Statement with multiple joins and field with CSV in it
Barand replied to mongoose00318's topic in MySQL Help
Table subquery ? -
$hours_per_day = 6; $total_hours = 20; $days = floor($total_hours / $hours_per_day); $hours_remaining = $total_hours - $days * $hours_per_day; echo "$days days and $hours_remaining hours" ; //--> 3 days and 2 hours
-
Small business needs help creating PHP interview questions
Barand replied to aadamsx's topic in PHP Coding Help
@Jokeh There's a good chance that the question is no longer relevant after nearly 2 1/2 years- 7 replies
-
- application
- full-stack
-
(and 1 more)
Tagged with:
-
Ensure users have to log in before they can vote so you know their user_id. When they vote, store the poll_id and user_id. Put a unique constraint on (poll_id, user_id) so that combination can not be added twice.
-
Fixed. What editor are you using? <?php include 'functions.php'; // Connect to MySQL $pdo = pdo_connect_mysql(); // If the GET request "id" exists (poll id)... if (isset($_GET['id'])) { // MySQL query that selects the poll records by the GET request "id" $stmt = $pdo->prepare('SELECT * FROM polls WHERE id = ?'); $stmt->execute([$_GET['id']]); // Fetch the record $poll = $stmt->fetch(PDO::FETCH_ASSOC); // Check if the poll record exists with the id specified if ($poll) { // MySQL query that selects all the poll answers $stmt = $pdo->prepare('SELECT * FROM poll_answers WHERE poll_id = ?'); $stmt->execute([$_GET['id']]); // Fetch all the poll anwsers $poll_answers = $stmt->fetchAll(PDO::FETCH_ASSOC); // If the user clicked the "Vote" button... if (isset($_POST['poll_answer'])) { // Update and increase the vote for the answer the user voted for $stmt = $pdo->prepare('UPDATE poll_answers SET votes = votes +1 WHERE id = ?'); $stmt->execute([$_POST['poll_answer']]); // Redirect user to the result page header ('Location: result.php?id=' . $_GET['id']); exit; } } else { die ('Poll with that ID does not exist.'); } } else { die ('No poll ID specified.'); } ?> <?=template_header('Poll Vote')?> <div class="content poll-vote"> <h2><?=$poll['title']?></h2> <p><?=$poll['des']?></p> <form action="vote.php?id=<?=$_GET['id']?>" onSubmit="disable()" method="post"> <?php for ($i = 0; $i < count($poll_answers); $i++): ?> <label> <input type="radio" name="poll_answer" value="<?=$poll_answers[$i]['id']?>" <?=$i == 0 ? ' checked' : ''?>> <?=$poll_answers[$i]['title']?> </label> <?php endfor; ?> <div> <input type="submit" name="submit" value="Vote"> <a href="result.php?id=<?=$poll['id']?>">View Result</a> </div> </form> </div> <?=template_footer()?>
-
I created an extra table to define which category the values were in mysql> select * from catval; +-----+------+ | val | cat | +-----+------+ | 1 | 4 | | 2 | 4 | | 3 | 4 | | 4 | 4 | | 5 | 3 | | 6 | 3 | | 7 | 2 | | 8 | 2 | | 9 | 1 | | 10 | 1 | +-----+------+ then $sql = "SELECT a.cat as cata , b.cat as catb FROM datatb d JOIN catval a ON d.grpa = a.val JOIN catval b ON d.grpb = b.val "; $result = $db->query($sql); //categories $cat = [ 4 => ['name'=>'1:4', 'recs'=>[]], 3 => ['name'=>'5:6', 'recs'=>[]], 2 => ['name'=>'7:8', 'recs'=>[]], 1 => ['name'=>'9:10','recs'=>[]] ]; $n = 0; while ($row = $result->fetch_assoc()) { $cat[$row['cata']]['recs'][$n][] = $row['cata']; $cat[$row['catb']]['recs'][$n][] = $row['catb']; $n++; } // the output echo "<table border='1' style='width:500px; border-collapse:collapse;'>"; foreach ($cat as $c) { echo "<tr><th>{$c['name']}</th>"; for ($i=0; $i<$n; $i++) { echo '<td style="text-align:center;">' . (isset($c['recs'][$i]) ? join(',', $c['recs'][$i]) : '–') . "</td>"; } echo "</tr>\n"; } echo "</table>\n";
-
Why don't you reveal the data in the datatb table so we can see the input. Then show us what the output should look like from that data. That way we might able to see the path from one to the other.
-
Looking for a string within some text and wrapping it with a link
Barand replied to mongoose00318's topic in PHP Coding Help
Are you sure you have correct path - those names don't have much in common with the sample filenames that you posted earlier. Given the volume, it will better to chunk the $names array and add 1000 records per query. // populate the drawings table $chunks = array_chunk($names, 1000); foreach ($chunks as $ch) { $db->exec("INSERT IGNORE INTO drawings (drawing) VALUES " . join(',', $ch)); } -
$table .= $columnKey ?
-
Looking for a string within some text and wrapping it with a link
Barand replied to mongoose00318's topic in PHP Coding Help
$db should be a valid PDO connection. Change to $pdo if that's yours. -
Looking for a string within some text and wrapping it with a link
Barand replied to mongoose00318's topic in PHP Coding Help
Is this faster? $db->exec("DROP TABLE IF EXISTS drawings"); $db->exec("CREATE TABLE drawings (drawing varchar(20) not null PRIMARY KEY)"); $files = glob('files/*.*'); foreach ($files as $f) { $names[] = "('" . pathinfo($f, PATHINFO_FILENAME) . "')"; } // populate the drawings table $db->exec("INSERT IGNORE INTO drawings (drawing) VALUES " . join(',', $names)); // now delete those drawings NOT found in production table $db->exec("DELETE d FROM drawings d LEFT JOIN production_data p ON locate(d.drawing, p.description) WHERE p.description IS NULL; ");