-
Posts
24,302 -
Joined
-
Last visited
-
Days Won
792
Posts posted by Barand
-
-
Pretty much like estimating how long it will take to write a program
The first 80% takes 80% of the time. The last 20% takes another 80% of the time.
- 1
-
For future reference, I would have helped but I had a problem loading that picture of your data into a test table.
Normally I would load posted data into a test table to work on a problem but queries wouldn't work with all the data in a blob field.
-
Why set a superflous boolean variable when you have a perfectly good boolean expression already. All you are doing is adding an extra step
$too_many_labels will have the same value as $numberoflabels > 4
I'd go for option 1 or option 3, which would be
// style 3 $labelCounter = $db->prepare("SELECT count(*) ... "); // mySQL counts labels if($numberoflabels > 4) { echo "Sorry visitor, no label could be created"; } else { // RUN BIG CURL SCRIPT IF LESS THAN 5 LABELS // LONG CURL SCRIPT GOES HERE $log = $db->prepare("INSERT into label_counter... // log the good label }
- 1
-
Switch to PDO. It's much better than mysqli.
-
Have you tried restarting the server since you made the ini changes?
-
Check in your extensions folder to see what the names should be EG
-
The next "Fortnite" perhaps? ?
-
Extension names begin with php_
(windows)
extension=php_mysqli.dll
(linux)
extension=php_mysqli.so
-
With all the effort you are putting into this it sounds like more than just an April 1st event. Christmas with elves, reindeer and santas perhaps? Easter eggs and bunnies? Thanksgiving turkey shoot?
-
I give up. Just getting towards a 500 score when I accidentally clicked the Activity tab - back to zero!. I know, I should get a life.
-
I see you have also increased the difficulty level and got them all breeding like rabbits
-
Do we score any points in today's "duck shoot"?
-
Check your php.ini file. Ensure mysqli extension is enabled.
Also, phpinfo() will tell you - if it is you will have a mysqli section.
-
try something like this example
<script type="text/javascript"> function myFunction(myform) { return myform.selA.value != '' || myform.textB.value != '' } </script> <form action="" onsubmit="return myFunction(this)"> <select name='selA'><option value=''>- select -</option><option>AAAAAAAA</option><option>BBBBBBBBB</option></select> <input type="text" name="textB"> <input type="submit" name="btnSub" value="Submit"> </form>
-
7 hours ago, ginerjm said:
I would move the onsubmit to a submit button element
... and pray that the user doesn't hit the Enter button while in the text box to submit the form
-
2 hours ago, requinix said:
As opposed to PHP's && and ||, which are actually subtly different than "and" and "or".
Just to confirm Requinix's statement by psedocode examples
This works:
result = query(sql) or die(error message)
Whereas this doesn't
result = query(sql) || die(error message)
-
In MySQL you use backticks "`" around identifiers when the identifier name is a reserved keyword or contains a space or other special characters. In your code they would not be necessary.
In Postgres a different character from the backtick is used in those circumstances. The manual will tell you which.
While most RDMS systems have a standard core SQL there are variations between the various dialects. You have to be aware of them.
-
You can't use them for column and table names, they got that correct, but I have never had a problem when using LIMIT ?,?
-
Try reading your own code. Go through it line by line and check the value of each variable after each line executes. Does it look right to you? (you should end up with 0, 1, 5)
vales after executing line ----------------------------- wallet balance amount 3 3 5 if($wallet + $balance >= $amount) { 3 3 5 $wallet = (string)($wallet - $amount); -2 3 5 //}elseif $wallet = 0; { $balance = ($balance - $amount); -2 -2 5
-
try something like this
$amount = 5; $wallet = 3; $balance = 3; if ($wallet >= $amount) { $wallet -= $amount; } elseif ($wallet + $balance >= $amount) { $amount_remain = $amount - $wallet; $wallet = 0; $balance -= $amount_remain; } else { echo "Insufficient funds<br>"; } echo "W: $wallet<br>B: $balance";
-
You can use
WHERE question_id IN (46, 47, 51)
-
I find the easiest way to do these is to get the data you need then store in an array that is structured to match the required output. Then create your output from the array.
DATA
SELECT * FROM test.wp_lvsz_evr_attendee; SELECT * FROM test.wp_lvsz_evr_answer; +-----+-----------------+-------+-------+----------+ +-----------------+-------------+--------+ | id | registration_id | lname | fname | event_id | | registration_id | question_id | answer | +-----+-----------------+-------+-------+----------+ +-----------------+-------------+--------+ | 459 | 1 | Doe | John | 8 | | 1 | 40 | aaa | | 460 | 2 | Evans | Jane | 9 | | 1 | 41 | bbb | | 461 | 3 | Smith | Dave | 8 | | 1 | 42 | ccc | | 462 | 4 | Jones | Alec | 9 | | 1 | 43 | ddd | +-----+-----------------+-------+-------+----------+ | 2 | 40 | eee | | 2 | 41 | fff | | 2 | 42 | ggg | | 2 | 43 | hhh | | 3 | 40 | kkk | | 3 | 41 | mmm | | 3 | 42 | nnn | | 3 | 43 | ooo | | 4 | 40 | ppp | | 4 | 41 | qqq | | 4 | 42 | rrr | | 4 | 43 | sss | +-----------------+-------------+--------+
QUERY
SELECT att.id , concat( lname, ' ', left( fname, 1 ) ) AS fullname , question_id , answer FROM wp_lvsz_evr_answer ans JOIN wp_lvsz_evr_attendee att ON att.registration_id = ans.registration_id AND question_id BETWEEN 41 AND 43; +-----+----------+-------------+--------+ | id | fullname | question_id | answer | +-----+----------+-------------+--------+ | 459 | Doe J | 41 | bbb | | 459 | Doe J | 42 | ccc | | 459 | Doe J | 43 | ddd | | 460 | Evans J | 41 | fff | | 460 | Evans J | 42 | ggg | | 460 | Evans J | 43 | hhh | | 461 | Smith D | 41 | mmm | | 461 | Smith D | 42 | nnn | | 461 | Smith D | 43 | ooo | | 462 | Jones A | 41 | qqq | | 462 | Jones A | 42 | rrr | | 462 | Jones A | 43 | sss | +-----+----------+-------------+--------+
CODE
<?php $res = $db->query("SELECT att.id , concat( lname, ' ', left( fname, 1 ) ) AS fullname , question_id , answer FROM wp_lvsz_evr_answer ans JOIN wp_lvsz_evr_attendee att ON att.registration_id = ans.registration_id AND question_id BETWEEN 41 AND 43 "); $headings = [ 42 => 'Belt' , 43 => 'Event' , 41 => 'School' ]; $temp_array = array_fill_keys(array_keys($headings), ''); // array for each attendee to be filled in fro query results // process query results and place in array with attendee as the key $data = []; foreach ($res as $r) { if ( !isset($data[$r['id']])) { $data[$r['id']] = [ 'name' => $r['fullname'], 'answers' => $temp_array ] ; } $data[$r['id']]['answers'][$r['question_id']] = $r['answer'] ; // store answer in its array position } // now we can easily output the array into an html table $theads = "<tr><th>Name</th><th>" . join('</th><th>', $headings) . "</th></tr>\n"; $tdata = ''; foreach ($data as $att) { $tdata .= "<tr><td>{$att['name']}</td><td>" . join('</td><td>', $att['answers']) . "</td></tr>\n"; } ?> <table border='1' style='border-collapse: collapse; width: 600px'> <?=$theads?> <?=$tdata?> <?table>
RESULT
-
What are the table structures? I can't tell from your query which table all the relevant columns belong to.
-
An insert will typically take hundredths of a second (depending on key complexity). If you are timing out you have a bigger problem. Check the connection, that's often the slower part.
- 1
help with a registration form
in PHP Coding Help
Posted
You use password_verify() to verify passwords.