Jump to content

everisk

Members
  • Posts

    95
  • Joined

  • Last visited

    Never

Everything posted by everisk

  1. With the code, I now got array like Array ( [http://www.abcde.com] => Array ( [stimes] => 823 [pp] => 26.97 ) [http://www.12345.com] => Array ( [stimes] => 561 [pp] => 18.38 ) [http://www.xyz123.com] => Array ( [stimes] => 3 [pp] => 0.03 ) ) What do I need to change to get array like. I need to traverse array but number. Array ( 1 => Array ( 'url' => 'http://www.abcde.com', 'stimes' => 823, 'pp' => 26.97 ), 2 => Array ( 'url' => 'http://www.12345.com', 'stimes' => 561, 'pp' => 18.38 ), 3 => Array ( 'url' => 'http://www.xyz123.com', 'stimes' => 3, 'pp' => 0.03 ), ); Thanks a lot!
  2. I have an array that looks like Array ( [1] => Array ( [url] => http://www.abcde.com [stimes] => 823 [pp] => 26.97 ) [2] => Array ( [url] => http://www.12345.com [stimes] => 561 [pp] => 18.38 ) [3] => Array ( [url] => http://www.xyz123.com [stimes] => 1 [pp] => 0.03 ) [4] => Array ( [url] => http://www.xyz123.com [stimes] => 1 [pp] => 0.03 ) [5] => Array ( [url] => http://www.xyz123.com [stimes] => 1 [pp] => 0.03 ) ) How do I combine those with the same URL together? The [stimes] will also need to be accumulated. Many thanks in advance.
  3. I think you could try using SQL statement to fetch the row in descending order (you should already store something like id). That should fetch the latest row. Something like select * from your_table order by field_name DESC
  4. I'm trying to write a simple PHP code that read emails from an account. The problem is now with the non-English subject. I work with Thai language which uses 'windows-874' character encoding. When I fetch the email headers, the subject line is gibberish. Example Email from XXXXXXXXXXXX , subject =?windows-874?B?zejSueHF6cc6IEhTQkMgQ29tbWVudHM=?=, date Wed, 12 Dec 2007 10:53:22 +0700 Email from XXXXXXXXX , subject Another Dec E-newsletter, date Wed, 12 Dec 2007 10:58:09 +0700 How do I get the subject line to show correctly? Any help will be greatly appreciated. Below is my code. <?php $login="email@mydomain.com"; //pop3 login $password="somepassword"; //pop3 password $conn = @imap_open("{mail.mydomain.com:110/pop3/notls}INBOX", $login, $password) or die(imap_errors()); $headers = @imap_headers($conn) or die("Couldn't get emails"); //$numEmails = 50; $numEmails = sizeof($headers); for($i = 20; $i < $numEmails+1; $i++) { $mailHeader = @imap_headerinfo($conn, $i); //$head = imap_fetchheader($conn, $i); //print $head; $from = $mailHeader->fromaddress; $subject = strip_tags($mailHeader->subject); $date = $mailHeader->date; echo "<strong>$i. Email from $from, subject $subject, date $date</strong><br><br>"; } ?>
  5. Hello, I have a recursive function which is running as expected. However, I dont know how could I access the variable in the recursive function outside of the function scope. The variables are in array. Below is my code. Thanks! //get forwarder id $sql = "select * from forward_network where email='$email'"; $tab = mysql_query($sql) or die("Cannot select email"); $row = mysql_fetch_array($tab); $forwarder_id = $row['id']; //find children of forwarder $children = get_children($forwarder_id); print_r($children); function get_children($id) { $sql = "select * from forward_network where parent_id=$id"; $tab = mysql_query($sql) or die("Cannot get children"); if($tab) { //if there is value in $tab or children are found, then store it while($row = mysql_fetch_array($tab)) { $child['id'] = $row['id']; $child['email'] = $row['email']; $child['parent_id'] = $row['parent_id']; $child['level'] = $row['level']; //get children of children ,, recursive print "<pre>"; print_r($child); print "</pre>"; print "<br>"; get_children($row['id']); } } return $child; }
  6. Hi, I have a code where I need to use an IFRAME to load something from external page then display that the process has succeeded, then a message shows that user can close the browser. Now I'm using sleep() to delay the page (and hope that the IFRAME will finish loading within that time). But I dont think this is working as different people have different connection speed. Below is the short version of my code. Many thanks in advance! echo "<div align=center><iframe src='http://xxx.com' frameborder=\"0\" width=\"1\" height=\"1\"></iframe></div>"; echo "<div align=center><iframe src='http://www.xxx.com' frameborder=\"0\" width=\"1\" height=\"1\"></iframe></div>"; sleep(10); echo "<div align=\"center\">Success!</div>";
  7. Thanks EKINdesigns. It worked, except that i have to change chr(13) to chr(10). But thanks a lot!
  8. Hello all, I need some help printing some code on the page. Originally I read HTML code from a url and I need to replace 'Beginning of Line' and 'End of Line' with line number. However, I do not know how this can be done. Any help would be really appreciated. $enews = file_get_contents("http://my.sony.co.th/newsletter/issue/issue-MySony061aug22/index_en.html"); $enews = htmlspecialchars($enews); print "<pre>$enews</pre>"
  9. Sorry .. here it is. Thanks a lot! <?php $url = "http://wisetarget.net/promotions/sony/issue-MySony060July17/mysony/index_th.php"; $input = @file_get_contents($url) or die('Could not access file: $url'); ////first I try to extract the link from href tag by regular expressions $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>"; if(preg_match_all("/$regexp/siU", $input, $matches)) { print "<pre>"; print_r ($matches); print "</pre>"; } $replace = "<div class=\"overlayON\">"; $replace .= graph($matches['2']['0']); // this number has to loop to [2][1] , [2][2], and so on for all $matches value $replace .= "</div><a"; $html = str_replace("<a", $replace, $input); print $html; function graph($var) { $var .= "CORRECT"; return $var; } ?>
  10. Hi, I have to add <div class="overlayON"><?php graph($i); ?></div> in front of all <a href="..">. The value of $i is dynamic. I thought that str_replace would do the job but seem like I cannot use dynamic variable to replace the string. To make it clearer .. <div class="overlayON"><?php graph(1);?></div><a href=....> <div class="overlayON"><?php graph(2);?></div><a href=....> <div class="overlayON"><?php graph(3);?></div><a href=....> Thanks!
  11. Hi, I need to find if 2 array contains same value, if so then add their count values. For example, I have the below array. I have to add 'count' of array 0 and array 1 because the 'url' is the same (open). I have to also add 'count' of array 2 and array 3 because the 'url' is the same. Thank you in advance! Array ( [0] => Array ( [lid] => 1567 [url] => open [count] => 736 ) [1] => Array ( [lid] => 1573 [url] => open [count] => 265 ) [2] => Array ( [lid] => 1568 [url] => http://my.sony.co.th/newsletter/issue/SonyCenter_promotion/index.html [count] => 186 ) [3] => Array ( [lid] => 1575 [url] => http://my.sony.co.th/newsletter/issue/SonyCenter_promotion/index.html [count] => 73 ) ) My code that populate the array $i=0; while($row = mysql_fetch_array($table)) { //get URL name $sql2 = "select * from all_links where id=$row[lid]"; $tab2 = mysql_query($sql2) or die("Cannot get URL"); $url = mysql_fetch_array($tab2); $t_link[$i]['lid'] = $row['lid']; $t_link[$i]['url'] = $url['link']; $t_link[$i]['count'] = $row['clid']; $i++; }
  12. I have array that looks like below. I want to add the count of the array if the URL is the same. For example, array[4] is the same as array[6] then array[count][4] + array[count][6]. Any help would be greatly appreciated. I am not so good with array . Thanks! Array ( [url] => Array ( [0] => open [1] => open [2] => open [3] => open [4] => http://my.sony.co.th/newsletter/issue/issue-MySony058June6/index.html [5] => http://www.sony.co.th/DSLR/a100/ [6] => http://my.sony.co.th/newsletter/issue/issue-MySony058June6/index.html [7] => http://www.sony.co.th/DSLR/a100/ ) [count] => Array ( [0] => 3315 [1] => 2247 [2] => 516 [3] => 293 [4] => 274 [5] => 204 [6] => 193 [7] => 178 ) ) This is my code $t_link = array("url"=>array(""), "count"=>array("")); $i=0; $sql = "SELECT count(lid) as clid, lid ,nl,times FROM linksd a where n=146||n=147||n=137||n=138 group by lid order by clid DESC"; $table = mysql_query($sql) or die("Cannot get count"); while($row = mysql_fetch_array($table)) { //get URL name $sql2 = "select * from links where id=$row[lid]"; $tab2 = mysql_query($sql2) or die("Cannot get URL"); $url = mysql_fetch_array($tab2); $t_link["url"][$i] = $url['link']; $t_link["count"][$i] = $row['clid']; $i++; } echo "<pre>"; print_r($t_link); die;
  13. oh .. sorry .. one more thing .. it seems like when I first initialize the array the value for both [0][0] and [1][0] are not stored. Array ( [chart_data] => Array ( [0] => Array ( [0] => null /////missing [1] => 2007-05-10 [2] => 2007-05-11 [3] => 2007-05-12 [4] => 2007-05-13 [5] => 2007-05-14 [6] => 2007-05-15 [7] => 2007-05-16 [8] => 2007-05-17 [9] => 2007-05-18 [10] => 2007-05-19 [11] => 2007-05-20 [12] => 2007-05-21 [13] => 2007-05-22 [14] => 2007-05-23 [15] => 2007-05-24 [16] => 2007-05-25 [17] => 2007-05-26 [18] => 2007-05-28 ) [1] => Array ( [0] => open /////missing [1] => 250 [2] => 112 [3] => 34 [4] => 21 [5] => 32 [6] => 27 [7] => 14 [8] => 8 [9] => 4 [10] => 2 [11] => 2 [12] => 4 [13] => 4 [14] => 3 [15] => 2 [16] => 1 [17] => 1 [18] => 1 ) ) )
  14. MadTechie, you are a genius! Your modified code your correctly, it looks like the extra data were from SendChartData(). Thanks a million!
  15. Thanks a lot MadTechie, your code seems to working very well. I'm not very good with array so I need help again. Instead of printing $tmp I tried printing $chart but then I got unwanted strings in red. How do I get rid of it? Array ( [chart_data] => Array ( [0] => Array ( [1] => 2007-05-10 [2] => 2007-05-11 [3] => 2007-05-12 [4] => 2007-05-13 [5] => 2007-05-14 [6] => 2007-05-15 [7] => 2007-05-16 [8] => 2007-05-17 [9] => 2007-05-18 [10] => 2007-05-19 [11] => 2007-05-20 [12] => 2007-05-21 [13] => 2007-05-22 [14] => 2007-05-23 [15] => 2007-05-24 [16] => 2007-05-25 [17] => 2007-05-26 [18] => 2007-05-28 ) [1] => Array ( [1] => 250 [2] => 112 [3] => 34 [4] => 21 [5] => 32 [6] => 27 [7] => 14 [8] => 8 [9] => 4 [10] => 2 [11] => 2 [12] => 4 [13] => 4 [14] => 3 [15] => 2 [16] => 1 [17] => 1 [18] => 1 ) ) ) 2007-05-10 2007-05-11 2007-05-12 2007-05-13 2007-05-14 2007-05-15 2007-05-16 2007-05-17 2007-05-18 2007-05-19 2007-05-20 2007-05-21 2007-05-22 2007-05-23 2007-05-24 2007-05-25 2007-05-26 2007-05-28 250 112 34 21 32 27 14 8 4 2 2 4 4 3 2 1 1 1 $chart['chart_data'][0][0]=""; $chart['chart_data'][1][0]="open"; //<--changed $tmp = array("open" => array(), "sdate" => array()); $sql = "SELECT count(*) as open, sdate FROM table a where nl=111 and lid=863 group by sdate order by sdate ASC"; $table = mysql_query($sql) or die("cannot select"); $i=1; while($row=mysql_fetch_array($table)) { $tmp["sdate"][$i] = $row['sdate']; $tmp["open"][$i] = $row['open']; $i++; } $chart['chart_data'][0] = $tmp['sdate']; $chart['chart_data'][1] = $tmp['open']; print_r($chart); SendChartData ( $chart );
  16. Thanks alot MadTechie but that doesn't seem to work. When execute SendChartData($chart) .. it seems to get only value I initialized in the first 2 lines and not what what I populate within the while block. $chart['chart_data'][0][0]=""; $chart['chart_data'][1][0]="Opens"; Let me paste the full code in the correct manner again $chart['chart_data'][0][0]=""; $chart['chart_data'][1][0]="Opens"; $sql = "SELECT count(*) as open, sdate FROM table a where nl=111 and lid=863 group by sdate order by sdate ASC"; $table = mysql_query($sql) or die("cannot select"); while($row=mysql_fetch_array($table)) { static $i=1; $chart['chart_data'][0]['$i'] = $row['sdate']; $chart['chart_data'][1]['$i'] = $row['open']; $i++; } SendChartData ( $chart );
  17. Hi I try to populate an array variable by pulling data from data using while. However, whatever I insert only stays in the while loop. I need the values to be available outside of the while loop. Below is the code... $chart['chart_data'][0][0]=""; $chart['chart_data'][1][0]="Opens"; $sql = "SELECT count(*) as open, sdate FROM table a where nl=111 and lid=863 group by sdate order by sdate ASC"; $table = mysql_query($sql) or die("cannot select"); while($row=mysql_fetch_array($table)) { static $i=1; $chart['chart_data'][0]['$i'] = $row['sdate']; $chart['chart_data'][1]['$i'] = $row['open']; $i++; } SendChartData ( $chart ); Thanks a lot!
×
×
  • 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.