-
Posts
24,572 -
Joined
-
Last visited
-
Days Won
824
Everything posted by Barand
-
Split array every 3 commas & return as string?
Barand replied to AquariaXI's topic in PHP Coding Help
If you just echo the contents of the file, it will all be on one line as newlines (and other whitespace) are ignored by HTML. Try echo '<pre>' . file_get_contents('myfile.txt') . '</pre>'; or open the file in an editor -
On this page it clearly states
-
Something like adding a line of code inside your resetCamera() fuction eg console.log("resetting camera now") so you can see in the log that it was called OK
-
I make it 3 if include the correction to your SQL syntax
-
Unsure why I cannot see the table i'm doing a join on
Barand replied to Fishcakes's topic in MySQL Help
You could, but using * in a select is rarely a good idea. -
There are some problems with your approach. For ON DUPLICATE KEY to work, the session_id column would also have to be defined as UNIQUE Your random_number column is defined a VARCHAR(6), so if you concatenate another 6 characters, where can they go? Then INSERT INTO mytable (Session_id,Random_Number) VALUES (?, ?) ON DUPLICATE KEY UPDATE Random_Number = CONCAT(Random_number, VALUES(Random_Number) )
-
Unsure why I cannot see the table i'm doing a join on
Barand replied to Fishcakes's topic in MySQL Help
Then add "avatar" to the list of columns you are selecting (SELECT clause). You have added it to the tables to select from (FROM clause). -
They both worked when they left the shop. DATA TABLE: johanm (data provided by you) +----+-------+------------+----------+ | id | name | value_from | value_to | +----+-------+------------+----------+ | 2 | Test1 | C1 | L3 | | 3 | Test2 | C3 | T5 | +----+-------+------------+----------+ Query 1 with results... SELECT id , name FROM johanm WHERE FIELD('C4', 'C1', 'C2', 'C3', 'C4', 'C5', 'T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'L1', 'L2', 'L3', 'L4', 'L5') >= FIELD(value_from, 'C1', 'C2', 'C3', 'C4', 'C5', 'T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'L1', 'L2', 'L3', 'L4', 'L5') AND FIELD('L2', 'C1', 'C2', 'C3', 'C4', 'C5', 'T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'L1', 'L2', 'L3', 'L4', 'L5') <= FIELD(value_to, 'C1', 'C2', 'C3', 'C4', 'C5', 'T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'L1', 'L2', 'L3', 'L4', 'L5'); +----+-------+ | id | name | +----+-------+ | 2 | Test1 | +----+-------+ Query 2 with (same) results... (JSON version requires MySQL v5.7.7 +) SELECT id , name FROM johanm j JOIN ( select @jarray := '["C1", "C2", "C3", "C4", "C5", "T1", "T2", "T3", "T4", "T5", "T6", "L1", "L2", "L3", "L4", "L5"]' ) init WHERE SUBSTRING_INDEX(SUBSTRING_INDEX(JSON_SEARCH( @jarray, 'one', j.value_from), ']', 1), '[', -1) + 0 <= SUBSTRING_INDEX(SUBSTRING_INDEX(JSON_SEARCH( @jarray, 'one', 'C4'), ']', 1), '[', -1) + 0 AND SUBSTRING_INDEX(SUBSTRING_INDEX(JSON_SEARCH( @jarray, 'one', j.value_to), ']', 1), '[', -1) + 0 >= SUBSTRING_INDEX(SUBSTRING_INDEX(JSON_SEARCH( @jarray, 'one', 'L2'), ']', 1), '[', -1) + 0; +----+-------+ | id | name | +----+-------+ | 2 | Test1 | +----+-------+
-
If you are running the same query I posted on the same data that you posted you should get the same results as me. So which is different?
-
Try $amount = 28; $change = calcChange($amount); foreach ($change as $v => $n) { echo "$n €$v coins <br>"; } function calcChange($amt) { $coins = [ 10 => 0, 5 => 0, 2 => 0, 1 => 0 ]; foreach ($coins as $v => &$n) { $n = intdiv($amt, $v); $amt -= $n * $v; } return $coins; }
-
Using ORDER BY I get this with your posted data mysql> SELECT offers.heading -> , offers.description -> , offers.image -> , offers.status -> , offers.extent -> , addons.addon_title -> , addons.addon_desc -> , addons.thumb -> , addon_available -> FROM offers -> JOIN offers_addons USING (id) -> JOIN addons USING (idde) -> ORDER BY offers.id; +-------------------+---------------------------+-------------+--------+------------+-------------------+---------------------+-------------+-----------------+ | heading | description | image | status | extent | addon_title | addon_desc | thumb | addon_available | +-------------------+---------------------------+-------------+--------+------------+-------------------+---------------------+-------------+-----------------+ | addon here | addon description | texecoz.png | OFF | 2021-09-13 | new text | new description | default.png | 2021-05-30 | | this is addon | addon another description | texecoz.png | OFF | 2021-09-13 | some text | another description | default.png | NULL | | this is addon | addon another description | texecoz.png | OFF | 2021-09-13 | testing | product description | 0410.jpg | 2021-05-25 | | addon title | new addon description | images.jpg | OFF | NULL | helllo there | the description | alhua.png | NULL | | addon title | new addon description | images.jpg | OFF | NULL | testing | product description | 0410.jpg | 2021-05-25 | | another title | latest addon description | santa.png | ON | 2021-09-13 | testing | product description | 0410.jpg | 2021-05-25 | | another title | latest addon description | santa.png | ON | 2021-09-13 | helllo there | the description | alhua.png | NULL | | this is a heading | the addon description | paxton.png | ON | 2021-09-13 | testing | product description | 0410.jpg | 2021-05-25 | | this is a heading | the addon description | paxton.png | ON | 2021-09-13 | here is more text | latest description | 44445.jpg | NULL | +-------------------+---------------------------+-------------+--------+------------+-------------------+---------------------+-------------+-----------------+
-
That's because you are using GROUP BY. This for aggregations and gives one row per offer_id. Try changing it to ORDER BY
-
You can also do it using JSON functions (which I thought might be more elegant until I hit the problem of extracting the numeric values of the json paths returned by JSON_SEARCH() eg "$.[12]" ) SELECT id , name FROM johanm j JOIN ( select @jarray := '["C1", "C2", "C3", "C4", "C5", "T1", "T2", "T3", "T4", "T5", "T6", "L1", "L2", "L3", "L4", "L5"]' ) init WHERE SUBSTRING_INDEX(SUBSTRING_INDEX(JSON_SEARCH( @jarray, 'one', j.value_from), ']', 1), '[', -1) + 0 <= SUBSTRING_INDEX(SUBSTRING_INDEX(JSON_SEARCH( @jarray, 'one', 'C4'), ']', 1), '[', -1) + 0 AND SUBSTRING_INDEX(SUBSTRING_INDEX(JSON_SEARCH( @jarray, 'one', j.value_to), ']', 1), '[', -1) + 0 >= SUBSTRING_INDEX(SUBSTRING_INDEX(JSON_SEARCH( @jarray, 'one', 'L2'), ']', 1), '[', -1) + 0 ;
-
It's not pretty, but the working with comma-separated lists in SQL never is SELECT id , name FROM johanm WHERE FIELD('C4', 'C1', 'C2', 'C3', 'C4', 'C5', 'T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'L1', 'L2', 'L3', 'L4', 'L5') >= FIELD(value_from, 'C1', 'C2', 'C3', 'C4', 'C5', 'T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'L1', 'L2', 'L3', 'L4', 'L5') AND FIELD('L2', 'C1', 'C2', 'C3', 'C4', 'C5', 'T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'L1', 'L2', 'L3', 'L4', 'L5') <= FIELD(value_to, 'C1', 'C2', 'C3', 'C4', 'C5', 'T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'L1', 'L2', 'L3', 'L4', 'L5');
-
the properties of the DateInterval object that you will need are ->days ->h ->i so you will have some calculation but it's not rocket science. Note there is also a "d" property but that is the number of days as in "Difference = 5 months 3 days 6 hrs"
-
either method: "POST", or $.post (instead of $.ajax or $.get)
-
Splitting multidimensional array based on values
Barand replied to 684425's topic in PHP Coding Help
One problem in this type of app, where you want to output something when there is no data, is you are asking the question "Hands up everyone who isn't here?". Your query needs to know all status_id values to look for. So you need a status table +-----------+ | status | +-----------+ | status_id | | descrip | +-----------+ Example (I added a status 3 as there weren't any of those) USER STATUS +---------+-----------+----------+ +-----------+----------+ | user_id | status_id | username | | status_id | descrip | +---------+-----------+----------+ +-----------+----------+ | 1 | 1 | peterd | | 1 | Status A | | 2 | 1 | lauran | | 2 | Status B | | 3 | 2 | tomd | | 3 | Status C | | 4 | 1 | cheggs | +-----------+----------+ | 5 | 2 | pollyv | | 6 | 2 | pollys | | 7 | 1 | tomc | | 8 | 2 | comet | | 9 | 2 | cupid | | 10 | 1 | donner | | 11 | 1 | blitzen | | 12 | 2 | dancer | | 13 | 2 | prancer | | 14 | 1 | dasher | | 15 | 1 | vixen | +---------+-----------+----------+ query SELECT s.status_id , coalesce(group_concat(u.username order by user_id separator ', '), 'NO DATA') as users FROM status s LEFT JOIN user u USING (status_id) GROUP BY status_id; results +-----------+--------------------------------------------------------------+ | status_id | users | +-----------+--------------------------------------------------------------+ | 1 | peterd, lauran, cheggs, tomc, donner, blitzen, dasher, vixen | | 2 | tomd, pollyv, pollys, comet, cupid, dancer, prancer | | 3 | NO DATA | +-----------+--------------------------------------------------------------+ -
One problem I can see is that you aren't telling your ajax request to use POST so it is probably defaulting to GET Does it work if you change $_POST in script.php to $_GET?
-
You appear to be missing an "if" elseif (isset($_POST['save'])) ^^
-
If only PHP had a way you could increment a count. $i = 0; $content = ' <style> td { font-weight: normal; font-size: 8px; line-height: 12px; color: #000000; } </style> <table id="receiptTable" style="max-height: 1000px;" > <tr> <td width = "7%" > '. ++$i .' </td> <td width= "8%" > '.'xxxxxx'.' </td> <td width= "10%" > '.'xxxxxx'.' </td> <td width= "30%"> '.'123'.' '.'Kg'.' </td> <td width= "20%" > RM '.'123.45'.' </td> <td width= "20%" > RM '.'123.45'.' </td> </tr> <tr> <td width = "7%" > '. ++$i .' </td> <td width= "8%" > '.'xxxxxx'.' </td> <td width= "10%" > '.'xxxxxx'.' </td> <td width= "30%"> '.'123'.' '.'Kg'.' </td> <td width= "20%" > RM '.'123.45'.' </td> <td width= "20%" > RM '.'123.45'.' </td> </tr> <tr> <td width = "7%" > '. ++$i .' </td> <td width= "8%" > '.'xxxxxx'.' </td> <td width= "10%" > '.'xxxxxx'.' </td> <td width= "30%"> '.'123'.' '.'Kg'.' </td> <td width= "20%" > RM '.'123.45'.' </td> <td width= "20%" > RM '.'123.45'.' </td> </tr> </table> '; OUTPUT
- 1 reply
-
- 1
-
PHP runs on the server, javascript runs on the client after the PHP has finish running and sent the page to the client. Store $PAGE in a hidden field in your html <input type="hidden" id="page-name" value="<?=$PAGE?>" > In your script you can then access it with var page = $("#page-name").val() then send it i your ajax request $.post( "script.php", {"page":page}, // data function(content) { $("#notif").html(content) }, "TEXT" ) In script.php, access the page from $_POST['page]