Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. $sql = "SELECT firstname, lastname FROM Players WHERE Username = ?"; $stmt = $conn->prepare($sql); $stmt->bind_param('s', $username); $stmt->execute(); // either $stmt->bind_result($firstname, $lastname); $stmt->fetch(); echo $firstname . ' ' . $lastname; // or $res = $stmt->get_result(); $row = $res->fetch_assoc(); echo $res['firstname'] . ' ' . $row['lastname'];
  2. try $maxshipping=0; foreach ($_SESSION['products'] as $prod) { $maxshipping = max($maxshipping, $prod['shipping1']); } echo $maxshipping;
  3. the code is OK so either item_id is not 22 code is not executed
  4. Don't run queries in loops. To do this use a recursive function on your data stored in an array. This code will store your data in the array $data. $data[ref_id][referrers] will be an array of the chain of referrers for each user. EG Array ( [J1234] => Array ( [acct_name] => john [refer_id] => 0 [referrers] => Array ( ) ) [B3456] => Array ( [acct_name] => bull [refer_id] => J1234 [referrers] => Array ( [0] => J1234 ) ) [D5567] => Array ( [acct_name] => doe [refer_id] => J1234 [referrers] => Array ( [0] => J1234 ) ) [F7788] => Array ( [acct_name] => frank [refer_id] => J1234 [referrers] => Array ( [0] => J1234 ) ) [J9990] => Array ( [acct_name] => jimmy [refer_id] => J1234 [referrers] => Array ( [0] => J1234 ) ) [T6784] => Array ( [acct_name] => tommy [refer_id] => F7788 [referrers] => Array ( [0] => F7788 [1] => J1234 ) ) [T9988] => Array ( [acct_name] => tom [refer_id] => F7788 [referrers] => Array ( [0] => F7788 [1] => J1234 ) ) [G8866] => Array ( [acct_name] => girly [refer_id] => D5567 [referrers] => Array ( [0] => D5567 [1] => J1234 ) ) [F0099] => Array ( [acct_name] => fred [refer_id] => J9990 [referrers] => Array ( [0] => J9990 [1] => J1234 ) ) [R7722] => Array ( [acct_name] => ronaldo [refer_id] => B3456 [referrers] => Array ( [0] => B3456 [1] => J1234 ) ) ) the code $sql = "SELECT id , acct_name , ref_id , refer_id FROM test_referral"; $data = array(); $res = $mysqli->query($sql); while ($row = $res->fetch_assoc()) { $data[$row['ref_id']] = array( 'acct_name' => $row['acct_name'], 'refer_id' => $row['refer_id'], 'referrers' => array() ); } foreach ($data as $id => $user) { getRef($data, $data[$id]['refer_id'], $id); } // // recursive function to get list of referrers // function getRef(&$data, $id, $startid) { if ($id=='0') return; $data[$startid]['referrers'][] = $id; getRef($data, $data[$id]['refer_id'] ,$startid); } That will work for any depth of referrals. Where you have a fixed depth then you can use a query with a couple of left joins SELECT r.id , r.acct_name , r.ref_id , r1.ref_id as first , r2.ref_id as second FROM test_referral r LEFT JOIN test_referral r1 ON r.refer_id = r1.ref_id LEFT JOIN test_referral r2 ON r1.refer_id = r2.ref_id; +----+-----------+--------+-------+--------+ | id | acct_name | ref_id | first | second | +----+-----------+--------+-------+--------+ | 1 | john | J1234 | | | | 2 | bull | B3456 | J1234 | | | 3 | doe | D5567 | J1234 | | | 4 | frank | F7788 | J1234 | | | 5 | jimmy | J9990 | J1234 | | | 6 | tommy | T6784 | F7788 | J1234 | | 7 | tom | T9988 | F7788 | J1234 | | 8 | girly | G8866 | D5567 | J1234 | | 9 | fred | F0099 | J9990 | J1234 | | 10 | ronaldo | R7722 | B3456 | J1234 | +----+-----------+--------+-------+--------+
  5. By default, when you sort an array of arrays, the arrays are sorted on the first element. So you could put the distance at the start of each array and then just sort(). $results = [ [5, 'abc', 'defg'], [8, 'def', 'efg'], [12, 'ghj', 'fghij'], [10, 'klm', 'ghijk'], [8, 'nop', 'lmn'], ]; sort($results); echo '<pre>SORTED ',print_r($results, true),'</pre>'; gives SORTED Array ( [0] => Array ( [0] => 5 [1] => abc [2] => defg ) [1] => Array ( [0] => 8 [1] => def [2] => efg ) [2] => Array ( [0] => 8 [1] => nop [2] => lmn ) [3] => Array ( [0] => 10 [1] => klm [2] => ghijk ) [4] => Array ( [0] => 12 [1] => ghj [2] => fghij ) )
  6. Or you could sidestep the problems and not allow any dates after the 28th of any month edit : If the recurring value is monthly or higher
  7. You could add COUNT(DISTINCT l.likes_username) as userCount to the select clause
  8. Does this help? SELECT trans_ref , acct_num , payee , company , acct_no , amt , purpose , recurring , due_date , CASE recurring WHEN 'weekly' THEN due_date + INTERVAL 7 DAY WHEN 'bi-weekly' THEN due_date + INTERVAL 14 DAY WHEN 'monthly' THEN due_date + INTERVAL 1 MONTH WHEN 'quarterly' THEN due_date + INTERVAL 3 MONTH WHEN 'half-yearly' THEN due_date + INTERVAL 6 MONTH WHEN 'yearly' THEN due_date + INTERVAL 1 YEAR END as next_due , status , pay_status FROM $tbl_name ORDER BY trans_id DESC LIMIT $start, $limit And throw away that useless first query.
  9. I really don't know whether to laugh or cry when I read your code. You are supposed to incorporate the CASE statement that Kicken gave you into your query so you calculate the next_due for every row.
  10. Then you are processing the results incorrectly mysql> SELECT recurring, due_date, -> CASE recurring -> WHEN 'weekly' THEN due_date + INTERVAL 7 DAY -> WHEN 'bi-weekly' THEN due_date + INTERVAL 14 DAY -> WHEN 'monthly' THEN due_date + INTERVAL 1 MONTH -> WHEN 'quarterly' THEN due_date + INTERVAL 3 MONTH -> WHEN 'half-yearly' THEN due_date + INTERVAL 6 MONTH -> WHEN 'yearly' THEN due_date + INTERVAL 1 YEAR -> END as next_due -> FROM tblchidi; +-----------+------------+------------+ | recurring | due_date | next_due | +-----------+------------+------------+ | monthly | 2014-12-25 | 2015-01-25 | | Bi-Weekly | 2014-12-10 | 2014-12-24 | | yearly | 2014-12-20 | 2015-12-20 | | quarterly | 2014-12-24 | 2015-03-24 | +-----------+------------+------------+
  11. You should notice that my code uses mysqli (as you should, or PDO) Instead of : mysql_select_db($database_conexxion, $conexxion); use this to create a mysqli connection: $mysqli = new mysqli (host, username, password, databasename); using your credentials.
  12. Create a table "whatever" (where whatever is a meaningful name for the data) and load the data into it. Once it is in a table you can manipulate further if required. CREATE TABLE `whatever` ( `id` int(11) NOT NULL AUTO_INCREMENT, `url` varchar(255) DEFAULT NULL, `name` varchar(45) DEFAULT NULL, `cname` varchar(45) DEFAULT NULL, PRIMARY KEY (`id`) ) With the exception of the single quotes instead of double quotes, each line looks as though it is json encoded, so you could loop through each line, decode and insert into the table.
  13. What are the relationships between the entities represented by each line and those contained within each line?
  14. Strange you got no results. I ran the code against your data and got this (I reversed the order of the column heads)
  15. Without data, that's all I can do.
  16. Easiest way is <ol> <li>Product</li> ... </ol>
  17. One suggestion that I would make is to change the WHERE condition. You are doing a left join on table a so there may not be a matching record so use the schedule table ids in the where clause. I.E. change AND (h.teamid=$teamid OR a.teamid=$teamid) to AND (s.homeid=$teamid OR s.awayid=$teamid) or you could use this alternative AND $teamid IN (s.homeid, s.awayid)
  18. So you would have two tables and use a join to match on tag +-----+-------------+------------+ | ID | title | imageURL | +-----+-------------+------------+ | 1 | abc | /im/abc.jpg| | 2 | xyz | /im/xyz.jpg| +-----+-------------+------------+ | | +---------------+ | +--------+-------------+ |imageID | tag | +--------+-------------+ | 1 | animal | | 1 | dog | | 1 | snow | | 2 | mountains | | 2 | snow | +--------+-------------+ Example SELECT i.ID, i.title FROM images i JOIN tags t ON i.ID = t.imageID WHERE t.tag = 'snow'
  19. Correction to above, main query should be GROUP BY esfera, cilindro SELECT sum(compra+regula_mas-venta-taller-regula_menos) as stock , cilindro , esfera FROM movimiento JOIN item ON item.id_item=movimiento.id_item JOIN rx ON rx.id_rx=item.id_rx JOIN cilindro ON cilindro.id_cil=rx.id_cil JOIN esfera ON esfera.id_esf=rx.id_esf GROUP BY esfera, cilindro ORDER BY esfera DESC
  20. try something like this with a single query <?php // // GET CILINDRO VALUES // $sql = "SELECT cilindro FROM cilindro ORDER BY cilindro"; $cilindro = array(); $res = $mysqli->query($sql); while ($row = $res->fetch_row()) { $cilindro[] = $row[0]; } $thead = "<tr><th></th><th>" . join('</th><th>', $cilindro) . "</th></tr>\n"; $initial = array_fill_keys($cilindro, ''); // empty initial array for each row // // GET STOCK VALUES // $sql = "SELECT sum(compra+regula_mas-venta-taller-regula_menos) as stock , cilindro , esfera FROM movimiento JOIN item ON item.id_item=movimiento.id_item JOIN rx ON rx.id_rx=item.id_rx JOIN cilindro ON cilindro.id_cil=rx.id_cil JOIN esfera ON esfera.id_esf=rx.id_esf GROUP BY movimiento.id_item ORDER BY esfera DESC"; $tdata = ''; $currEsfera = ''; $esfdata = $initial; $res = $mysqli->query($sql); while (list($stock,$cil, $esf) = $res->fetch_row()) { if ($esf != $currEsfera) { // change of esfera? if ($currEsfera) { // don't want initial balank values $tdata .= "<tr><td>$currEsfera</td><td>".join('</td><td>', $esfdata)."</td></tr>\n"; } $currEsfera = $esf; $esfdata = $initial; } $esfdata[$cil] = $stock; } // output row for final esfera value $tdata .= "<tr><td>$currEsfera</td><td>".join('</td><td>', $esfdata)."</td></tr>\n"; ?> <table border='1'> <?php echo $thead, $tdata?> </table>
  21. The & is actually & which gives the extra four characters 34 4 20 48 H 61 a 6e n 64 d 73 s 20 53 S 75 u 67 g 61 a 72 r 20 26 & 61 a 6d m 70 p 3b ; 20 53 S 70 p 69 i 63 c 65 e
  22. Why don't you incorporate the colore into your hazards array. For example $hazard_array = array ( array ('Air Quality Alert', 'rgba(128, 128, 128, 0.4)'), array ('Child Abduction Emergency', 'rgba(255, 215, 0, 0.4)'), array ('Fire Weather Watch', 'rgba(255, 222, 173, 0.4)'), array ('Red Flag Warning', 'rgba(255, 20, 147, 0.4)'), array ('Special Weather Statement', 'rgba(255, 228, 181, 0.4)') ); foreach ($hazard_array as $ha) { $spanStyle = "background-color:{$ha[1]};border:solid 1px #333;width:15px;height:10px;display:inline-block;"; echo "<span style='$spanStyle'> </span> {$ha[0]}<br>"; } Gives
  23. How prophetic is that ?
  24. That error message is generally a result of your query failing due to an error. See what mysqli_error contains http://php.net/manual/en/mysqli.error.php
  25. Use column aliases. SELECT i.ID as instructorID , c.ID as classID , i.instructor , `class title` FROM instructor i INNER JOIN classes c USING (Instructor) Don't uses column names containing spaces. The classes table should contain the instructor id (as a foreign key) and not the name. The name should only appear in the instructor table.
×
×
  • 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.