Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation since 08/17/2019 in all areas

  1. 2 points
    This is my take on it. I copy/pasted a couple of extra jobs to give... CODE <?php $required = ['Feasibility', 'Measure Up', 'Model Drawing', 'Concept Design', 'Developed Design', 'Resource Consent', 'Construction Documentation' ]; $colors = array_combine($required, ['w3-red', 'w3-green', 'w3-orange', 'w3-deep-orange', 'w3-teal', 'w3-yellow', 'w3-purple'] ); $staff_arr = [ 'Staff1' => 'SP', 'Staff2' => 'MB', 'Staff3' => 'BF', 'Staff4' => 'MCP', 'Staff5' => 'DG' ]; function state_dropdown($staff, $color) { return "<form action='' method='POST'>" . "<select class='w3-input w3-round $color' name ='StaffName' onchange='this.form.submit()'>" . // why is a menu of states called "StaffName" ? "<option value =''>$staff</option>" . "<option class='form-control col-sm-3 bg-white text-dark'>Feasibility </option> " . "<option class='form-control col-sm-3 bg-white text-dark'>Measure Up </option> " . "<option class='form-control col-sm-3 bg-white text-dark'>Model Drawing </option> " . "<option class='form-control col-sm-3 bg-white text-dark'>Concept Design </option> " . "<option class='form-control col-sm-3 bg-white text-dark'>Developed Design </option> " . "<option class='form-control col-sm-3 bg-white text-dark'>Resource Consent </option> " . "<option class='form-control col-sm-3 bg-white text-dark'>Construction Docs </option> " . "</select>" . "</form>"; } $xml = simplexml_load_file('plugnz.xml'); $data = []; // // collect the jobs and current task data into an array // foreach ($xml->Jobs->Job as $job) { $id = (string)$job->ID; $state = (string)$job->State; if (!in_array($state, $required)) continue; $data[$id] = [ 'name' => (string)$job->Name, 'state' => $state ]; $tasks = $job->xpath("Tasks/Task[Name='$state']"); $clr = $colors[$state]; $due = (string)$tasks[0]->DueDate; $data[$id]['due'] = date('Y-m-d', strtotime($due)); $data[$id]['display_date'] = date('M d Y', strtotime($due)); $assigned = []; foreach ($tasks[0]->Assigned->Staff as $s) { $assigned[] = $staff_arr[(string)$s->Name]; } $staff_str = join(' ', $assigned); $data[$id]['task'] = [ 'staff' => $staff_str, 'clr' => $clr ]; } // // sort the data array on the task due date DESC // uasort($data, function($a,$b) { return $b['due'] <=> $a['due']; } ); // // output the array as a table // $tdata = ''; foreach ($data as $jid => $jdata) { $tdata .= "<tr><td class='jobno'>$jid</td><td>{$jdata['name']}</td>"; foreach ($required as $stat) { if ($jdata['state']==$stat) { $tdata .= "<td>" . state_dropdown($jdata['task']['staff'], $jdata['task']['clr']) . "</td>"; } else { $tdata .= "<td>&nbsp;</td>"; } } $tdata .= "<td>&nbsp;</td>"; $tdata .= "<td>{$jdata['display_date']}</td></tr>"; } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="creation-date" content="05/10/2019"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <title>Job Status Table</title> <style type="text/css"> body { font-family: verdana,sans-serif; font-size: 10pt; padding: 20px 50px; } table {border-collapse: collapse;} .th-sm-1 { font-size: 8pt; text-align: left; } .jobno { font-weight: 600; color: #2196f3; } select { width: 120px; } </style> </head> <body> <table border=1> <thead> <tr> <th class="th-sm-1">Project Number</th> <th class="th-sm-1">Project Name</th> <th class="th-sm-1">Feasibility</th> <th class="th-sm-1">Measure Up</th> <th class="th-sm-1">Model Drawing</th> <th class="th-sm-1">Concept Design</th> <th class="th-sm-1">Developed Design</th> <th class="th-sm-1">Resource Consent</th> <th class="th-sm-1">Construction Docs</th> <th class="th-sm-1">Milestone</th> <th class="th-sm-1">Due Date</th> </tr> </thead> <tbody> <?=$tdata?> </tbody> </table> </body> </html>
  2. 1 point
    Perfect! I see it now. I ended up following your advice and created an fgetcsv PHP script (which only took me an hour, not the 2 days I anticipated :-) Now instead of the hassle of opening the file in excel, copy-and-pasting into text editor, creating a mySQL lookup, formatting the data to paste back into Excel, etc., all I have to do is open up SSH and type "php my_new_script.php" and voila.
  3. 1 point
    Create a view for yourself that shows threads and the initial posts. It'll make life easier. Though I'm really skeptical that XenForo doesn't have a way to get that information sort of finding the first post for a given thread ID - after all, since there is an ID in the first place, surely there is some source generating that ID, right? Once you have the view the query to find users is trivial.
  4. 1 point
    Yup. Personally I would also be tracking the nodes as members of the chart itself, but that's besides the point. Sounds too complicated. Speaking of complicated, you could create a NodeCollection object that offers iteration by category and series. The series and category objects then use that collection instead of managing their nodes manually. I'm leaning towards this. Having links on both ends makes it harder to move things around, as you have to remember to update both links, but it's not too unreasonable to do so. Meh. If the id isn't set then there's no operations to clear it, but instead it adds operations to check the value. More lines of code for no net benefit. The nodes must be cloned because they can/should only belong to one chart. No cloning means you are reusing them in two places. Same reason you have to clone the series and categories.
  5. 1 point
  6. 1 point
    And the problem is... that it's not replacing anything? Metacharacters like \e do not work in single-quoted strings.
  7. 1 point
    It's extremely unlikely that a Windows update broke this. Something else happened.
  8. 1 point
  9. 1 point
    There is that risk, yes. But what I haven't said is that you're really the only one here who knows your application best. There is no one-size-fits all answer to stuff like ecommerce. No one can just tell you what to do and be totally right about it: every company needs something a little different, and when random people on the internet give advice some of it will be right and some of it will be wrong. I also don't think I mentioned but your questions are (mostly) not technical questions. They're business questions. Application requirements. So what you should do is figure out, as best as you can, what the requirements are and how to go about satisfying them. Is there a requirement that an order exist in the system before the user submitted payment? Is there a requirement that a cart be saved in an account instead of temporarily held in the browser? Create a specification that describes everything you need to support, then make sure what you code supports it.
  10. 1 point
    Monospaced font (courier) between <pre>..</pre> tags does the job, as does using the <> button in this forum. Oops| Forgot to edit that one after copy/pasting.
  11. 1 point
    You probably saw the behavior you did due to using sessions. When you start a session PHP will lock the session data so that it's not affected by other processes. This lock exists until you either call session_write_close or the process ends. So if you're long-running process doesn't need to update any session data, call session_write_close prior to starting it. That said, lots of concurrent long-running processes could block a server. Your HTTP server will process each request using a thread or worker process (depends on the configuration). I'll only spin up a certain number of these based on the configuration and if that limit is reached it'll stop responding to requests. Your long-running processes would tie up some of these threads. The number of threads available on an actual server will probably be relatively high though, so unless you expect a lot of these processes to be running concurrently it likely won't be an issue. If the server is setup with something like PHP-FPM or a CGI setup though, the number of allowed PHP instances may be smaller. You limit would be the smaller of the the http server's limits or PHP's limits. If you want to keep your site responsive though, the way to manage that would be to offload the work to a background process so that your website can continue to respond to requests. The user would then go to the page which would trigger the processing and you would respond with a message like "We're working on your request, check back in a bit". When the process is complete give the user the results. There are many ways to accomplish this, such as using services like redis, gearman, beanstalkd, etc or simply adding records to your database and having a background service checking for new records periodically.
  12. 1 point
    Not even remotely the case. Locally, were you using the built-in server that PHP provides? Don't. It's good for quick stuff but it's not a real server. Set up your development environment to match your production environment as closely as possible.
  13. 1 point
    I'd say it depends on the type of book. For something like a technical reference that's marked up and linked properly then sure, online may be a better scenario as people would probably be less inclined to be reading start to finish and instead jumping around to the information they need or want. For something more story/native that's intended to be read front to back in order, I'd gather most people would not be reading it on a PC. Most readers I know either stick to physical books or their phones/e-readers. I'm not trying to sell stuff, but that's my general point of view on things as well. Most attempts at stopping piracy I've experienced are counter-productive. They don't do a great job at preventing piracy (someone breaks it eventually, and usually in relatively short order), but limit your non-pirating customers severely. For example pretty much nothing the movie industry has tried has worked for very long but their attempts prevent me from easily creating a digital copy of the movies I buy for use on my HTPC though, which is a perfectly legal and reasonable thing to do. In my opinion, the best way to try and tackle the problem would be to 1) Make sure your product is easy to acquire for those who want it (reasonably priced, no region locks, etc) 2) Monitor the web for pirated copies and respond appropriately when you find them.
  14. 1 point
    Or I could just use the Print option and print the web page to a PDF file! In this case the decision on "HOW" to store the content is irrelevant from a security concern. Determien the best format based on the best delivery method for the user. Since the intent is not for the user to download for later use, then PDF is probably not the option. But, if I was a user on your site I would think it is pretty stupid that I can't download the content I paid for to read when it is convenient for me (i.e. on a plane for example). But, you just need to decide what makes sense for you. The security is irrelevant because each method can be adequately 'protected' from direct access: Static HTML, Dynamic HTML (from database) or PDF files. It just doesn't matter. If you take this approach the Chapters/sections should just be the raw HTML markup. They should all use a common stylesheet. Here is a very generic example. User goes to a url such as getbook.php?bookid=3&chapter=5 (a chapter/section id is only needed if the book is split up). <?php $bookId = intval($_GET['bookid']); $chapter = intval($_GET['chapter']); if (user has permission to $bookId) { //Define path to the content $bookContent = "/my_secured_directory/{$bookId}/{$_GET['chapter']}.htm"; } else { //Error condition - redirect user to an error page } ?> <html> <head> //Include common stylsheet </head> <body> //HTML that comes before the book output <div id="book_content"> <?php include($bookContent); ?> </div> //HTML that comes before the book output </body> </html>
  15. 1 point
    And what is to stop someone from saving the content displayed in the webpage and sharing that just as they would with a PDF? Heck, the user can just "print" the web page to a file (PDF, HTML, etc.). Anything that is viewed on a webpage can be copied (even if you try to implement some javascript hacks - which you should NOT do). Storing the content in a database does nothing to prevent this type of tampering either. Regardless of whatever method used to deliver your content (PDF or HTML) - it doesn't matter. I think your concern is about people directly accessing the content. That is easy to control - don't put the files in publicly accessible areas! Put them in a directory that is outside of the public folders. Your PHP files when being processed will be able to access the files, but a user could not access them through a URL. After you validate that the user can view a particular resource) just include the file in the output. That will prevent unauthorized access to the content from your web server. But, as stated previously, once you present content to a user, there is really nothing you can do to prevent them from copying/saving the content.
  16. 1 point
    Not even close. This code... $product_details = "SELECT * FROM product WHERE product_id=".$_GET['product_id']; $prepare = $connect->prepare($product_details); $prepare->execute(); ...would embed any SQL injection code contained in the GET into the query which would then be executed. (Just as an unprepared query would) In the correct version the injection code would only be treated as data and not part of the SQL code.
  17. 1 point
    If your goal is ease of use for the end user to maximize sales, then you could reduce the friction some while still gaining most of the benefits. As was mentioned before, don't make the verification required to process the transaction, but rather do it after the fact. There's really no need for the user to enter a code, most places just send a link with a unique code in the URL. User clicks the link and the email is verified. Show the user a notice on login that their email needs to be verified still, and possibly lock out their account until verification is complete after some time. If it were me, I'd probably have a process such as: User selects a subscription type Gather account & payment information Create account, send verification email Let the user access what they paid for. After 3-7 days, restrict the account if the email is still unverified. That works around potential email delays and gets the user to their content the quickest. You could do the double email field as an additional measure to try and catch people fat-fingering their email. In most cases though the user will probably enter it correctly, get the verification email, and click the link on their own time without issue. If the user does fat-finger their email (intentially enter an invalid one) they will get their content for a while, but then have to correct the problem. Allow a user to change their email if their account is restricted due to no verification. Depending on the level of security you want, maybe require the password as well to re-start the verification process. A third option to minimize end-user friction would be to let them use something like google, facebook or twitter to login instead of creating an account. A lot of people prefer that these days as it's one less account/password to have to remember. I know I personally am far more likely to hit the 'Login with Google' button than I am the 'Create an account' button.
  18. 1 point
    That all depends on the person. Some will be fine, some won't, others will we be somewhere in between. To be honest, you'll never make everyone happy. The best you can do is try something and see how things go. If you're not getting the results you want, you can always adjust. Depending on how big your audience is and how much time you have for testing, you could develop 2 separate options of the sign-up process. One would require the users to validate the email address. The other would skip the validation. You could then use A/B testing to see which option results in more website signups. More information about A/B testing can be found here: https://en.wikipedia.org/wiki/A/B_testing
  19. 1 point
  20. 1 point
    First thing you should do is get a keyboard that that has return and tab keys. That will enable you to format your code into separate lines with indents so it is understandable. When you've done that, repost your code using a code box ("<>" button in the toolbar). If it's readable there's a chance someone might read it.
  21. 1 point
    My 0.02 worth... Why are you "denormalizing" your data by creating several objects all with the same id and color code. Would it not be more sensible (and a lot easier) to create a merged data set like this... <PRODUCTINFORMATION> <PRODUCTS> <PRODUCT> <PRODUCT_NUMBER>53-03</PRODUCT_NUMBER> <PRODUCT_PRINT_ID>42</PRODUCT_PRINT_ID> <PRODUCT_NAME>ProductFirst</PRODUCT_NAME> <COLOR_CODE>03</COLOR_CODE> <PRINTING_POSITION> <ID>TOP BOX</ID> </PRINTING_POSITION> <PRINTING_TECHNIQUES> <PRINTING_TECHNIQUE> <ID>DL</ID> </PRINTING_TECHNIQUE> <PRINTING_TECHNIQUE> <ID>L2</ID> </PRINTING_TECHNIQUE> <PRINTING_TECHNIQUE> <ID>P4</ID> </PRINTING_TECHNIQUE> </PRINTING_TECHNIQUES> </PRODUCT> </PRODUCTS> </PRODUCTINFORMATION> Below is my solution to your original quest using SimpleXML. Hava a go at it on your own as requinix suggested first then peek only if you really get stuck
  22. 1 point
    I believe you can keep using importNode, it's just that you have to be deliberate about what you copy and where you appendChild it to. Can't just do a simple copy and expect it to transform itself into the shape you want. But then you'd have to learn XSLT, and then figure out how to make PHP do it.
  23. 1 point
    It's quite happily copying what you've told it to copy. Without any changes. Thing is you don't want to just copy the nodes. What you want is to change the structure of the XML. Which means you have to write code that understands the original structures and the structures you're trying to create. 1. Copy the PRODUCT_NUMBER, PRODUCT_PRINT_ID, PRODUCT_NAME 2. Create a new PRINTING_POSITIONS to work on. For each PRINTING_POSITION, 3. Create a new PRINTING_POSITION to work on. For each PRINTING_TECHNIQUE, 4. Copy the ID 5. Copy the PRINTING_TECHNIQUE 6. Either (a) copy the COLOR_CODE or (b) copy everything except the PRODUCT_NUMBER, PRINT_ID, and NAME
  24. 1 point
    They are entirely unnecessary. PS - it is generally not recommended to use the "select *" query format. Always select the fields that you truly want to obtain from the query and not just do the catchall "*" operand. This way you (and those behind you) know what field names you have acquired from the query and in what order they are in should you choose to use numeric indices.
  25. 1 point
    You need to pass the $con to your function. IE echo '<div class="jump_menu">' . sectional_select($con) . '</div>'; ^^^^ Also your function should return the text value to be printed instead of echoing within the function EG function sectional_select($con) { $output = '<select>'; $output .= "<option value=''>- select sectional -</option>"; // add options ... $output .= "</select>"; return $output; }
  26. 1 point
    $con is outside the scope of your function. The function does not know it exists. You need to pass $con to the function. I would suggest learning about variable scope. I would also highly recommend you turn on error reporting.
  27. 1 point
    Your webserver is responding the the browser with a redirect (Status 302) so the browser is trying to follow that redirect. If you're creating a new resource you should be responding with status code 201. If you're updating an existing resource you should respond with status code 200.
  28. 1 point
    That's the only one that you check with isset(). Should be if ( !isset($_SESSION['defaultseasonid_']) || !isset($_SESSION['defaultmatchtypeid_']) || !isset($_SESSION['defaultlanguage_']) ) but the ?? method is a lot simpler.
  29. 1 point
    As of PHP 7.0 you could replace this code... if(!session_is_registered('defaultseasonid_') || !session_is_registered('defaultmatchtypeid_') || !session_is_registered('defaultlanguage_')) { $_SESSION['defaultseasonid_'] = $pdata['DefaultSeasonID']; $_SESSION['defaultmatchtypeid_'] = $pdata['DefaultMatchTypeID']; $_SESSION['defaultlanguage_'] = $pdata['DefaultLanguage']; $defaultseasonid = $_SESSION['defaultseasonid_']; $defaultmatchtypeid = $_SESSION['defaultmatchtypeid_']; $defaultlanguage = $_SESSION['defaultlanguage_']; } else { $defaultseasonid = $_SESSION['defaultseasonid_']; $defaultmatchtypeid = $_SESSION['defaultmatchtypeid_']; $defaultlanguage = $_SESSION['defaultlanguage_']; } with ... $defaultseasonid = $_SESSION['defaultseasonid_'] ?? $pdata['DefaultSeasonID']; $defaultmatchtypeid = $_SESSION['defaultmatchtypeid_'] ?? $pdata['DefaultMatchTypeID']; $defaultlanguage = $_SESSION['defaultlanguage_'] ?? $pdata['DefaultLanguage']; "??" is the "null coalesce" operator, so $a = $b ?? $c ?? $d; will set $a to the first of the three values that is not null.
  30. 1 point
    I added a systemd drop-in to create the directory prior to launching the service. /etc/systemd/system/php7.3-fpm.service.d/prestart.conf [Service] ExecStartPre=/bin/mkdir -p /var/run/php7-fpm
  31. 1 point
    if the purpose is to find the class given the sectional# then it would be easier if the array were inverted... <?php foreach (range(1,16) as $sect) $sectional_class[$sect] = 4; foreach (range(17,32) as $sect) $sectional_class[$sect] = 3; foreach (range(33,48) as $sect) $sectional_class[$sect] = 2; foreach (range(49,64) as $sect) $sectional_class[$sect] = 1; echo $sectional_class[25]; //--> 3 ?> or you can get them direct form the database without using array to look them up SELECT t.team_name , s.sectional_id , c.class_id FROM team t JOIN sectional_team st USING (team_id) JOIN sectional s USING (sectional_id) JOIN class c USING (class_id) WHERE season = ?
  32. 1 point
    Are you able to show more of the code? How is $state being populated now? Never mind, you showed that already.
  33. 1 point
    And that may very well be what you end up using, but what we're trying to check out is whether (a) there is, in fact, something better to use, and (b) whether what we come up with not only solve the problem but not create additional problems to solve, be that now or in the future.
  34. 1 point
    It's better to put your Apache configuration inside apache's main (or vhost) configuration file then disable .htaccess file processing. However that's the kind of optimization that you only really need to do if you're trying to run a high traffic site and need every bit of performance you can get. Making a change such as a new redirect or rewrite rule would then require editing the configuration and reloading apache. Not a terrible thing but more cumbersome than editing the site-specific .htaccess. Yes, if you want multiple versions of PHP then you need to have them all installed separately in a way that doesn't conflict. Hopefully your package management system takes care of that for you. For example, I use ubuntu and the ondrej/php PPA which installs the configurations into /etc/php with a sub-folder for the version and api type. I use FPM so my configuration is in /etc/php/7.3/fpm/ with pools defined in /etc/php/7.3/fpm/pools.d/ Yes. You could do a per-site setup, per user, or something different. That's pretty much up to you and what you find most convinent. What I prefer to do is create a separate pool for each system user that hosts sites. I configure that pool with settings appropriate for their site and also configure it to run using their user account so there's no need really to deal with permission problems when the site whats to manipulate the files. For example, a typical pool configuration might look something like: [kicken] prefix = /var/run/php7-fpm user = $pool group = www-data listen.owner = www-data listen.group = www-data listen.mode = 0600 listen = $pool.sock php_value[error_log] = /var/log/php7-fpm/$pool-error.log php_value[session.save_path] = /var/lib/php7/$pool/sessions php_flag[log_errors] = on php_value[memory_limit] = 32M php_value[upload_max_filesize] = 500M php_value[post_max_size] = 501M php_value[max_input_vars] = 5000 I made a copy of the default www pool when I first set things up and made some general changes (like error log, session path, using $pool instead of hard-coded names) and save that as a template. Each time I need to add a new pool I just copy that template, rename the pool and make tweaks if necessary. I prefer using unix sockets vs TCP sockets as /var/run/php7-fpm/kicken.sock is easier to remember than 127.0.0.1:9038 or whatever port you want to use for that pool. On the apache side of things, I have a separate configuration file for all the PHP stuff that looks like Define PHP7_POOL_DEFAULT "proxy:unix:/var/run/php7-fpm/www-data.sock|fcgi://localhost" Define PHP7_POOL_KICKEN "proxy:unix:/var/run/php7-fpm/kicken.sock|fcgi://localhost" Define PHP7_POOL_USERX "proxy:unix:/var/run/php7-fpm/userx.sock|fcgi://localhost" Define PHP7_POOL_USERY "proxy:unix:/var/run/php7-fpm/usery.sock|fcgi://localhost" Define PHP7_POOL_USERZ "proxy:unix:/var/run/php7-fpm/userz.sock|fcgi://localhost" ScriptAlias /phpsource.cgi /usr/lib/cgi-bin/php7-source Action php-source /phpsource.cgi virtual <FilesMatch "\.phps"> SetHandler php-source </FilesMatch> <Directory /usr/lib/cgi-bin> Require all granted </Directory> <FilesMatch ".+\.ph(ar|p|tml)$"> SetHandler ${PHP7_POOL_DEFAULT} </FilesMatch> The pool's are setup as variables that can be used in the vhost configurations, and it sets up a default configuration. I set mine up to support highlighted .phps extensions also using a traditional CGI setup, but that can be skipped/ignored. In each vhost I set it to the right pool by giving it it's own FilesMatch with the appropriate handler. <VirtualHost *:443> ServerName aoeex.com ServerAlias www.aoeex.com <FilesMatch ".+\.ph(ar|p|tml)$"> SetHandler ${PHP7_POOL_KICKEN} </FilesMatch> </VirtualHost> Setting up multiple versions is just a matter of installing each version's php-fpm package, configuring a pool for that version, and pointing apache to whatever socket you setup for that pool. Fairly simple. I used to have a 5.6 setup going as well due to some old third-party software but I was finally able to move to single 7.3 version recently. Ideally you'd want to only have a single version going, and only use multiple versions if you really need to for some specific reason.
  35. 1 point
    2 ) You could setup users with access to different sets of databases/tables. Connect to the server using the username that has the required access privileges
  36. 1 point
    My solution requires just the records for mina1111 with consecutive record numbers (to facilitate finding the last 5 records) so I created a temporary table from your data. Also because I needed to reference the table a second time in a subquery (you can;t do this with temp tables) I had to create a second temporary table. I'm afraid it isn't the most efficient query ever written as it uses a dependent subquery. -- -- create temp table a -- create temporary table mina1111_a select a.recno , a.v_score , @count := @count+1 as reccount from ajoo a JOIN (select @count:=0) as init where user = 'mina1111'; -- -- create temp table b -- create temporary table mina1111_b select a.recno , a.v_score , @count := @count+1 as reccount from ajoo a JOIN (select @count:=0) as init where user = 'mina1111'; -- -- calculate rolling 5-record averages -- SELECT a.recno , j.user , a.v_score , a.reccount , ( SELECT AVG(b.v_score) as avscor FROM mina1111_b b WHERE reccount BETWEEN a.reccount-4 and a.reccount ) as av5 FROM mina1111_a a JOIN ajoo j using (recno) WHERE a.reccount > 4; -- -- remove the temporary tables -- drop temporary table mina1111_a; drop temporary table mina1111_b; results... +-------+----------+---------+----------+--------+ | recno | user | v_score | reccount | av5 | +-------+----------+---------+----------+--------+ | 9 | mina1111 | 4 | 5 | 3.0000 | | 10 | mina1111 | 5 | 6 | 3.6000 | | 11 | mina1111 | 0 | 7 | 2.8000 | | 12 | mina1111 | 1 | 8 | 2.4000 | | 13 | mina1111 | 1 | 9 | 2.2000 | +-------+----------+---------+----------+--------+ Temporary table... +-------+---------+----------+ | recno | v_score | reccount | +-------+---------+----------+ | 3 | 2 | 1 | | 6 | 4 | 2 | | 7 | 3 | 3 | | 8 | 2 | 4 | | 9 | 4 | 5 | | 10 | 5 | 6 | | 11 | 0 | 7 | | 12 | 1 | 8 | | 13 | 1 | 9 | +-------+---------+----------+
  37. 1 point
    Looks like it's just the quotes that are missing IE use <img src="<?php echo $path['t'];?>"/> But as that is what the code is doing for you anyway it isn't going to cure the problem of images not appearing. You could try <img src="<?php echo $path['o'];?>"/> or <img src="<?php echo $path['src'];?>"/> If none of those work then the images ain't there anymore.
  38. 1 point
    The error is nothing to do with the upgrade, except that error reporting got turned on. When PHP comes across an unquoted string then it assumes it is a defined constant. It then searches for the definition. Not finding a definition it then assumes it is string literal ("t"). This is only a warning and doesn't affect the running of the code (other than slowing it down while it searches for a constant definition). The question is, therefore, "Is there a key "t" in the $path array?" Try adding a line of code to debug... <?php $images = get_group('Banner Images'); ?> <?php echo '<pre>.print_r($images, true).'</pre>'; // ADD THIS LINE foreach ($images as $image) { . . . Post the output from that line so we can see the data.
  39. 1 point
    Obviously the 't' is meant as an index into the array that is in $path. One should ALWAYS use quotes around an index value unless it is a php variable name. Since you are using something called just "t" you need to figure out what belongs there - most likely a dollar sign. Clearing that up and avoiding what php is defaulting your index to (from the error message it may be simply the value "t") an incorrect value. Do you know what $path actually contains? You can do a bit of debugging by simply displaying it.
  40. 1 point
    I saw nothing in the documentation to explain this, and I'm confident that this is both concrete5's fault and something that they should fix. For you, a) Create a CSS file for overriding this kind of stuff, define a new font-family like "Glyphicons Halflings 2" with correct srcs, and override .ccm-ui .glyphicon and whatever else to use the corrected font-family b) Fix the concrete5 files directly
  41. 1 point
    Perhaps you can make use of the get_class() function
  42. 1 point
    Composer creates an autoload file that you can include at the top of your PHP scripts instead of having to include every package individually. Then you just have to use them as if they're classes that you've included. https://getcomposer.org/doc/01-basic-usage.md#autoloading Example from site. require ( __DIR__ . '/vendor/autoload.php'; $log = new Monolog\Logger('name'); $log->pushHandler(new Monolog\Handler\StreamHandler('app.log', Monolog\Logger::WARNING)); $log->addWarning('Foo');
  43. 1 point
    An alternative approach... storage_unit: date unit rented, price per month storage_payment: record of payments made for each unit TABLE: storage_unit TABLE: storage_payment +---------+-------------+-------+ +------------+---------+--------------+--------+ | unit_id | rental_date | price | | payment_id | unit_id | payment_date | amount | +---------+-------------+-------+ +------------+---------+--------------+--------+ | 1 | 2019-02-28 | 20.00 | | 1 | 1 | 2019-03-28 | 20.00 | | 2 | 2019-04-30 | 20.00 | | 2 | 1 | 2019-04-28 | 20.00 | | 3 | 2019-05-01 | 20.00 | | 3 | 1 | 2019-05-31 | 20.00 | | 4 | 2019-05-15 | 20.00 | | 4 | 2 | 2019-05-30 | 20.00 | | 5 | 2019-05-30 | 20.00 | | 5 | 2 | 2019-06-30 | 20.00 | +---------+-------------+-------+ | 6 | 2 | 2019-07-30 | 20.00 | | 7 | 3 | 2019-06-01 | 20.00 | | 8 | 4 | 2019-06-19 | 20.00 | | 9 | 3 | 2019-07-01 | 20.00 | +------------+---------+--------------+--------+ use a query to calculate payments and late fees SELECT u.unit_id , u.rental_date , COALESCE(MAX(p.payment_date), u.rental_date) as `last_paid` , timestampdiff(MONTH, COALESCE(MAX(p.payment_date), u.rental_date), CURDATE()) as mths_since_last , @ld := u.rental_date + INTERVAL timestampdiff(MONTH, u.rental_date, CURDATE()) MONTH as last_due , SUM(IFNULL(p.amount, 0)) as paid_to_date , u.price * timestampdiff(MONTH, u.rental_date, CURDATE()) as due_to_date , u.price * timestampdiff(MONTH, u.rental_date, CURDATE()) - SUM(IFNULL(p.amount, 0)) as rental_owed , CASE WHEN ( timestampdiff(MONTH, COALESCE(MAX(p.payment_date), u.rental_date), CURDATE()) = 1 ) AND ( timestampdiff(DAY, @ld, CURDATE()) <= 5 ) THEN 0 ELSE timestampdiff(MONTH, COALESCE(MAX(p.payment_date), u.rental_date), CURDATE()) * 15 END as late_fees FROM storage_unit u LEFT JOIN storage_payment p USING (unit_id) GROUP BY unit_id; +---------+-------------+------------+-----------------+------------+--------------+-------------+-------------+-----------+ | unit_id | rental_date | last_paid | mths_since_last | last_due | paid_to_date | due_to_date | rental_owed | late_fees | +---------+-------------+------------+-----------------+------------+--------------+-------------+-------------+-----------+ | 1 | 2019-02-28 | 2019-05-31 | 2 | 2019-07-28 | 60.00 | 100.00 | 40.00 | 30 | | 2 | 2019-04-30 | 2019-07-30 | 0 | 2019-07-30 | 60.00 | 60.00 | 0.00 | 0 | | 3 | 2019-05-01 | 2019-07-01 | 1 | 2019-08-01 | 40.00 | 60.00 | 20.00 | 15 | | 4 | 2019-05-15 | 2019-06-19 | 1 | 2019-07-15 | 20.00 | 40.00 | 20.00 | 0 | | 5 | 2019-05-30 | 2019-05-30 | 2 | 2019-07-30 | 0.00 | 40.00 | 40.00 | 30 | +---------+-------------+------------+-----------------+------------+--------------+-------------+-------------+-----------+
  44. 1 point
    Protecting a form field from what? htmlspecialchars() is for use when outputting user-supplied data data to a web page. mysql_real_escape string() is was used to protect input values to queries from SQL injection. This is now obsolete, replaced by mysqli_real_escape_string() or (better still) the use of prepared statements to completely separate the query code from the user-supplied data.
  45. 1 point
    I have no idea what you are starting with or what you want to finish with, so here is general method of dealing with a hierarchy. category table +--------+-----------+--------+ | cat_id | catname | parent | +--------+-----------+--------+ | 1 | Cat 1 | 0 | | 2 | Cat 2 | 0 | | 3 | Cat 3 | 0 | | 4 | Cat 1 1 | 1 | | 5 | Cat 1 2 | 1 | | 6 | Cat 2 1 | 2 | | 7 | Cat 2 2 | 2 | | 8 | Cat 2 3 | 2 | | 9 | Cat 3 1 | 3 | | 10 | Cat 1 1 1 | 4 | | 11 | Cat 1 1 2 | 4 | | 12 | Cat 2 3 1 | 8 | +--------+-----------+--------+ Code output Store arrays of items belonging to each parent in an array Starting with parent 0, list its children but each time you list a child you check if it is itself a parent and list its children. The recursive function does this for you. Code $sql = "SELECT cat_id, catname, parent FROM category"; $res = $db->query($sql); // // store arrays of items for each parent in an array // while (list($id, $name, $parent) = $res->fetch_row()) { $data[$parent][] = array('id'=>$id, 'name'=>$name); } echo '<pre>', print_r($data, 1), '</pre>'; // call the recursive function displayHierarchy($data, 0); // function to print a category then its child categories function displayHierarchy(&$arr, $parent) { if (isset($arr[$parent])) echo "<ul>\n"; foreach($arr[$parent] as $rec) { echo "<li>{$rec['name']}"; if (isset($arr[$rec['id']])) displayHierarchy($arr, $rec['id']); echo "</li>\n"; } echo "</ul>\n"; }
  46. 1 point
    I have been playing around with a possible database solution to your problem Given that a postcode such as "EH12 3AB" breaks down into four parts viz +------+----------+--------+------+ | area | district | sector | unit | +------+----------+--------+------+ | EH | 12 | 3 | AB | +------+----------+--------+------+ ... I was toying with this table structure CREATE TABLE `postcode` ( `pc_id` int(11) NOT NULL AUTO_INCREMENT, `seller` int(11) DEFAULT NULL, `area` varchar(2) DEFAULT NULL, `district` varchar(2) DEFAULT NULL, `sector_min` char(1) DEFAULT NULL, `sector_max` char(1) DEFAULT NULL, `unit_min` char(2) DEFAULT NULL, `unit_max` char(2) DEFAULT NULL, `deliverable` tinyint(4) DEFAULT NULL, `price` decimal(8,2) DEFAULT NULL, PRIMARY KEY (`pc_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-------+--------+------+----------+------------+------------+----------+----------+-------------+-------+ | pc_id | seller | area | district | sector_min | sector_max | unit_min | unit_max | deliverable | price | +-------+--------+------+----------+------------+------------+----------+----------+-------------+-------+ | 1 | 1 | EH | 1 | 1 | 4 | AA | ZZ | 1 | 1.50 | | 2 | 1 | EH | 1 | 5 | 5 | AA | BZ | 1 | 1.80 | | 3 | 1 | EH | 1 | 5 | 5 | CA | ZZ | 0 | 2.00 | | 4 | 1 | EH | 2 | 1 | 9 | AA | ZZ | 1 | 2.25 | | 5 | 1 | EH | 3 | 1 | 9 | AA | PZ | 1 | 2.50 | +-------+--------+------+----------+------------+------------+----------+----------+-------------+-------+ My code was $postcodes = [ 'EH1 2DB', 'eh15bg' , 'eh1 5ba', 'eh15dg', 'EH2 7HJ', 'EH3 2PT', 'EH3 8SX', 'EH146DE' ]; echo '<pre>'; foreach ($postcodes as $pc) { vprintf('%s%s %s%s : %s<br>', deliveryPrice($db, $pc)); } echo '</pre>'; function deliveryPrice($db, $pcode) { $pcode = strtoupper(str_replace(' ', '', $pcode)); $area = $district = ''; $sector = substr($pcode,-3, 1); $unit = substr($pcode, -2); $l = strlen($pcode); $first = str_split(substr($pcode, 0, $l-3)); foreach ($first as $c) { if (ctype_digit($c)) { $district .= $c; } else { $area .= $c; } } $res = $db->prepare("SELECT price FROM postcode WHERE area = ? AND district = ? AND ? between sector_min AND sector_max AND ? BETWEEN unit_min AND unit_max AND deliverable "); $res->execute( [ $area, $district, $sector, $unit ] ); $p = $res->fetchColumn(); $price = $p ? number_format($p, 2) : 'N/A'; return [$area, $district, $sector, $unit, $price ]; } RESULTS: EH1 2DB : 1.50 EH1 5BG : 1.80 EH1 5BA : 1.80 EH1 5DG : N/A EH2 7HJ : 2.25 EH3 2PT : 2.50 EH3 8SX : N/A EH14 6DE : N/A
  47. 1 point
    ...and you are NOT using a framework like jQuery or Prototype, think long and hard to come up with a very good reason why you are not! In all my years of coding, the only valid reason I have ever seen for not using one of these tools, is because someone is trying to learn it the old fashioned way (but not necessarily actually build websites with it). Or...someone is trying to build their own framework. That's it! IMO there has been no other reason worthy enough to warrant not using jQuery or the like! "It will bloat my website, increase page load time, blahblah" is not a good enough reason! These frameworks are compacted and browsers will cache them! So if you post an AJAX question here and your code and/or question does not involve the use of an existing framework like jQuery, then be prepared for you first response to be something along the lines of "Why aren't you using a framework?" Seriously. It is super easy. Way easier than that code you're trying to post. Save yourself the headache. Get jQuery or similar. DO IT.
  48. 1 point
    It was not my intention (nor do I think I implied it) to say you're stupid if you don't use a framework. I said do yourself a favor and make your life easier. Also, I am not "just another soldier" in the "we use frameworks" army. I actually actively resisted and opposed frameworks for a very long time. I too made arguments such as "If people learn jQuery, they won't learn the core language and therefore they will be weak." But the bottom line is that there's always going to be a certain amount of coding involved to keep things cross-browser compatible. And after several years of developing and maintaining my own baked framework (because that is essentially what you wind up with), I came to the realization that there's a whole lot of people out there much smarter than me who are dedicated to maintaining frameworks such as jQuery, vs. just myself, and on my very best of days my code will look very similar to theirs anyways. In short, I came to the realization that it was a waste of my time trying to develop and maintain my own baked framework, because my coding career does not revolve around that framework. Now, I still agree with the notion that one should take the time to learn javascript without frameworks, before diving into using them. I still absolutely agree with the dangers of not properly learning the nuances of javascript if you don't. And the same can be said for any language and framework. But if you've reached that level of expertise, all you are doing is holding yourself back by dedicating time and effort to maintaining your own baked solution. There's basically no compelling argument to do it, unless you are looking to distribute it and focus solely on it. Literally thousands of sites and coders out there developing, testing and submitting feedback etc. to a framework will always do it better than you, one person, trying to basically do the same thing on your own. And for what? Bragging rights? If I'm "just another.." then tell me, what makes you think rolling your own is better? I honestly want to know, because as I said, I did start on your side of the fence. Anyways, I also agree that there's little point in using it if you're only going to use like 1 tiny piece of it. I suppose I will concede that maybe I should amend the OP to weigh the options. But thing is, 9/10 times I see people not using a framework for stuff like AJAX.. turns out the site they are working on is already using a framework. This certainly comes up a lot more for freelancers and coders working in agencies who work with many clients on many sites and it's constantly new sites/clients in the door, vs. some coder working as web dev for a single company. Point being that if you get hired by a client to do some work on their site, it is better to evaluate what they already have going on there and use what's already there, than to just start throwing your own stuff into the mix. If you want to talk about unnecessary bloat, well that's a prime example right there. P.s. - telling me to "keep it civil" right after you've thrown out a "you're just another.." statement.. classy.
  49. 1 point
    Lol first impression was "who the hell is starting yet another thread in caps". But I think many people here agree on what you just wrote. I don't even bother reading vanilla js doing ajax stuff.
This leaderboard is set to New York/GMT-04:00
  • Newsletter

    Want to keep up to date with all our latest news and information?
    Sign Up
×
×
  • 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.