Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. I was thinking something like this $data = array(); foreach ($accounts_data as $adata) { $data[$adata['id']]['name'] = $adata['name']; $data[$adata['id']]['dates'] = array(); } foreach ($followers_data as $fdata) { $id = $fdata['account_id']; $data[$id]['dates'][$fdata['date_time']] = $fdata['followers']; } echo '<pre>',print_r($data, true),'</pre>';
  2. ginerjm Instead of being so ready to criticise the OP about not writing a better query, read the post and you'll see the data comes via an API Frankchester You could structure your accounts array as id => array ('name' => accountname) Then loop through the second array. Using the id as the key, append to that id's array in the first table. Your "dates" subarray structure probably just needs to be dates = array ( $date => $followers) instead of creating the extra level with dates = array ($date = array('followers' => $followers))
  3. You need to store in $_SESSION insterad of creating a new array each time one is posted session_start(); var_dump( $_POST); if (!isset($_SESSION['items'])) { $_SESSION['items'] = array(); } if(isset($_POST['item']) && !empty($_POST['item'])) { $_SESSION['items'][] = $_POST['item']; } Use session_start() and this same session array in the form page to list current items Note: unless you then save to a file or db table the items will be lost when the session ends.
  4. I have come across this model a couple of times. My test model is attached. Basically, products belong to categories and each category would have its own set of attributes (for example a camera will have a different set of attributes from a bed). Also the attributes have a start date/end date to allow, for example, price changes over time. The technique I used was to to create a table subquery to join the required attribute values into a single row which could be sorted, filtered etc. To make life easier I created a function which took an array of the required attribute ids and generated the required subquery. See this thread reply http://forums.phpfreaks.com/topic/277085-the-eav-model-or-something-better/?do=findComment&comment=1431597
  5. Have you looked at http://php.net/manual/en/function.parse-url.php
  6. ... or your $start contains 0 (have you misspelled $start in your code). Given your start and end, it should produce $start = 1416165131.3015; $end = 1416165131.4172; $diff = ($end - $start)*1000; echo $diff . ' ms'; // 115.70000648499 ms
  7. Databases were designed for filtering and sorting, it's what they do. Use the power of the query.
  8. Depends on how it is "broken". Could be that it defaults to US, or maybe it always returns "true"
  9. First thing to do is connect to your database server and set the default database http://php.net/manual/en/mysqli.construct.php Then you you need to query your database table and get the result set http://php.net/manual/en/mysqli.query.php The query you need will be "SELECT ing_title FROM content_langs WHERE ing_contID = 1" Next, get the record from the result set http://php.net/manual/en/mysqli-result.fetch-assoc.php Examples on the above page links should help you
  10. For the benefit of those looking for a solution, there are two ways 1. Using PHP date() function to format the date output $sql = "SELECT thedate FROM dates"; $res = $db->query($sql); list($thedate) = $res->fetch_row(); echo "| $thedate | " . date('d:m:Y', strtotime($thedate)) . " |<br>"; /* OUTPUT | 2014-11-16 | 16:11:2014 | */ 2. Using MySQL DATE_FORMAT() function mysql> SELECT -> thedate -> , DATE_FORMAT(thedate, '%d:%m:%Y') as formatted -> FROM dates; +------------+------------+ | thedate | formatted | +------------+------------+ | 2014-11-16 | 16:11:2014 | +------------+------------+
  11. Invalid, or zero, dates show as 1970-01-01 (day 0 in unix time)
  12. SELECT c.id, c.title, c.time, c.removed1, c.removed2, ct.reps, m1.username as user1, m1.member_first_name as firstname1, m1.member_last_name as lastname1, m2.username as user2, m2.member_first_name as firstname2, m2.member_last_name as lastname2, FROM conversation as c JOIN members as m1 ON c.member1 = m1.id JOIN members as m2 ON c.member2 = m2.id JOIN ( SELECT c.title, COUNT(*) as reps FROM conversation GROUP BY title ) as ct ON c.title = ct.title WHERE ((c.member1='{$memberid}' AND c.read1='No' AND c.removed1='No' ) OR (c.member2='{$memberid}' AND c.read2='No' AND removed2='No' )) AND c.id2='1' ORDER BY c.id DESC
  13. Does this give what you want? <?php // players in order of best to worst $players = array ( 1 => 'Player_1', 'Player_2', 'Player_3', 'Player_4', 'Player_5', 'Player_6', 'Player_7', 'Player_8', 'Player_9', 'Player10', 'Player11', 'Player12', ); // put player12 into an array 12 times, player11 11 times etc $adjusted = array(); foreach ($players as $k=>$p) { $tmp = array_fill(0,$k,$p); $adjusted = array_merge($adjusted, $tmp); } shuffle($adjusted); $adj = array_unique($adjusted); echo '<pre>',print_r($adj, true),'</pre>'; ?>
  14. Not offhand, member. I don't know what your $adjusted array looks like.
  15. You need an "ALTER TABLE" query to add the new columns http://dev.mysql.com/doc/refman/5.6/en/alter-table.html
  16. When you use switch($num) the case values should be possible values of $num eg switch ($dayOfWeek) { case 6: echo "Saturday"; break; case 0: echo "Sunday"; break; default: echo "Weekday"; break; } Alternatively, as in_array() returns true or false, you could switch (true) { case $dow == 6: echo "Saturday"; break; case $dow == 0: echo "Sunday"; break; default: echo "Weekday"; break; } Also, the string concatenation operator in PHP is a period (.) and not '+'
  17. Your message table does not contain a link to the message it is replying to, so how do expect to count the replies?
  18. To expand a variable inside a string the string has to be in double quotes. You have used single quotes. Where is $row defined? Where is that input tag supposed to finish?
  19. Why? You use GROUP BY c.id. If id is unique, and it probably is, then you you get a total count of 1 per id. What are you trying to count in "reps"?
  20. Very confusing SQL queries. When you have a table like your "conversation" table which references two member ids it is usual to connect the member table twice with different aliases and not the conversation table. It is much better to to use explicit join syntax rather then "...FROM A,B,C WHERE...". it is more efficient it separates the structure of the query from the record selection criteria eg SELECT m1.username as user1, m2.username as user2, .... FROM conversation c JOIN member m1 ON c.member1 = m1.id JOIN member m2 ON c.member2 = m2.id WHERE .....
  21. I suggest you check your function showCountryContentInPage()
  22. It may be the relative directory path. You have defined $dir = '/images/advisory'; but in your img tags you use "images/advisory" without the preceding "/". Also, why the <form> tags when you have no form inputs?
  23. Further to my previous post, here is an example using an SVG overlay (assumes your image is "keys.png" and is in the same folder) <?php function segments($cx,$cy,$rad) { $off = 23; $segs = array ( 1 => array($off, -$off), 2 => array(-$off, -$off), 3 => array(-$off, -$off), 4 => array(-$off, $off), 5 => array($off, $off), 6 => array($off, $off) ); $svg=''; $prevtheta = deg2rad(-35); $x1 = $cx + $rad * cos($prevtheta); $y1 = $cy - $rad * sin($prevtheta); $cumval = 0; $vals = array(1=>68,56,56,68,56,56); $total = array_sum($vals); foreach ($vals as $k=>$n) { $cumval += $n; $theta = deg2rad($cumval/$total * 360-35); $x = $cx + $rad * cos($theta); $y = $cy - $rad * sin($theta); $cy1 = $cy + $segs[$k][0]; $cy2 = $cy + $segs[$k][1]; $svg .= "<path class='segment' d='M $cx $cy1 L $x1 $y1 A $rad $rad 0 0 0 $x $y L $cx $cy2 Z' data-segment='$k'/>\n"; $x1 = $x; $y1 = $y; $prevtheta = $theta; } return $svg; } ?> <html> <head> <title>sample</title> <style type="text/css"> .segment { stroke: none; stroke-width: 2px; fill: #eee; fill-opacity: 0; cursor: pointer; } .segment:hover { fill-opacity: 0.1; } #bullseye:hover { fill-opacity: 0.5; fill: #f66; } </style> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript"> $().ready(function() { $(".segment").click(function() { var seg = $(this).data("segment"); // click actions for segments switch (seg) { case 0: alert("Zero"); break; case 1: alert("One"); break; case 2: alert("Two"); break; case 3: alert("Three"); break; case 4: alert("Four"); break; case 5: alert("Five"); break; case 6: alert("Six"); break; } }) }) </script> </head> <body> <div> <svg width='621' height='502' viewBox='0 0 621 502'> <image x="0" y="0" width="621" height="408" xlink:href="keys.png" /> <?=segments(310,191,181)?>; <circle id='bullseye' class='segment' cx="310" cy="191" r="35" data-segment='0' /> </svg> </div> </body> </html>
  24. $tot = 0; while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { .... .... $tot += $row['duration']; // accumulate duration } echo "Total duration: $tot";
  25. Build the first array with the section code as the key, as that is the common element, then add to it instead of building the second array
×
×
  • 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.