Jump to content

requinix

Administrators
  • Posts

    15,274
  • Joined

  • Last visited

  • Days Won

    432

Community Answers

  1. requinix's post in Difference between PC development environment and hosting. was marked as the answer   
    Ha. Ha ha. Hahahaha. 
    Yes. And that only scratches the surface of how files work differently between the two.
     
    Always use forward slashes / for file paths. They work on Linux and Windows. Backslashes \ work on Windows but not on Linux. Backslashes are also special in PHP strings, and accidentally writing "path\to\folder" won't even work on Windows (though 'path\to\folder' will).
     
    A leading slash has special meaning, too. Like how \misc on Windows means C:\misc (or whatever drive), /misc on Linux means the root of the filesystem. When locating files on your site, use the DOCUMENT_ROOT as a prefix. It's the path to the public root of your website.

    include($_SERVER['DOCUMENT_ROOT'] . '/misc/mem_header.php');On Windows you'll sometimes see filenames with \ and / mixed. As long as the backslashes are coming from PHP itself (like the DOCUMENT_ROOT) and not your own code that's okay and you don't need to worry about trying to fix it.
  2. requinix's post in Keeping URL Elements after form submission was marked as the answer   
    Make the form submit to the URL you want, and/or make the code redirect to the URL you want.
     
    Really that simple.
  3. requinix's post in creating table from array with different value was marked as the answer   
    This goes so much more easily when you preprocess the data into associative arrays.
     
    $graph is the unserialized array you posted* but without the [age] you added to it.

    <?php foreach ($graph as $grade => $data) { $monitors = $days = []; // preprocess foreach ($data as $data2) { $monitors[$data2["label"]] = []; foreach ($data2["data"] as $data3) { $days[] = $data3["x"]; $monitors[$data2["label"]][$data3["x"]] = $data3["y"]; } } // clean $days = array_unique($days); sort($days, SORT_NUMERIC); // draw table ?> <strong><?=strtoupper($grade)?></strong><br> <table border="1"> <thead> <tr> <th>Monitor Label</th> <?php foreach ($days as $d) { ?> <th><?=$d?>D</th> <?php } ?> </tr> </thead> <tbody> <?php foreach ($monitors as $label => $mdata) { ?> <tr> <td><?=$label?></td> <?php foreach ($days as $d) { ?> <td><?=$mdata[$d] ?? ""?></td> <?php } ?> </tr> <?php } ?> </tbody> </table> <?php } <strong>25P</strong><br> <table border="1"> <thead> <tr> <th>Monitor Label</th> <th>1D</th> <th>2D</th> <th>3D</th> <th>6D</th> <th>7D</th> <th>15D</th> <th>28D</th> </tr> </thead> <tbody> <tr> <td>C81</td> <td>6.220000</td> <td>10.220000</td> <td></td> <td></td> <td>21.440000</td> <td></td> <td>30.780000</td> </tr> <tr> <td>C82</td> <td>8.000000</td> <td></td> <td>20.890000</td> <td>30.670000</td> <td>32.555000</td> <td></td> <td>51.110000</td> </tr> <tr> <td>C83</td> <td>7.110000</td> <td></td> <td>19.780000</td> <td>23.560000</td> <td>32.225000</td> <td>38.890000</td> <td></td> </tr> </tbody> </table>* Please don't post serialized data. It's impossible for humans to read. Post the print_r or var_dump output.
  4. requinix's post in delete account was marked as the answer   
    Our policy is not to delete accounts or content. If you don't want to be an active member anymore then simply don't be an active member anymore.
  5. requinix's post in how to display in html table was marked as the answer   
    If all you want to change is to have those items listed in order then notice that GROUP_CONCAT can sort too.
  6. requinix's post in add a update statment MS SQL in php was marked as the answer   
    Forget about $orderid.
     
    The data is coming from the $sql2 query, right? Every single $orderid came from that query, right? That query is what decided which orderids to return, right? It looked at everything and decided which ones to get, right?
     
    Now you want to do something to all those orders that came back, right? They all get the same treatment, right?
     
    Look at the query you started with. You gave it conditions to match against each order.
     
    Here's where it gets magical:
     
    If you do an UPDATE query with those very same conditions then it'll target the very same orders that the first query returned.
     
    You follow that? So. All you have to do is make a new UPDATE query with the right syntax that does the thing you want it to do, copy those conditions from the earlier SELECT, and run it.
  7. requinix's post in delete from table where NOT IN array was marked as the answer   
    Also works, but with a small problem: the player names are strings, so not only do they need quotes
    $query = "DELETE FROM `garage_list` WHERE `player` NOT IN ('" . implode("','", $cart) . "')";but the names would have to be escaped - or use a prepared statement instead. I went with the account_ids instead since they're numbers which makes it a bit easier, but looking at it now it's not actually that much less work.
  8. requinix's post in Storing credit card details... was marked as the answer   
    Do you? I mean is there a real reason why you can't penalize a non-paying user for skipping out? Is there some reason why a finished auction cannot be restarted due to lack of payment? You could always, say, have the second-highest bidder inherit the winnings if the highest doesn't pay up. 
     
    Anyway, you do have some leverage, whether you like it or not: the technical and business requirements of your application. Whatever gateway must have a way of performing the actions you need - the clients can choose whichever service they want but it must somehow support certain features.
     
    Storing details is out of the question. Don't do it. It's a huge hassle, not to mention a big responsibility with legal ramifications for failure.
     
    The problem you're trying to solve is that you can auth for an amount but if the bids get too high then you're stuck. I can think of a couple possible business-rule solutions to that:
    1. Auth for the initial amount, possibly a bit more, and have the user re-auth if the bidding goes over the limit imposed by the gateway. Or a fixed amount. Whatever.
    2. Implement auto-bidding: user puts down the highest amount they're willing to bid and you auth for that much. Then auto-bidding rules kick in. If the user loses out then they can re-auth for a higher amount.
    3. Act as a sort of gateway yourself. Use whatever actual payment gateway(s) you want, you take all the money directly, then you automatically/periodically transfer funds to the clients. You have full control over everything.
  9. requinix's post in What did he mean when he wrote this? was marked as the answer   
    He's mostly correct but should have been more precise.
     
    If you try to assign to a variable (or property) that does not exist then PHP will (generally) create it for you no problem. In fact for variables this is how you're supposed to do it because there's no way to define them beforehand, unlike properties.

    <?php class Example { } $e = new Example(); $e->no_such_property = 123; var_dump($e); object(Example)#1 (1) { ["no_such_property"]=> int(123) }If you try to read from a variable (or property) that does not exist then PHP will issue a warning and pretend the value is null.
    <?php var_dump($no_such_variable); Notice: Undefined variable: no_such_variable in... NULL <?php class Example { } $e = new Example(); var_dump($e->no_such_property); Notice: Undefined property: Example::$no_such_property in... NULLIf you define the property in the class then that doesn't happen.
    <?php class Example { public $no_such_property; // defines the property with a default value of NULL } $e = new Example(); var_dump($e->no_such_property); NULL
  10. requinix's post in Does the order of an object's properties mean anything? was marked as the answer   
    Order does not matter. Loose object comparison works like an array comparison.
  11. requinix's post in Order of precedent for accessing properties and ternary operators was marked as the answer   
    Yeah, PHP 7 has a number of syntax improvements. You'll have to use the long form.
     
    And yes, $x ?: $y is shorthand for $x ? $x : $y. PHP 7 also adds $x ?? $y which is short for isset($x) ? $x : $y.
  12. requinix's post in How to check token in form created by password_hash() function was marked as the answer   
    Is this token a password? No? Then don't try to make it a password. All you need is a random value, so

    sha1(uniqid(time(), true))is sufficient. 
    Put the value in the form and in the session, then compare the two values. Regular string comparison.
  13. requinix's post in Total number from XML values was marked as the answer   
    Then do that.
    $value = @$counts["Tornado Warning"] + @$counts["Severe Thunderstorm Warning"] + @$counts["Flash Flood Warning"];I'm using @ here because PHP will warn if the warning doesn't exist in the array and its default behavior of evaluating to null is acceptable.
  14. requinix's post in Dynamic populating rows was marked as the answer   
    You're using the part of Bootstrap's styling that sizes boxes. Don't do that.
  15. requinix's post in Pagination output was marked as the answer   
    $page_nums = range($lower_limit, $upper_limit);range() supports counting down, such as from 1 to 0. Add some logic in there to make sure that doesn't happen; I suggest returning an empty array if num_rows == 0.
  16. requinix's post in php function() help... was marked as the answer   
    Actually the problem is your query:

    mysql_query("SELECT * FROM $datatable")You're using a variable $datatable. Variables defined outside of functions are not automatically available inside functions, so $datatable is undefined and the query you execute is
    SELECT * FROMObviously, MySQL complains because the table name is missing. 
    If you want the best advice for what to do then the answer depends on what this function is supposed to represent. Like, why are you moving everything into a function? Is it really just for appearance's sake? That's not that much of a reason: it's the same code just in a different place. In fact, code like that typically does not go into a function because what you're doing to display the data is highly specific to where you're displaying it, and it's unlikely that you'll want to do the exact same thing in another place.
     
    So without knowing much more, I would say to leave the code where it is. You can make it look a nicer by not doing everything within PHP; I would write that code like

    <?php // ... $result = mysql_query("SELECT * FROM $datatable") or die(mysql_error()); ?> <table border="1"> <tr> <th>Date</th> <th>Dose</th> <th>INR</th> <th>Notes</th> <th>Script</th> <th>Action</th> <th></th> </tr> <?php while ($row = mysql_fetch_array($result)) { ?> <tr> <td><?=$row["date"]?></td> <td><?=$row["dose"]?> mg.</td> <td><?=$row["inr"]?></td> <td><?=$row["notes"]?></td> <td><?=$row["script"]?></td> <td>Edit | Delete</td> </tr> <?php } ?> </table>Visually speaking, I think that's a big improvement upon what you have now. 
    PHP 5.6 is dead. Time to upgrade: 7.1 if you can, 7.0 at a minimum. Better to do it now than have to deal with it later.
  17. requinix's post in PHP issues with mysqli extension and PDO, pdo_mysql extensions was marked as the answer   
    You have 7.0 installed but CentOS has 7.1 in their repos. Try

    yum install php70w-mysqliAs for multiple versions, don't. Until you understand how your OS does packaging, use whatever version they provide. That probably means uninstalling PHP 5.whatever and 7.0 you have now and installing 7.1 instead.
  18. requinix's post in php, ajax, sessions and security was marked as the answer   
    Sessions are managed with cookies and the browser will make that all work automatically with the AJAX.
     
    I wouldn't expect that you'd need to worry about CSRFs for this. It's not like the queries are performing any actions - what CSRFs are really about. But if you still need to have it then pass the token in the AJAX request; how you do that varies but probably means putting the token into the page with your PHP and appending it to the AJAX URL or including it in the request data.
  19. requinix's post in data integrity of data stored using drop down lists. was marked as the answer   
    User ID? I didn't say anything about a user ID...
     

    SELECT whatever you want if anything at all FROM countries co JOIN states st ON co.id = st.country JOIN cities ct ON st.id = ct.state JOIN pins p ON ct.id = p.city WHERE co.id = ? AND st.id = ? AND ct.id = ? AND p.id = ?The query will only return a result if the four IDs exist and they are related to each other.
  20. requinix's post in Search function only return values with exact match was marked as the answer   
    Case-sensitivity in MySQL is dictated by the collation used.
     
    All of yours are

    COLLATE utf8_binutf8_bin, which means UTF-8 (good) with binary comparisons (bad). Your table has that as a default. Your database probably has it as a default too. 
    Change everything that you want to be case-insensitive to use a case-insensitive collation. Do

    SHOW COLLATION WHERE Charset = 'utf8';and pick one of the *_ci collations by reading the names and using common sense. If you're not confident in your choice, post the list. 
    Then use ALTER TABLE statements to change the columns. ALTER TABLE can also do the table's default collation and ALTER DATABASE will do the database's.
  21. requinix's post in Need help in split function utf8 string was marked as the answer   
    Seems .split is not Unicode safe. Seems like ECMAScript says it should be...
     
    Use .match(RegExp) instead. With the /u flag it will match every Unicode character in the string.

    numbers = what.match(/./gu);
  22. requinix's post in Is there any downsides to using this method to randomly select a user id from a table? was marked as the answer   
    Yes, it will be slow.
     
    If you only want one then do

    SELECT COUNT(1) FROM users WHERE active = :active SELECT user_id FROM users WHERE active = :active LIMIT x, 1where "x" is the value from the first query.
  23. requinix's post in How to validate html input strings was marked as the answer   
    The embed snippets all look the same. Just ask the user for the URL to the video, parse_url() it until you reach the video ID, and make the snippet yourself.
  24. requinix's post in Should exceptions ever be thrown with optional second argument for code? was marked as the answer   
    Throwable is an interface with a getCode method. Exception implements Throwable. That's why there are two.
     
    If you have a numeric code to include there then you should use it. Personally I've haven't found it to be useful.
  25. requinix's post in SimpleXMLElement error loading string was marked as the answer   
    Stop touching the raw XML. Leave it alone. If you want to fix the name and... whatever you're doing to the plot... then do it after the XML has been loaded and do it to those variables you're using.

    $data = get_url('http://'.$API_SERVER.'./channels.php?token='.$API_TOKEN); header("Content-Type: text/plain"); echo $data; exit; $API_CHANNELS = simplexml_load_string($data); $title = (string)$API_CHANNEL->name; $title = preg_replace('#(.*?) \(.*?\)#s', '$1', $title);If you do what I said there then you won't see M3U stuff and you will see XML. I'll ask again: what XML do you see?
×
×
  • 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.