Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Programming

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-09-2002, 09:46 AM
Senior Webmaster
 
Join Date: Oct 2001
Location: Kuala Lumpur, Malaysia
Posts: 294
Rep Power: 93
kidino is on a distinguished road
Send a message via Yahoo to kidino
Tips PHP-MySQL

OK, ni saja nak share satu PHP-MySQL punya tips.

Andaikanlah ada satu table yang mana kita ada column DATE_FROM dan DATE_TO untuk validate status seseorang nak tengok dah expire belum. Contoh sistem yang mungkin menggunakan menda macam ni adalah macam sistem keahlian ke, dan sebagainya. Table mungkin macam ni ...
Code:
+----------------+------------+------------+
| NAME           | DATE_FROM  | DATE_TO    |
+----------------+------------+------------+
| Ali            | 2002-01-01 | 2002-12-31 |
| Abu            | 2002-01-01 | 2002-06-30 |
+----------------+------------+------------+
Cara tercepat dan teringkas yang aku tau untuk evaluate sama ada keahlian masih hidup ataupun dah expire adalah dengan kod macam kat bawah ni
PHP Code:
$status[0] = 'Expired';
$status[1] = 'Active';

$sql    "SELECT NAME, ((NOW() >= DATE_FROM) AND (NOW() <= DATE_TO)) STATUS\n";
$sql .= "FROM ahli";
$result mysql_query($sql);

echo 
"<table>\n";
echo 
"<tr><td>NAME</td><td>STATUS</td></tr>\n";
while(
$data mysql_fetch_array($result))
{
    
$member_status $status[$data['STATUS']];
    echo 
"<tr><td>$data[NAME]</td><td>$member_status</td></tr>\n";
}
echo 
"</table>\n"
Tak paham? Dia senang aje, kat SQL statement yang kita buat tu, kita nak dua column jea, NAME dan STATUS. STATUS akan return sama ada 0 atau 1, merujuk kepada statement SQL kita, ((NOW() >= DATE_FROM) AND (NOW() <= DATE_TO)) STATUS. Dengan macam ni, kita dah set yang $status[0] = "Expired"; dan $status[1] = "Active";. Dengan ini, $status[$data['STATUS']]; akan return sama ada "Active" atau "Expired".

So OK lah ... selamat mencuba.
__________________
--------------------------------------------
Khairil Iszuddin Ismail

Last edited by kidino; 02-09-2002 at 09:59 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 17-09-2002, 02:02 PM
bazet's Avatar
Novice Webmaster
 
Join Date: Aug 2001
Location: Ampang KL
Posts: 93
Rep Power: 90
bazet is on a distinguished road
Send a message via ICQ to bazet Send a message via AIM to bazet Send a message via Yahoo to bazet
Tips yg bagus. macam aku yg lemah SQL nih buat satu function khas untuk kira perbezaan hari.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 22-09-2002, 03:10 AM
hymns's Avatar
Senior Webmaster
 
Join Date: Nov 2001
Location: Johor
Posts: 769
Rep Power: 101
hymns is on a distinguished road
Send a message via ICQ to hymns Send a message via Yahoo to hymns
aha... cute gak coding tu... tapi still tak paham... sape leh ajar aku utk... QUERY, ADD, REM, SEARCH SQL yg tersimple sekali utk aku paham... boleh kan???
__________________
I hate when:

vBulletin Message:
Sorry! The administrator has specified that users can only post one message every 60 seconds
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
new tips portal -> www.tips.com.my beyondsunn Websites Review and Suggestion 5 27-07-2005 04:20 PM
tips-travel.com alang Websites Review and Suggestion 3 11-07-2004 05:27 PM
Tips nurulmajdi Website Programming 5 17-05-2004 06:19 PM
Tips MySQL-PHP 2 kidino Website Programming 1 22-09-2002 03:24 AM
Tips : Embedded PHP bazet Website Programming 2 22-09-2002 03:01 AM


All times are GMT +8. The time now is 03:22 AM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.


WebmasterMalaysia.com is Proudly Hosted by Exabytes Semi Dedicated Server.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61