Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation since 03/14/2019 in all areas

  1. 2 points
    If this is a repetitive project that is going to build all of the mentioned arrays every time it is executed, perhaps you should consider not having to re-build your second array by using the SKU as the index value of the first array and avoid creating the 2nd array. Change this: $product_table[] = ['SKU' => $sku, 'Label' => $attribute_name, 'Value' => $term_obj->name ]; to: $product_table[$sku][] = ['Label' => $attribute_name, 'Value' => $term_obj->name ];
  2. 1 point
    ...oh wait, this code is not located on the page that renders Events.php? Okay, this all makes quite a bit more sense now. You can do this showing/hiding stuff with pure CSS, which will also make it work automatically with Events.php#Event1 links. Remove all the Javascript that deals with showing and hiding, including the various onclicks, and add a <style> a.w3-modal:not(:target) { display: none; } </style> to Events.php. The :target selector is true when you hit anchors like #Event1, so that CSS will hide the w3-modals that are not the current anchor. Which also means going to just Events.php (no anchor) will hide all of them by default.
  3. 1 point
    the 'echo'ed sql query statement has some single quotes around the 2nd occurrence of the time column. this 1st showed up in the OPs post. edit: which Barand just posted too without any notification from the form software about a new post in the thread.
  4. 1 point
    You have single quotes arond "time" so it is being treated as a string literal. Use backticks like you have around the previous one.
  5. 1 point
    They are the same. Note the github url on the packagist page. Generally speaking in these situations I start by designing the PHP interface I need and then try and code the necessary drivers to match that interface. As drivers are built it may be necessary to change the interface to accommodate. For example you may start with: interface DeviceController { public function start() : Promise; public function stop() : Promise; public function open() : Promise; public function close() : Promise; //... } Then, foreach device you have to support make a driver that implements that interface, for example: class ModbusRtuDevice implements DeviceController { private $socket; public function __construct(SocketClient $socket){ $this->socket = $socket; } public function start() : Promise { return $this->send('start'); } public function stop() : Promise { return $this->send('stop'); } public function open() : Promise { return $this->send('open'); } public function close() : Promise { return $this->send('close'); } private function send($action) : Promise { $command = json_encode([ 'action' => $action , 'arguments' => [] ]); return $this->socket->sendCommand($data); } } The just code the rest of your application according to the DeviceController interface. I'd focus first on just creating an interface that you'd ideally want. Then focus on implementing a driver for it for whatever your most common device type is. Adjust the interface design where required as problems arise. Once that is working, move on to implementing a driver for the next most common devices. Again, adjust the interface as required but keep in mind your first driver. If a change is needed and avoid just adding some driver specific method/parameter. Adjust the interface to something that works for both devices and make the adjustments to the original driver as needed to accommodate the new interface design. A lot of this is sometimes easier said than done, I know. Sometimes it may take quite a few iterations to really get things in a good place.
  6. 1 point
    Don't use "SELECT star", specify the columns you need. Now you can just encode the results as it contains the columns required. Also you don't seem to have the hang of prepared queries. You don't put post data directly into the query (ever) but use placeholders and pass the values as parameters. if(isset($_POST["name"])) { $query = " SELECT physics , maths , chemistry , biology , sst FROM zeta WHERE name = ? ORDER BY id ASC "; $statement = $connect->prepare($query); $statement->execute( [ $_POST['name'] ] ); $result = $statement->fetchAll(); echo json_encode($result); }
  7. 1 point
    I asked because the data you posted does not match your code ,,,,,,,, ,,,,,,,, ,,,,,,,, ,,,,,,,, ,,,,,,,, ,,,,,,,, ,,,,,,,, ,,,,,,,, ,,,,,,,, ,,,Fields,Physics~75,Maths~50,Chemistry~65,Bio~85,SST~100 ,,,Name1,10,25,35,42,62 ,,,Name2,80,45,45,45,25 ,,,Name3,63,25,63,36,36 ,,,Name4,82,36,75,48,42 ,,,Name5,45,45,78,25,24 ,,,Name6,36,36,15,75,36 ,,,Name7,99,45,24,24,45 ,,,Name8,45,85,85,85,96 | | $row[3] $row[8] The name is in index position 3, not 0. Also, use prepared statements and use PDO instead of mysqli (it makes life easier) $db = pdoConnect(); $db->exec("CREATE TABLE IF NOT EXISTS zeta ( id int not null auto_increment primary key, name varchar(30), physics int, maths int, chemistry int, biology int, sst int ) "); $stmt = $db->prepare("INSERT INTO zeta (name,physics,maths,chemistry,biology,sst) VALUES (?,?,?,?,?,?) "); $fp = fopen('zeta.csv', 'r'); while ($row = fgetcsv($fp)) { if ($row[3]=='Fields' || $row[3]=='') continue; $stmt->execute(array_slice($row,3)); } fclose($fp); Giving mysql> select * from zeta; +----+-------+---------+-------+-----------+---------+------+ | id | name | physics | maths | chemistry | biology | sst | +----+-------+---------+-------+-----------+---------+------+ | 1 | Name1 | 10 | 25 | 35 | 42 | 62 | | 2 | Name2 | 80 | 45 | 45 | 45 | 25 | | 3 | Name3 | 63 | 25 | 63 | 36 | 36 | | 4 | Name4 | 82 | 36 | 75 | 48 | 42 | | 5 | Name5 | 45 | 45 | 78 | 25 | 24 | | 6 | Name6 | 36 | 36 | 15 | 75 | 36 | | 7 | Name7 | 99 | 45 | 24 | 24 | 45 | | 8 | Name8 | 45 | 85 | 85 | 85 | 96 | +----+-------+---------+-------+-----------+---------+------+
  8. 1 point
    I suspect a program failure at this line. $_POST['name'] etc are arrays - you are trying to treat them as string values here. I would $lastId = 99999; // or whatever $sql = "INSERT INTO sports(id_studentfk, mode_stu, sport, id_projfk) values(:value, :mode, :sport, :lastid)"; $stmt = $connect->prepare($sql); foreach ($_POST['name'] as $k => $name) { $mode = $_POST['mode'][$k]; $sport = $_POST['sport'][$k]; if ( $name!='' && $mode!='' && $sport!='' ) $stmt->execute( [ 'name' => $name, 'mode' => $mode, 'sport' => $sport, 'lastid' => $lastId ]); }
  9. 1 point
    As Kicken has already said - if YOUR code is doing the updates that you are trying to monitor afterwards, then by all means alter your code to send you a notification via email or with a simple text file on your server that tells you when and what changed.
  10. 1 point
    The session cookie is an access token. Think about it.
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
×

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.