Jump to content
Sign in to follow this  
cade

Php Troubleshooting

Recommended Posts

aku ada satu script nak display date and time, aku nak papar kan dia sebiji macam putera.com buat

contoh:

kalo user post a msg pada hari ini, date and time will display "today"...and also kalo user tu baru 2 jam lepas post entry, php akan display "2 hours ago"...

mcm mana nak bina dlm php?

if (date()==$row['masa'])
echo "today";

setakat ni jer aku dpt pikir kan dulu...sbb utk yg lain tu aku dah hadap berpuluh puluh kali kegagalan.... sad.gifsad.gif

tq

Edited by cade

Share this post


Link to post
Share on other sites

cari beza masa sekarang dgn masa dari dlm DB..

$dateFromDB = strtotime(row['masa']);
$dateToday = mktime();

$diff = $dateToday - $dateFromDB;

strotime akan tukarkan date dlm bentuk human-readable (eg. "2005-07-18") kepada UNIX timestamp.

mktime akan ambil masa sekarang dlm bentuk UNIX timestamp

UNIX timestamp ni sebenarnya perwakilan masa dlm bentuk jumlah saat, jadi bila kita tolak dua masa diatas kita dapat saatnya.. maka $diff akan pegang beza dua masa tersebut dlm SAAT..

kita dah dapat SAAT tu.. Now lets us see your logic on how to convert the SAAT to MINIT, JAM and so on..

rujuk:

http://php.net/manual/en/ref.datetime.php

http://forums.ittutor.net/index.php?showtopic=27392

http://www.michaelhorowitz.com/php/datediff.php

http://www.google.com/search?q=php+date+difference

Share this post


Link to post
Share on other sites

Note: Please keep in mind that these functions are dependent on the locale settings of your server. Make sure to take daylight saving time (use e.g. $date = strtotime('+7 days', $date) and not $date += 7*24*60*60) and leap years into consideration when working with these functions.

apa maksud kat text yg aku highlight kan tuh??

p/s: aku punyer progress still slow due to takder pc kat umah....tak sempat pun nak baca link yg ader...

Share this post


Link to post
Share on other sites

my progress.....

function dateDiff($dateTimeBegin,$dateTimeEnd) {

         $dateTimeBegin=strtotime($dateTimeBegin);
         if($dateTimeBegin === -1) { /*apa maksud kat sini???*/
           return("invalid begin time....");
         }

         $dateTimeEnd=strtotime($dateTimeEnd);
         if($dateTimeEnd === -1) 
     {
           return("invalid end time");
         }

         $dif=$dateTimeEnd - $dateTimeBegin;

          switch($dif) {

          case ($dif >= 1 ) && ($dif < 3600):  	
          return(", " . floor($dif/60) . " minutes ago"); //1min = 60s

           case ($dif >= 3600) && ($dif < 86400): // > 1hr and < 1day
           return(", " . floor($dif/3600) ." hours ago" ); // 1hrs = 3600s

           case ($dif > 86400) && ($dif <= 172800):
           return(", yesterday");

           default:
               return(date("l dS of F Y h:i:s A",$dateTimeBegin));
         }
} 

aku copy dari link yg ader kat ats nih...tapi slightly modified...

Tapi aku still ader beberapa kemuskilan utk code kat atas nih....dkt bahagian if condition. Apabila dia check dateTime === -1, apa maksud dia sebenarnya dia nih...??

Kalo dlm PHP, kiter guner text area punyer kontrol sbg input dlm db kat mySQL, mcmana nak display exactly mcm user entered...contohnya,

kite enter some text then kita press enter key, utk write new line & enter text kat situ....

Share this post


Link to post
Share on other sites

Example: $a === $b

Name: Identical

Result: TRUE if $a is equal to $b, and they are of the same type. (introduced in PHP 4)

Oleh sebab data dlm PHP ialah "loosely typed", maka ada operator ni utk banding nilai 2 variable sama termasuk jenis datanya..

Gunakan nl2br() utk tukar linefeeds (\n) kpd tag <br> ..

http://my2.php.net/nl2br

Share this post


Link to post
Share on other sites

apa maksud -1 disitu?

Adakah mail() function dlm php depending on server apa yg kiter guna?

thanks

Edited by cade

Share this post


Link to post
Share on other sites

Returns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0, this function would return -1 on failure.
Tengok strtotime, kalau tak berjaya dia return -1 .. beware tho', there'll be some glitch if ur using this code in PHP 5.1.0 and above..

Tengok, aku search PHP Manual.. kalau ko sendiri cari kat PHP Manual tentu boleh dpt jawapan dgn lebih cepat..

Share this post


Link to post
Share on other sites

mail() function kalau tak silap depends on the settings kat php.ini file..

cuba check, aku tak pasti, tak pernah amik tahu..

Share this post


Link to post
Share on other sites

aku ader try buat guest book guner php, masalahnyer ialah camna nak halang data dari masuk ke dlm database apabila user baru saja click kat submit button utk post entry and then dia pergi click plak dkt Refresh button kat browser....Aku guna form method = get

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...