-
Posts
15,229 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
If you make changes to the database then that means changes to the underlying file, right? You can know if there were changes if the timestamp changes.
-
This is really just templating. Just about any templating solution will work. Do you really want the input and template files to be valid PHP code? Doesn't seem like a good idea to me. I mean, it's not like you can execute them as they are now. How about simpler stuff like (input.ini) colour = "brown" animal = "cat" (template.php.tpl) <?php echo "<p>This is a {{colour}} $animal.</p>"; <?php $variables = parse_ini_file("input.ini"); $template = file_get_contents("template.php.tpl"); $pairs = array(); foreach ($variables as $name => $value) { $pairs["{{" . $name . "}}"] = $value; } echo strtr($template, $pairs);
-
Modification time of the SQLite file?
-
Timestamp. Versioning. Deltas. Stuff like that. Hashes can tell you that something changed but won't help you identify what it was.
-
"$resp->Ack" would only have worked if was a child of the root element. Sounds like it wasn't, but I can't be sure because you didn't post the XML you're working with.
-
1. The PHP is irrelevant. Only the HTML it outputs matters. 2. Actually it kinda does. Those three selectors are all essentially "if"s: if this matches, or if that matches, or if the other one matches, then...
-
If you're taking the approach of putting an ID on the body then you can do everything with pure CSS. <body id="home"> <ul id="menu"> <li id="menu-home"> <a href="/index">Home</a> </li> </ul> /* something along the lines of */ body#home #menu #menu-home a, body#foo #menu #menu-foo a, body#bar #menu #menu-bar a { whatever; }
-
Because that's all the "simple" syntax allows: one property. If you're looking for a rationale from the PHP developers as to why only one property indirection is permitted then you're probably going to have to ask them directly. [edit] Ohhh, you mean why is it an error. Not why is it not allowed. Nevermind.
-
Right, they're the same for particular types of items, but not for all items. That means the data structure will have to vary somehow, and you can accomplish that with a JSON string or by creating an arbitrary array. To refine the example I gave earlier, <input type="hidden" name="items[0]" value="door"> <input type="hidden" name="options[0][opening]" value="chain"> <input type="hidden" name="options[0][numwindows]" value="2"> <input type="hidden" name="options[0][storey]" value="1">0 is the first item added to the order. It is a "door". The door comes with multiple options, which arrive in your code as an array in $_POST. $option_keys = array( "door" => array("opening", "numwindows", "storey") ); $items = array(); foreach ($_POST["items"] as $n => $type) { if (!isset($option_keys[$type])) { // error: invalid item type continue; } $item = array("type" => $type, "options" => array()); if (isset($_POST["options"][$n])) { // extract options from the form and validate against $option_keys $item["options"] = array_intersect_key($_POST["options"][$n], array_flip($option_keys[$type])); if (count($item["options"]) != count($option_keys[$type])) { // error: not all options set in form continue; } } $items[$n] = $item; } // $items = array( // 0 => array( // type => "door", // options => array( // opening => "chain", // numwindows => 2, // storey => 1 // ) // ) // )The JSON option isn't that much different. <input type="hidden" name="items[0][type]" value="door"> <input type="hidden" name="items[0][options]" value="{"opening":"chain","numwindows":2,"storey":1}"> $option_keys = array( "door" => array("opening", "numwindows", "storey") ); $items = array(); foreach ($_POST["items"] as $n => $item) { if (!isset($item["type"], $option_keys[$item["type"]])) { // error: invalid item type continue; } if (!isset($item["options"])) { $item["options"] = array(); } // extract options from the form and validate against $option_keys $options = array_intersect_key($item["options"], array_flip($option_keys[$item["type"]])); if (count($options) != count($option_keys[$item["type"]])) { // error: not all options set in form continue; } $item["options"] = $options; $items[$n] = $item; } // $items = array( // 0 => array( // type => "door", // options => array( // opening => "chain", // numwindows => 2, // storey => 1 // ) // ) // )And there are multiple variations possible for both of those, depending on what's easiest to work with both in the Javascript and the PHP.
-
JSON might be useful if the inputs vary a lot - like there isn't a consistent structure every time you prompt for particular details regarding an item. Make sure to validate it on the next page so that someone can't tamper with the data before submitting the form. The normal answer is to use arrays, which could also help here but probably isn't the only thing you need. <input type="hidden" name="whatever[]" value="1"> <input type="hidden" name="whatever[]" value="2"> <input type="hidden" name="whatever[]" value="3">and $_POST["whatever"] is an array.
-
Compare $data between the working and non-working versions to find out what the difference is.
-
Need a conditional statement inside of a link to echo div class
requinix replied to harshclimate's topic in PHP Coding Help
An easy way to determine which file the user is looking at would be basename($_SERVER["REQUEST_FILENAME"])That'll be "index.php" or "index-02.php" or whatever. Put that value into a variable then test it for each of the links: if it matches then show the class, otherwise don't. class="active">01- 3 replies
-
- php
- conditional statment
-
(and 1 more)
Tagged with:
-
:/ It's running from within PHP so why would it be not be affected by PHP settings?
-
On how to do... what? There are multiple options here that you should do some research on and think about before jumping right into the code.
-
Either change the link so that it takes them to the purchase page, or make the download link redirect the user (with or without a warning) to the purchase page. When they buy it, redirect them back to the initial page they were on - the one with the link they clicked. If it's not obvious, you never link to the actual music file. Downloads should always be handled by a PHP script which authenticates the user before directly outputting the music file. Really the music itself shouldn't be located anywhere on your server in a place that someone could access it over the web.
-
i want to do a data-backup of a old notebook - with knoppix
requinix replied to dil_bert's topic in Miscellaneous
Step 3: copy the data. Where's the confusion? -
Make HTTP GET request with cURL from Wowza Rest API
requinix replied to Texan78's topic in PHP Coding Help
Referring to the last line: $streamStatus = $obj->isConnected?'true':'false'; -
As the docs say, brpoplpush - which you can read as a "b"locking "r"ight "pop" and "l"eft "push" - deals with two lists, and moves one element from one to the other. If all you need is a simple queue with blocking then do lpush+brpop or rpush+blpop (whichever "direction" makes most sense to you).
-
Anecdotally and without any sort of source to back me up, you shouldn't do an indefinite timeout on a blocking function. I think that's from personal experience. Do a "long" timeout of less than a minute, then worst case your loop just jumps back to the start and it starts blocking again immediately.
-
Make HTTP GET request with cURL from Wowza Rest API
requinix replied to Texan78's topic in PHP Coding Help
You lost the CURLOPT_RETURNTRANSFER option from your first post. Need that. -
Measure the time yourself. $start = time(); whatever loop { $remaining = $limit - (time() - $start); blocking function with timeout of $remaining if possible if function timed out or time() > $start + $limit then die }
-
Make HTTP GET request with cURL from Wowza Rest API
requinix replied to Texan78's topic in PHP Coding Help
The formatting doesn't matter - those two JSON samples are equivalent. $obj is an object by default. You can work with that just fine. It doesn't have to be an array. But if you really want an array then check the documentation that Barand linked to. -
Make HTTP GET request with cURL from Wowza Rest API
requinix replied to Texan78's topic in PHP Coding Help
Are you running PHP from the same machine that you tried with the browser? A timeout suggests the connection is blocked, like by a firewall. -
Then rather than watching a file try message queues: process that receives the AJAX requests sends a message to a queue while the processes that talk to clients wait (again, with blocking) for a message to arrive on their particular queue. Software like Redis and (IIRC) Memcached can also do blocking queues, if you have anything like that already in place. If the data is small then the message could contain it, otherwise all it has to do is act as a signal that the receiving process needs to check the database. Point is to avoid polling.