-
Posts
4,705 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
Fatal error: Using $this when not in object context Error message
kicken replied to lovephp's topic in PHP Coding Help
Wherever you got that code from, it expects to be part of a class which has a seems_utf8 function in it. You need to either get the entire class and use it or modify the code to not use $this. If you have a seems_utf8 function, just change the call to remove $this-> and it may work (depending on what the seems_utf8 function looks like). If you don't have that function you'll need to get it. Since it seems like what you may be trying to do is convert the title to ascii for use as a URL slug, you could also just try removing all that and using iconv to convert from the input charset to ascii. For example: <?php function create_slug($title){ //Convert to ascii $slug = iconv('windows-1252', 'ascii//TRANSLIT//IGNORE', $title); //Lowercase and limit length $slug = strtolower(substr($slug, 0, 90)); //Replace whitespace with a - $slug = preg_replace('/\s+/', '-', $slug); //Remove non a-z, 0-9, - characters. $slug = preg_replace('/[^a-z0-9-]+/', '', $slug); //Combine multiple - into a single - $slug = preg_replace('/-+/', '-', $slug); //Strip leading or trailing - $slug = trim($slug, '-'); return $slug; } You may need to adjust your in charset. -
I'm not really sure what your asking. So long as you call createElement each iteration you'll be creating new unique element objects. If you tried to just re-use some element, such as: $elem = $doc->createElement('div'); foreach ($xpath->query('//something') as $something){ $something->appendChild($elem); } Then you'd end up with a document with only a single div appended to the last $something as each call to appendChild would just move it rather than duplicate it. If you're familiar at all with how DOM manipulation works in Javascript, then it works the same way in PHP.
-
PHP code in .html file just shows as PHP... sometimes!
kicken replied to LLLLLLL's topic in PHP Coding Help
Sounds like it is just a common server-configuration problem. If you have a PHP file includeing other files then those files will be parsed for PHP code regardless of their extension or the server's configuration. That is what the include function does, it includes another file as PHP code. Accessing a .html file directly and having the PHP code not be executed means that your setup is not properly configured to apply PHP to .html files. Go over your configuration again and verify it is correct and being loaded by apache. -
Generally when your updating associations like this, you'd just have a complete list of what records should be associated. Rather than try and take that list and compare it to the existing DB to decide what to add/remove, it's simpler to just remove everything then insert the necessary associations. If for some reason you don't think deleting all the old associations will work for you, then explain why that won't work as it's generally uncommon. Think of your many-to-many setup as just a one-to-many setup when it comes to updating it. If your updating the c1 side with new associations, it's like a one-to-many between the c1 value and all the c2 values. If your updating the c2 side, it's just the opposite.
-
No, that flag just makes it return the input strings that do not match, instead of those that do. It doesn't flip the input and pattern parameters.
-
Looks like you have your arguments backwards. I don't think preg_grep is what you want anyway. Just do a loop with preg_match.
-
Storing file modification date in database
kicken replied to NotionCommotion's topic in PHP Coding Help
If you want to ensure the date doesn't accidentally change then storing it in the database when you create the file would probably be the best thing. If you ever decide to move the storage location of the files then the filesystem date may end up changing to the current date/time for all the files making it look like you uploaded everything all at the same time. As far as how to store the date, just use a DATETIME column and store the time using the UTC timezone. When you read it back, do so as UTC then you can convert it to a local time if desired. //Assuming PHP is configured to use the local timezone by default. echo 'Local Time: ', (new DateTime())->format('Y-m-d H:i:s'), PHP_EOL; $dt = new DateTime(); $dt->setTimezone(new \DateTimeZone('UTC')); $store = $dt->format('Y-m-d H:i:s'); echo 'UTC Time: ', $store, PHP_EOL; $dt = new DateTime($store, new \DateTimeZone('UTC')); $dt->setTimezone(new \DateTimeZone(date_default_timezone_get())); echo 'Restored local time: ', $dt->format('Y-m-d H:i:s'), PHP_EOL; -
check value stays unchanged even after form submit?
kicken replied to lovephp's topic in Javascript Help
A cookie would limit the change to only a single browser, only work if they have cookies enabled, and get reset if they ever cleared their cookies. If that's fine for what you need then sure, use a cookie. Use something like JS-Cookie to get/set your cookie. If you need the change to be more permanent then you're back to using a database. -
check value stays unchanged even after form submit?
kicken replied to lovephp's topic in Javascript Help
If you want the change to persist across page loads, then you need to store and retrieve the value from somewhere, such as a database. You can't "sort this out" until you do the database work first. -
There is no need to re-initialize already existing editors, you only need to initialize the one in your new cloned area. You'd do that by finding the editor element in the clone then calling the summernote function on it. $("#add-another").click(function(e) { e.preventDefault(); var clone = $("#meta-clone").clone(); clone.appendTo("#meta-container"); clone.find('.wysiwyg').summernote({height: 150, minHeight: null, maxHeight: null}); }); On another note, if your currently cloning an existing already-initialized editor you should probably not be doing that. The clone should only have the editor placeholder element, then you initialize the editor after cloning.
-
While I've not done any testing, I would assume that using non-capturing groups would be slightly better. However I doubt the difference between the two is worth worrying about unless you're running a particular expression many times in a loop. As a developer, you should inform them that such arbitrary rules are silly and they are doing their uses a disservice. For the last few projects I've worked on I've take the route of using a minimum length + 3 of 5 basic checks. Those checks being: One or more lower case letters One or more upper case letters One or more digits One or more special characters Length of 15 characters or more. It provides a reasonable amount of flexibility while also helping to prevent the use of simple passwords.
-
How is jquery being applied and how can I apply it?
kicken replied to EricOnAdventure's topic in Javascript Help
It doesn't work because your BoxmeGmap(); call in your main.js file is throwing an error which is preventing any further on-load events from running. Either fix this or remove that call for now and then see if it works. -
If you look at the cleaned up version of that output, you can see that the key which contains the values you are interested in is Row. This means you want to be referencing $Grid.Row in your template. array(10) { ["Details"]=> array(0) { } ["HasEditGrant"]=> bool(true) ["CancelUrl"]=> string(28) "unidata.php?operation=return" ["EditUrl"]=> string(32) "unidata.php?operation=edit&pk0=1" ["PrintOneRecord"]=> bool(false) ["PrintRecordLink"]=> string(36) "unidata.php?operation=printrec&pk0=1" ["ExportButtons"]=> array(0) { } ["Title"]=> string(7) "Unidata" ["PrimaryKeyMap"]=> array(1) { ["id"]=> string(1) "1" } ["Row"]=> array(79) { ["University"]=> array(3) { ["Caption"]=> string(10) "University" ["Value"]=> string(24) "Alabama A & M University" ["DisplayValue"]=> string(24) "Alabama A & M University" } ["STABBR"]=> array(3) { ["Caption"]=> string(6) "STABBR" ["Value"]=> string(2) "AL" ["DisplayValue"]=> string(2) "AL" } ["PREDDEG"]=> array(3) { ["Caption"]=> string(7) "PREDDEG" ["Value"]=> string(1) "3" ["DisplayValue"]=> string(1) "3" } ["HIGHDEG"]=> array(3) { Now, what's next depends on what specifically you want. You say you only want to display the University, but University is an array with three values, so which value do you want? Or do you want all three? I'm going to assume you only want the DisplayValue. If so, then you don't even need a loop at all, you'd just reference it as so: $Grid.Row.University.DisplayValue
-
how to post only user selected values in a form
kicken replied to michelle1404's topic in Javascript Help
Is there a reason you are trying to do this in Javascript rather than the PHP file you're posting to? It'd be easier in PHP, especially if you convert the inputs to an array. <form action="" method="post"> <select name="var[]" class="form-control"> <option value="0">0</option> <option value="10">10</option> <option value="20">20</option> <option value="50">50</option> <option value="100">100</option> </select> <select name="var[]" class="form-control"> <option value="0">0</option> <option value="10">10</option> <option value="20">20</option> <option value="50">50</option> <option value="100">100</option> </select> <input type="submit" name="submit" value="Submit"/> </form> $var = array_filter($_POST['var']); //Now $var only contains non-zero entries. If you really want to use Javascript then the easiest thing to do would probably be to disable the inputs with 0 values and use jquery to serialize the form. $('#formId').submit(function(e){ e.preventDefault(); var form = $(this); var selects = form.find('select'); //Disable zero values. selects.each(function(idx,ele){ if (ele.value == 0) ele.disabled=true; }); //Gather form data var data = form.serialize(); //Re-enable selects selects.prop('disabled', false); $.post('script.php', data); }); Something like that. -
If there is only one ticket, then the loop is unnecessary. You can just access it's name directly and test against it. $name = $tickets[0]->name; if (stripos($name, 'sssts') !== false){ echo "Yes $name"; }
-
You can use joins in an update just like you do in a select. If you check the manual page for the UPDATE syntax you can get an idea of how it works. This should work for your query: UPDATE community AS c LEFT JOIN block AS b ON b.community_id = c.community_id LEFT JOIN lot AS l ON l.block_id = b.block_id LEFT JOIN `schedule` AS s ON s.lot_id = l.lot_id LEFT JOIN days_to_order AS d ON c.days_to_order_id = d.days_to_order_id SET l.order_by_date = DATE_SUB(s.schedule_date, INTERVAL d.days_to_order DAY) WHERE s.reschedule_date IS NULL AND l.order_by_date IS NOT NULL AND l.lot_type_id > 2 AND s.schedule_date IS NOT NULL AND c.community_type < 3 AND l.active = 1 AND l.order_by_date > s.schedule_date
-
Use the DOM extension and DOMXPath to process the html. Using xpath queries to target the elements will provide more flexibility and easier extraction of the data. For example (untested) $dom = new DOMDocument(); $dom->loadHTML($html); $xpath = new DOMXPath($dom); $query = $xpath->query('//div[@class="productDetails"]/span/text()'); $data = $query->item(0)->textContent; Read up on XPath and how to do queries. Mine above may not be exactly right, it's been a while since I used it.
-
How can i get/query/list sub/nested comments from comment table?
kicken replied to colap's topic in PHP Coding Help
Have a look at this article for an example of how to build a tree structure out of a liner array: Building Tree Structures In Php Using References -
The only reason to split out the address would be if you want to allow the user to add multiple addresses. If they can only have one address then you'd just leave it in the original table. The same applies to the contacts. Technically you could separate out email and phone but it's probably not worth it. If you did want to separate it out, then you'd want a table more like this to allow any number of contact methods. create table user_contact ( id int auto_increment primary key, method varchar(20) not null, details varchar(200) ); method would be a string such as 'email', 'phone', 'facebook', etc. details would be whatever that methods value is. When deciding whether or not to split out a set of data into another table, I generally consider two things. 1) Can the user have multiples of this data (multiple addresses, multiple emails, etc). 2) Will I want to use this data independently of the other data occasionally. Regarding the second point, this applies sometimes to login information, particularly if I have multiple user types each with different details. For example, I might have three tables: login (id, username, password, type, other_shared_fields) faculty (id, bio, experience, etc) student (id, degree, enrollment_date, etc) Both faculty and student have logins and some common info such as name, email, etc. In some areas I also need to refer to a particular user regardless of their type (ie for change tracking). Have a separate login table allows for this.
-
You might be surprised what can be done with just CSS to alter the look and feel of a page. However even if you need more than just CSS changes you can use alternative an HTML structure. The way you create a theme is you create different template files with whatever base HTML you need. Within that HTML you put various placeholder values that you can replace with the actual content of the page later. For example, take a look at the Twig template engine. You'd define your template as something like this: theme1.html.twig <!doctype html> <html> <head><title>Theme 1</title></head> <body> {% block content '' %} </body> </html> You'd create as many of these theme templates as you need, each with a content block which will be replaced later. You can create multiple blocks if necessary, just give each one a unique name. Then all your content files extend the desired theme template. For example: about.html.twig {% extends 'theme1.html.twig' %} {% block content %} <p>This is your page content. All about us.</p> {% endblock %} Once you have all that working for one theme, you can change the extends tag to use a variable instead of a static file name and have PHP populate that variable with the theme template filename you wish to use. Be sure to go over all the Twig documentation to learn how to set it up and use it. Search for a few tutorials if need be also.
-
Add var_dump($_from); just before the foreach in the generated file so you can see what $Grid contains. Find the key for the university list then change you template to {foreach from=$Grid.whateverThekeyIs item=row}
-
It exists because as can be seen from your earlier post $row is not always an array. For example: So what you end up doing in your template is the equivalent of $row = "unidata.php?operation=return"; echo $row['University']['DisplayValue']; Obviously that is wrong. You get a 'u' out of that because $row['University'] become $row[0] due to casting the index as an integer which results in the first letter of the string, 'u'. Probably what you want to do is figure out which key your university list is stored under within $Grid and only loop over that specific key, not the entire $Grid array.
-
Give your output of the $row values it would seem like you need to identify whatever key contains the university details and handle it differently. What exactly does the $Grid/$row variable represent, and what output specifically are you trying to generate based on those variables? Your $row variable is obviously not always an array. In some instances it is a string, or a boolean, or an array with a different structure.
-
The file you are talking about is an auto-generated compiled version of the template. You should not be changing this file except possibly for debugging problems. Smarty could re-generate it at any time by re-compiling the template. What specific warning are you getting on that line? If things are done properly then you shouldn't be seeing any warnings.
-
Why are you trying to copy the fields at all? I don't really understand the purpose of this design. Perhaps if you explained more about what your overall goal is we could help you come up with a better solution. Just copying the form may not be the best way to do whatever you need to do. Sounds like a case of the XY Problem.