-
Posts
24,606 -
Joined
-
Last visited
-
Days Won
831
Everything posted by Barand
-
No "old farts" that I am aware of.
-
Need help with building a custom serialized function
Barand replied to jcmaad's topic in PHP Coding Help
Possibly. How can I know? Syntax is OK. -
Need help with building a custom serialized function
Barand replied to jcmaad's topic in PHP Coding Help
You'll find that serializing data it not used very much these days, largely abandoned in favour of JSON data $data = [ 'count' => 1, 'total' => 5, 'average' => 5 ]; echo "Serialized: " . serialize($data); echo "JSON: " . json_encode($data);; gives Serialized: a:3:{s:5:"count";i:1;s:5:"total";i:5;s:7:"average";i:5;} JSON: {"count":1,"total":5,"average":5} -
how to get the value of each input of each data I bring from the db?
Barand replied to yami's topic in PHP Coding Help
they aready are -
So just, for example, "SELECT id,name, email FROM ..." so you only retrieve what you need. That's why you shouldn't use "SELECT * " in queries as that retrieves every column, need it or not, and slow your queries. [EDIT] PS That's one of the reasons not to use SELECT *.
-
It seems reasonable to me, given the initial caveat.
-
how to get the value of each input of each data I bring from the db?
Barand replied to yami's topic in PHP Coding Help
You say all but only select a single item. And you don't have a submit button! Where is the $iditemm value coming from? No idea - where is it supposed to come from? -
while (($p1 = strpos($str, 'S', $p2)) !== false) { // while there is a next 'S', get its position $p2 = strpos($str, 's', $p1); // find position of following 's' if ($p2===false) { // if there is no following 's' $p2 = strlen($str); // assume its position is the end of the string } echo substr($str, $p1, $p2-$p1+1) . '<br>'; // echo the characters between the S and s }
-
Store the test dates - that will tell you who got there first.
-
You'll affect performance more, and complicate the queries, by splitting your users across more than one table. It would also break a rule of DB design - don't store derived data
-
+-----------+ | user | +-----------+ | user_id |--------+ | name | | | email | | +-----------------+ | phone | | | answer | +-----------+ | +-----------------+ | | answer_id | +----0<| user_id | | question_no | | selected_choice | +-----------------+ One user table. Query to find which answered 4 questions SELECT u.user_id , u.name FROM user u JOIN answer a USING (user_id) GROUP BY u.user_id HAVING COUNT(answer_id) = 4
-
Is there any chance that you might answer that question sometime soon? (At my age an fear I am running out of the time needed to get you thinking about what your code is doing)
-
There is an absence of DB query code in anything you have posted and you have not explicitly stated the origin of all those values that you are passing in the query string ($_GET data), so here is my guess... Does $_GET['did_ivr_disable'] contain the value from the database that you need? Or have you not thought about it?
-
If you always set it to zero, what other result do expect? I did say that it should be the value from your DB.
-
I'm equally sorry that we are new to telepathic communication and so have no idea what your code is that is giving the result below. Did you implement the method I showed you?
-
That must be annoying.
-
Exactly. As I said, determine which button needs to be shown as selected if the value in the database is 0, then the 0 button needs to be "checked". if the value in the database is 1, then the 1 button needs to be "checked". Example $currentValue = 0; // from DB $chk0 = $currentValue==0 ? 'checked="checked"' : ''; $chk1 = $currentValue==1 ? 'checked="checked"' : ''; echo "<input type='radio' name='myradio' value='0' $chk0> No   <input type='radio' name='myradio' value='1' $chk1> Yes";
-
Determine which button needs to be shown as selected and set its "checked" attribute
-
Always store in the correct format (yyyy-mm-dd hh:ii:ss). Retrieval is flexible... mysql> SELECT name, submitted FROM test WHERE submitted BETWEEN '2022-05-05 09:05:00' AND '2022-05-05 13:30:00'; +-------+---------------------+ | name | submitted | +-------+---------------------+ | Curly | 2022-05-05 10:46:30 | | Larry | 2022-05-05 12:20:30 | +-------+---------------------+ mysql> SELECT name, submitted FROM test WHERE submitted BETWEEN '20220505090500' AND '20220505133000'; +-------+---------------------+ | name | submitted | +-------+---------------------+ | Curly | 2022-05-05 10:46:30 | | Larry | 2022-05-05 12:20:30 | +-------+---------------------+ mysql> SELECT name, submitted FROM test WHERE DATE(submitted) = '2022-05-05' AND TIME(submitted) BETWEEN '09:05:00' AND '13:30:00'; +-------+---------------------+ | name | submitted | +-------+---------------------+ | Curly | 2022-05-05 10:46:30 | | Larry | 2022-05-05 12:20:30 | +-------+---------------------+ mysql> SELECT name, submitted FROM test WHERE DATE(submitted) = '20220505' AND TIME(submitted) BETWEEN '090500' AND '133000'; +-------+---------------------+ | name | submitted | +-------+---------------------+ | Curly | 2022-05-05 10:46:30 | | Larry | 2022-05-05 12:20:30 | +-------+---------------------+
-
My original should also have checked for no more 's' chars. $str = 'S0100111W 00000010 sS0100111R 11101011-sS0100111W 00000010 11101111 sS0100111W 00000010 sS0100111R 11101111-sS0100111W 00000010 11111111 sS0100111W 00000011 sS0100111R 10111100-sS0100111W 00000011 10111101 sS0100111W 00000011 sS0100111R 10111101-sS0100111'; $p1 = $p2 = 0; while (($p1 = strpos($str, 'S', $p2)) !== false) { $p2 = strpos($str, 's', $p1); if ($p2===false) { // add this check $p2 = strlen($str); } echo substr($str, $p1, $p2-$p1+1) . '<br>'; } giving S0100111W 00000010 s S0100111R 11101011-s S0100111W 00000010 11101111 s S0100111W 00000010 s S0100111R 11101111-s S0100111W 00000010 11111111 s S0100111W 00000011 s S0100111R 10111100-s S0100111W 00000011 10111101 s S0100111W 00000011 s S0100111R 10111101-s S0100111
-
using array_replace on a 2 dimensional array
Barand replied to webdeveloper123's topic in PHP Coding Help
You were close but your arrays were incorrectly defined. This works too $table = array_merge($table, $newdata); $array1 = array( 1 => ['age' => 33] ); $array5 = array( 5 => ['fname' => 'Sandra'] ); $array3 = array( 3 => ['lname' => 'Cunningham'] ); $table2 = array_replace_recursive($table, $array1, $array5, $array3); -
Try $str = 'S1234567 1234567s S1234567 1234567s S1234567 1234567s S1234567 1234567s'; $p1 = $p2 = 0; while (($p1 = strpos($str, 'S', $p2)) !== false) { $p2 = strpos($str, 's', $p1); echo substr($str, $p1, $p2-$p1+1) . '<br>'; } giving S1234567 1234567s S1234567 1234567s S1234567 1234567s S1234567 1234567s
-
What possessed you you to store data in a database like that?