Jump to content

Barand

Moderators
  • Posts

    24,338
  • Joined

  • Last visited

  • Days Won

    795

Everything posted by Barand

  1. For a start, too many "UNIONS". SELECT MONTH(due_date) as month , SUM(amount_paid) as total FROM ( SELECT due_date, amount_paid FROM table1 UNION ALL SELECT due_date, amount_paid FROM table2 )x GROUP BY month If you are having to do that, it looks like your table1 and table2 should be a single table with an additional identifier column.
  2. I see you are still adhering to the mantra "Why run one query when six will do?" https://forums.phpfreaks.com/topic/302526-divide-by-zero-warning/?do=findComment&comment=1539284
  3. Yes, that's OK. So long as they are both on the same server. The connection is to the server. And, as you said, you have privileges to access all databases in the query.
  4. Have you re-run the code to see what the errors are?
  5. You have several syntax errors. Turn on error reporting and it will tell you where they are. Put this code at top of your code error_reporting(E_ALL); ini_set('display_errors', 1);
  6. Did you run benanamen's code so you can see what your result's structure actually look like? I showed you how to process the results array. What more do you need?
  7. @kian3210 Three things Don't highjack someone else's post That is not PHP code - this is a PHP code help forum (moving to javascript forum) Use code tags for code
  8. I think it's a contest. The first person to work out what his input was wins the prize.
  9. Your $array contains a sub-array (results) of bus journeys, so you need foreach ($array['results'] as $bus) { echo $bus['destination]; // ... etc }
  10. Don't resurrect 6 year old posts
  11. Horses for courses. It depends on where you will use the function. If it is specific to one page, define it in that page. If it is used by more than one page then define it in a separate file. So some will be defined in the page, some in an application-specific function file and some in general function file.
  12. You need to provide your db credentials in the first $pdo line (database, username and password) $dbhost = 'localhost'; $dbuser = '****'; $dbpass = '****'; $database = '****'; $pdo = new PDO("mysql:host=$dbhost; dbname=$database", $dbuser, $dbpass);
  13. Did you create a PDO connection instead of the mysql_connect()? $pdo = new PDO("mysql:host=".HOST.";dbname=".DBNAME,USERNAME,PASSWORD); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  14. The content data is JSON encoded, so you need to decode it then access the content fields if (isset($_GET['zoeknummer'])) { $sql = "SELECT lead_content FROM lead"; $res = $pdo->query($sql); // where $pdo is your db connection while ($lead = $res->fetchColumn()) { $data = json_decode($lead); if ($data->zoeknummer == $_GET['zoeknummer']) { echo $data->komplex . ' : ' . $data->plaats . '<br>'; } } }
  15. When you pack all your data into a single column you give yourself no option other than select all the data. Construct you table correctly. CREATE TABLE `lead` ( `zoeknummer` int(11) NOT NULL, `komplex` varchar(45) DEFAULT NULL, `plaats` int(11) DEFAULT NULL, `versturen` tinyint(4) DEFAULT NULL, PRIMARY KEY (`zoeknummer`) ) +------------+---------+--------+-----------+ | zoeknummer | komplex | plaats | versturen | +------------+---------+--------+-----------+ | 110022 | test 1 | 1 | NULL | | 112255 | test 2 | 12 | NULL | | 554477 | test 4 | 84 | NULL | | 556478 | test 3 | 51 | NULL | +------------+---------+--------+-----------+ If you are just learning, learn PDO with you MySQL database and don't waste any more time with the mysql_ set of functions. These have been removed from PHP. As you are just fetching data to display, use GET instead of POST. Use POST for updating data. Your code would now be if (isset($_GET['zoeknummer'])) { $sql = "SELECT komplex , plaats FROM lead WHERE zoeknummer = ?"; $stmt = $pdo->prepare($sql); // where $pdo is your db connection $stmt->execute([ $_GET['zoeknummer'] ]); if ($row = $stmt->fetch()) { echo $row['komplex'] . ' : ' . $row['plaats']; } }
  16. try $timestamp = $output2['data'][$acc_id]['last_battle_time']; $dt1 = new DateTime(); $dt1->setTimestamp($timestamp); $dt2 = new DateTime(); echo ceil($dt1->diff($dt2)->days / 7) * 7;
  17. A recursive function is one that calls itself. So you pass an id to the function. The function than finds the next id. It then calls itself passing this new id. I came up with this, but not sure if it does exactly what wanted so you may need to tweak it. <script type="text/javascript"> var divs = []; $().ready(function() { $(".button").click(function() { divs = []; // clear results getLinkedDivs(this.id, "one"); // search data-one getLinkedDivs(this.id, "two"); // search data-two alert(divs.join(", ")); // show results }) }) function getLinkedDivs(id, dnum) { var dnum2 = dnum=="one" ? "two" : "one"; var div1 = $("div[data-"+dnum+"="+id+"]"); if (div1.length) { divs.push($(div1).attr("id")); var id1 = $(div1).data(dnum2); divs.push(id1); getLinkedDivs(id1, dnum); // call itself with next id } } </script>
  18. There are various functions in PHP for displaying dates/times and doing arithmetic with them. Before you use any of them, make sure you have set your default timezone. You can do this in your php.ini file or by using date-default-timezone-set. The easiest to use is the date function.
  19. A better way to do it is to have 1 row for each day for each user. CREATE TABLE `advent` ( `userid` int(11) NOT NULL, `day` int(11) NOT NULL, `opened` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0 or 1', PRIMARY KEY (`userid`,`day`) ) ; Then the update is simply UPDATE advent SET opened = 1 WHERE userid=? and day=?;
  20. @cyberRobot - the database is included in the connect parameters @lrghifra - a couple of problems When you bind the the parameters (3 of them) you are defining 4 types ("siss") You are defining the response as empty array and not the query results
  21. Use a recursive function to find the divs
  22. I did wonder if that were the case. Replace $certres = min($marks) >= 50 ? "Entitle for Cert $cert" : 'Complete only'; with $certres = "Entitle for Cert $cert"; for ($lvl=1; $lvl<=$cert; $lvl++) { if (min($studata[$lvl]) < 50) { $certres = 'Complete only'; break; } } That will check previous levels and not just the current level (NOTE this code occurs twice - inside the loop and after the loop to output the final student)
×
×
  • 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.