Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/09/2022 in all areas

  1. or... $res = $pdo->query("SELECT `option`, total FROM vote"); $data = $res->fetchAll(); $votes_cast = array_sum( array_column($data, 'total') ); foreach ($data as $r) { printf ("%s has %d votes (%0.1f %%)<br>", $r['option'], $r['total'], $r['total']*100/$votes_cast); }
    1 point
  2. You don't need dayofweek in attendance table for the same reason you don't need month and year columns. They are derived from the entry date so you are just duplcating data and creating unnecessary columns. mysql> SELECT YEAR('2022-06-09') as year -> , MONTH('2022-06-09') as month -> , DAYOFWEEK('2022-06-09') as dow; +------+-------+------+ | year | month | dow | +------+-------+------+ | 2022 | 6 | 5 | +------+-------+------+ Care to share?
    1 point
  3. OK, so unfortunately Carbon doesn't have a native formatter for that. So one way or another, I think you're going to have to touch all of your models as they all extend from Illuminate\Database\Eloquent\Model and if you override that base class you'll have to update all the use statements. That being the case, I'd look to either global scopes or accessors to handle your case.
    1 point
  4. A good website to understand PDO that I found is this one -> https://phpdelusions.net/pdo and I suggest creating a PHP sandbox to play around with PDO. After reading this thread I think you're concentrating too much on the mysql and other databases (which PDO can handle) than PHP PDO? I have been using PDO for sometime now, but I don't think it's easier to learn than mysqli, though once learned it is more versatile.
    1 point
  5. I don't see how they can be. They may not be right but they must be different. You stated that WS occured on Saturday mornings, so why would there be more than 1 per week? (each serid only appeared on one date in the test data you provided) You came here with a problem and I helped you. Now a shedload of never before mentioned requirements and conditions suddenly appear. How many more will creep out of the woodwork? I don't like "mission creep" . As well as only accepting live services (aforementioned where condition) you could also specify the day of week for each service +-------+----------------+--------------+-----------+ | serid | service_name | service_code | dayofweek | 1=Sun,..,7=Sat +-------+----------------+--------------+-----------+ | 1 | Prayer meeting | PM | 4 | | 2 | Worship | WS | 7 | | 3 | Thanks giving | PBB | 7 | | 4 | LS | LS | NULL | unspecified | 5 | Thanks giving | D1 | NULL | | 6 | Thanks giving | D2 | NULL | | 7 | Thanks giving | D3 | NULL | +-------+----------------+--------------+-----------+ and only process dates/services that match those specified days. That will limit them to one per week. The two queries then become -- -- headers query -- SELECT DISTINCT weekofyear(entrydate) - weekofyear(?) + 1 as wk_no , date_format(entrydate, '%e/%c') as edate , concat(date_format(entrydate, '%d'), ' ', service_code) as dayser , service_code FROM attendance a JOIN service s ON a.serid = s.serid AND (dayofweek(a.entrydate) = s.dayofweek OR s.dayofweek IS NULL) WHERE month(entrydate) = ? AND stype = 1 ORDER BY entrydate, a.serid; -- -- member attendance query -- SELECT weekofyear(entrydate) - weekofyear(?) + 1 as wk_no , concat(date_format(entrydate, '%d'), ' ', service_code) as dayser , group_no , mem_name , memid FROM attendance a JOIN member m USING (memid) JOIN service s ON a.serid = s.serid AND (dayofweek(a.entrydate) = s.dayofweek OR s.dayofweek IS NULL) WHERE month(entrydate) = ? AND stype = 1 ORDER BY group_no, mem_name, dayser
    1 point
  6. the php mysqli extension on your system must be compiled to use the mysqlnd driver, for the get_result and a few other functions/methods to be available - https://www.php.net/manual/en/mysqlnd.install.php i'm not sure this can be accomplished just through the hosting control panel. you will know when you are successful when there is a mysqlnd section in the phpinfo() output on your system. if you cannot enable this, your choices are, rewrite the code to - use the much simpler, more consistent, and better designed PDO extension. it has no mysqlnd driver gotya's like this. eliminate the use of the mysqli get_result function/method, which will require you to use mysqli_stmt::bind_result, and a bunch of code to dynamically fetch data as a result set or do a bunch of typing for all the columns/variables you are selecting from each query. however, if you are going to go through this much work, for each query, you might as well just spend the time to do item #1. converting a mysqli prepared query to use the PDO extension is fairly straight forward - make the database connection using PDO, storing the connection in a variable uniquely named, such as $pdo, so that you can identify/search which code has been converted or not. the use of ? positional prepared query place-holders is the same between mysqli and PDO. change the $mysqli->prepare() calls to use the $pdo connection variable, e.g. $pdo->prepare(). take the list of variables you are supplying to the ->bind_param() call, and supply them as an array to the ->execute([...]) call. remove the bind_param() calls and the get_result() calls. fetch the data using one of PDO's fetch methods - fetch(), fetchAll(), ... note: if you are using a foreach() loop to iterate over the msyqli result object (from the get_result call), you can loop over the PDO statement object in exactly the same way. for a non-prepared query, you would just use the PDO ->query() method instead of the mysqli ->query() method, then fetch/loop over the data as described above. any use of last insert id, num rows, or affected rows would need to use the equivalent PDO statements.
    1 point
  7. Diid you try switching off then on again 😀
    1 point
  8. As your CMS is using mysqli there isn't much you can do at that end (unless you want to rewrite it using PDO instead). You need to ensure that whatever version of MySql you use is implemented with the native driver (mysqlndnd) [PS] https://dev.mysql.com/downloads/connector/php-mysqlnd/
    1 point
  9. mysqli::get_result() is not available on all implementations Another reason to ditch mysqli for PDO.
    1 point
  10. Sure would help if you posted the rest of the output, not just the first line of it.
    1 point
This leaderboard is set to New York/GMT-05:00
×
×
  • 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.