Jump to content

Barand

Moderators
  • Posts

    24,566
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. As you posted echo $result["fromAddress"]["phone"]; works if $result is an array. If it's an object you need echo $result->fromAddress->phone;
  2. try form code echo "<table>"; for ($i=1; $i<=5; $i++) { echo <<<FORM <tr> <td style="width:70%;">Item $i</td> <td class="text-center"> <input type="hidden" name="equipmentId[$i]" value="$i"> <input name="equipmentQty[$i]" class="eqQty text-center up" type="text"> </td> </tr> FORM; } echo "</table>"; processing code if ($_SERVER['REQUEST_METHOD']=='POST') { $jobId = $_SESSION['current_job_id']; // prepare insert query $insert = $db->prepare("INSERT INTO ssm_equipment_order (job_id, equipment_id, equipment_quantity) VALUES (?,?,?) "); foreach ($_POST['equipmentId'] as $k => $eid) { if ($_POST['equipmentQty'][$k] > 0) { $data = [ $jobId, $eid, $_POST['equipmentQty'][$k] ] ; $insert->execute($data); } } }
  3. 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
  4. 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";
  5. You can use WHERE question_id IN (46, 47, 51)
  6. 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
  7. What are the table structures? I can't tell from your query which table all the relevant columns belong to.
  8. 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.
  9. An error code perhaps?
  10. Regardless of that interpretation, the manual makes it clear what it does and when to use it, and you claim to have read that.
  11. @phpsane It really is a waste of our time replying to your posts, isn't it? Prior to your posting that solution, two people had told you that you don't need mysqli_stmt_free_result(), and why you don't need it. Yet, still, there it is.
  12. You could try finding out what the text actually contains (seems like there are no spaces) $text = wpjm_the_job_description(); $short = substr($text,0,25); // get first 25 characters $chrs = str_split($short); // split into individual chars $hex = array_map('bin2hex', $chrs); // get the hex values of those chars echo '<pre>', print_r($chrs, 1), '</pre>'; // output to compare echo '<pre>', print_r($hex, 1), '</pre>'; // output to compare What is the output?
  13. Try $text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci. Aenean nec lorem."; $words = array_slice(explode(' ', $text), 0, 15); echo join(' ', $words) . '…';
  14. Then why not use one of those
  15. My guess is that 'B' is the char in position 6 of a string. But without more code and data that remains a guess.
  16. Is that your entry for this month's "Most Ridiculous Solution" competition? I have recreated the table from your CREATE TABLE code (except I changed the primary key to a column that actually exists in the table) and tried your function. Negative "stack" values were written without problem. I applaud your attempt at debugging to see which of the two queries is executed but it fails miserably as HERE1 is echoed regardless of which path the logic takes. What is the condition supposed to be (in business terms, forget you're a programmer) for the first query to execute instead of the second? It currently always executes unless there is negative stack value to begin with. When I ran it with a stack value of 5 and QUA value of (leaving 4 ) the "DOD" still said "Item is not there, Maybe in ..."
  17. $LNTerm = 60; $LNUnit = 'D'; $dt = new DateTime('2017-02-01'); $di = new DateInterval("P$LNTerm$LNUnit"); $dt->add($di); echo $dt->format('Y-m-d'); //--> 2017-04-02 $days_until = $dt->diff(new DateTime())->days; echo "<br>$days_until"; //--> 19
  18. Both are equally capable of providing prepared queries or insecure code
  19. $num_recs = 5; for ($count=1; $count<=$num_recs; $count++) { echo "$count of $num_recs<br>"; } But I could give you a more relevant example if you could get around to posting the code you have at present.
  20. Use a counter and increment it
  21. What is the table structure? SHOW CREATE TABLE items;
  22. Can you be more specific? "uuid" crops up in two different levels in that data and there are no objects.
  23. Probably not what you want but there may be something in here that might help $dt = new DateTime('2017-01-01'); $dt->modify('next monday'); $di7 = new DateInterval('P7D'); $dp = new DatePeriod($dt, $di7, 52); echo "<pre>\nWeek Monday Friday \n"; $i=0; foreach ($dp as $d) { printf("%3d %-12s%-12s\n", ++$i, $d->format('Y-m-d'), $d->modify('+4 days')->format('Y-m-d')); }
×
×
  • 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.