Menampilkan Data Beberapa Tabel adalah lanjutan dari tutorial Menyimpan Data & Menampilkan Beberapa Tabel. Sebelum membaca tutorial ini silahkan baca terlebih dulu tutorial sebelumnya. Ditutorial sebelumnya telah dijelaskan cara menyimpan data ke beberapa tabel sekaligus. Seperti dijelaskan sebelumnya, ada tiga tipe relasi antar tabel: relasi satu ke satu, satu ke banyak, dan banyak ke banyak. Di sini akan dijelaskan cara menampilkan data masing masing tipe relasi tabel.

Menampilkan Data Dari Tabel Berelasi Satu-ke-satu

  1. <?php  
  2. $conn = mysql_connect("localhost","root","blah");  
  3. mysql_select_db("test",$conn);  
  4. $sql = "select * from product p inner join buku b on p.id_produk=b.id_produk";  
  5. $result = mysql_query($sql);  
  6. ?>  
  7. <table cellpadding="5" cellspacing="0" border="1">  
  8.     <tr>  
  9.         <th>Nama</th>  
  10.         <th>Harga</th>  
  11.         <th>Penulis</th>  
  12.         <th>Penerbit</th>  
  13.         <th>ISBN</th>  
  14.         <th>Tanggal Terbit</th>  
  15.     </tr>  
  16.     <?php while($buku = mysql_fetch_array($result)){?>  
  17.     <tr>  
  18.         <td><?php echo $buku['nama'];?></td>  
  19.         <td><?php echo $buku['harga'];?></td>  
  20.         <td><?php echo $buku['penulis'];?></td>  
  21.         <td><?php echo $buku['penerbit'];?></td>  
  22.         <td><?php echo $buku['isbn'];?></td>  
  23.         <td><?php echo $buku['tgl_terbit'];?></td>  
  24.     </tr>  
  25.     <?php }?>  
  26. </table> 


Menampilkan Data dari Tabel Berelasi Satu-ke-banyak


Untuk menampilkan data dari tabel berelasi satu ke banyak juga bisa menggunakan sql join, namun lebih bagus jika tidak. Caranya adalah membaca tabel induk dan kemudian menampilkan tabel anak berdasarkan isi tabel induk,seperti:
  1. <?php  
  2. $conn = mysql_connect("localhost","root","blah");  
  3. mysql_select_db("test",$conn);  
  4. $sql = "select * from album";  
  5. $result = mysql_query($sql);  
  6. ?>  
  7. <table cellpadding="5" cellspacing="0" border="1">  
  8.     <tr>  
  9.         <th>Judul</th>  
  10.         <th>Artis</th>  
  11.     </tr>  
  12.     <?php while($album = mysql_fetch_array($result)){?>  
  13.     <tr>  
  14.         <td><?php echo $album['judul'];?></td>  
  15.         <td><?php echo $album['artis'];?></td>  
  16.     </tr>  
  17.     <tr>  
  18.         <td colspan="2">  
  19.         <strong>Lagu: </strong>  
  20.         <table cellspacing="0" cellpadding="3">  
  21.             <tr>  
  22.                 <td style="border-bottom:1px solid #000;">No Track</td>  
  23.                 <td style="border-bottom:1px solid #000">Judul</td>  
  24.                 <td style="border-bottom:1px solid #000">Durasi</td>  
  25.             </tr>  
  26.             <?php  
  27.             $rowset = mysql_query("select * from lagu where id_album='".$album['id']."'");  
  28.             while($lagu = mysql_fetch_array($rowset)){  
  29.             ?>  
  30.             <tr>  
  31.                 <td style="border-bottom:1px solid #000; border-right:1px solid #000"><?php echo $lagu['no_track'];?></td>  
  32.                 <td style="border-bottom:1px solid #000; border-right:1px solid #000"><?php echo $lagu['judul'];?></td>  
  33.                 <td style="border-bottom:1px solid #000"><?php echo $lagu['durasi'];?></td>  
  34.             </tr>  
  35.             <?php }?>  
  36.         </table>  
  37.         </td>  
  38.     </tr>  
  39.     <?php }?>  
  40. </table>

bisa dilihat kode di atas hampir sama dengan kode untuk menampilkan data dari satu tabel. Perbedaanya adalah pada baris 17-38. Baris 17-38 adalah untuk menampilkan lagu berdasarkan id_album album yang sedang ditampilkan.

Menampilkan Data dari Tabel Berelasi Banyak-ke-banyak


Untuk menampilkan data dari tabel yang berelasi banyak ke banyak hampir sama dengan cara menampilkan data dari tabel berelasi satu ke banyak.Bedanya adalah pada sql yang digunakan, yaitu sql join. Sekarang buka kembali file list-mahasiswa.php yang telah dibuat di tutorial sebelumnya dan ubah menjadi:

  1. <?php  
  2. $conn = mysql_connect("localhost","root","blah");  
  3. mysql_select_db("test",$conn);  
  4. $sql = "select * from mahasiswa";  
  5. $result = mysql_query($sql);  
  6. ?>  
  7. <table cellspacing="0" cellpadding="5" border="1">  
  8.     <tr>  
  9.         <td>NIM</td>  
  10.         <td>Nama</td>  
  11.         <td>Jurusan</td>  
  12.         <td>Aksi</td>  
  13.     </tr>  
  14.     <?php while($mhs = mysql_fetch_array($result)){?>  
  15.     <tr>  
  16.         <td><?php echo $mhs['nim'];?></td>  
  17.         <td><?php echo $mhs['nama'];?></td>  
  18.         <td><?php echo $mhs['jurusan'];?></td>  
  19.         <td><a href="mahasiswa_mk.php?nim=<?php echo $mhs['nim'];?>">Tambah Mata Kuliah</a></td>  
  20.     </tr>  
  21.     <tr>  
  22.         <td colspan="4">  
  23.             <strong>Mata Kuliah:</strong>  
  24.             <table cellspacing="0" cellpadding="5" width="100%">  
  25.                 <tr>  
  26.                     <td style="border-bottom:1px solid #000;">Kode MK</td>  
  27.                     <td style="border-bottom:1px solid #000;">Nama MK</td>  
  28.                 </tr>  
  29.                 <?php   
  30.                 $rowset = mysql_query("select * from mahasiswa_mk m inner join   
  31.                 mata_kuliah m1 on m.id_mk=m1.id where nim='".$mhs['nim']."'");  
  32.                 while($mk = mysql_fetch_array($rowset)){  
  33.                 ?>  
  34.                 <tr>  
  35.                     <td style="border-bottom:1px solid #000;border-right:1px solid #000"><?php echo $mk['kode'];?></td>  
  36.                     <td style="border-bottom:1px solid #000;"><?php echo $mk['nama'];?></td>  
  37.                 </tr>  
  38.                 <?php }?>  
  39.             </table>  
  40.         </td>  
  41.     </tr>  
  42.     <?php }?>  
  43. </table>
Sumber: http://www.myphptutorials.com
PT. YEPEKA USAHA MANDIRI

MEMBUTUHKAN :

WELDER SMAW 2 & PIPE FITTER KELAS 1 DENGAN KUALIFIKASI SEBAGAI BERIKUT :
1.BERSERTIFIKAT
2.BERPENGALAMAN DALAM PENGELASAN & MODIFIKASI PIPING

JIKA ANDA MEMENUHI KRITERIA DI ATAS, SEGERA KIRIM APLIKASI LAMARAN KE :

PT. YEPEKA USAHA MANDIRI (PT. YUM)
JL. ENGGANG BLOK Z NO.1 BTN PKT BONTANG

LAMARAN PALING LAMBAT TGL 8 DESEMBER 2011

I mentioned in my opening post on the main page that the market had reached important resistance. Here is the chart:




Hopefully you can see that purple trend line drawn in that I had been watching since early October as support for the SPX. Well on 11/17 you can see that the SPX broke decisively below that trendline, and the market had a correction.


Now, the market has rallied all the way back to the underside of that trendline. That seems like a logical place for the market to take a breather, and I have trimmed more of our trading positions today.



The market is higher this morning on the heels of further action in Europe to deal with the debt crisis, and an in-line employment report.

Europe was already higher this morning after news out that the ECB would loan the IMF 100-200 billion euros to fight the debt crisis. This is a backend way to get the IMF involved, by the ECB giving them the initial funds. But 100-200 billion euros is a drop in the bucket, and there is going to have to be much more involvement. I suspect EU officials will try to bring in more funds from surplus countries like China, Brazil, etc.

Here in the U.S., the nonfarm payrolls report showed that the economy added 120,000 jobs, in-line with estimates. Private payroll additions were a little higher at 140,000 (also in-line). But the big surprise was the unemployment rate, which dropped unexpectedly to 8.6%. It is now back to levels we haven't seen since March 2009. Some will argue that it's due to more people dropping out of the labor force, but that still leaves fewer people looking for jobs.

In corporate news, RIMM lowered guidance and said it will take a charge related to its Playbook inventories. That means it couldn't' sell as much as it thought, as iPad remains the #1 tablet. It's stock is down -9% so far. As for WDC, it's up 10% after raising guidance and saying it will resume production that had been halted due to flooding in Thailand.

The euro is lower today, but that isn't really hurting commodities. Copper prices are higher, and oil and gold are steady. Oil prices are still hugging the $100 level, and gold is up slightly near $1753.

The 10-year yield is easing back a bit to 2.07%; and the VIX is down -3.6% right now to 26.40. It had been down to 25.30 earlier before bouncing higher. As I have said, a move below 25 that sticks would likely embolden the bulls to be even more "risk on".

Trading comment: The market has now been up big for 4 of the last 5 sessions, even though we still have a long way to go today. But I will post a chart later that shows that the market has reached some important resistance levels and is likely due for a little pullback. I am trimming a few positions just slightly, and will wait to put more cash to work on said pullback vs. chasing things here. I hope I'm right. We are also getting into the time of year when performance anxiety peaks and where more good news out of Europe over the weekend could lead to additional short-covering.

The markets are roughly flat after yesterday's outsized rally. Yesterday was one of the biggest point gains on record for the Dow. The only problem is that if you look at the list of the biggest point day, almost of all of them were bear market bounces that didn't last. Let's hope this time is different.

Same-store sales reports have been coming out for retailers and have been a mixed bag for the most part. On the upside are stocks like ROST, COST, JWN, and GES. But there have been some big disappointments such as LULU and KSS.

In economic news, the ISM Manufacturing Index for November came in at 52.7, which is a nice bounce from 50.8 last month. China's PMI last night came in below expectations and dropped below the 50 level, which marks the delineation between expansion and contraction.

Europe's markets are mixed this morning after bond auctions were held in Spain and France. The euro is slightly higher, while commodities are mixed. Oil and gold prices are both roughly flat so far at $100.50 and $1750, respectively.

The 10-year yield is higher again to 2.10%; and the VIX is down -1.55% so far near 27.37.

Trading comment: Yesterday's gain came as a big surprise to most investors. Especially since the night before S&P had downgraded the banks and the futures were pointing to a lower open. The coordinated action by the central banks led to a sharp short-covering rally. The question now is will it be more similar to 1998 when the Fed action sparked a lasting rally or more like 2008 when there was more downside to come? I would not rule out the possibility of performance anxiety kicking in between now and year-end and pressuring portfolio managers to do more buying in hopes of adding performance. I know that's how I feel on a day like yesterday.

ACCESORIES
tilda : terminal emulator with first person shooter console likeness
gdesklets : Architecture for desktop applets
screenlets : Widget-like mini-applications for GNOME
xvkbd : Software virtual keyboard for X11
kvkbd : Virtual keyboard for KDE
cairo-clock : An analog clock drawn with vector-graphics
quicksynergy : GUI for easy configuration of Synergy
kalarm : KDE alarm message, command and email scheduler
cmatrix : Console Matrix simulates the display from “The Matrix”
drapes : a desktop wallpaper management application for the GNOME desktop
workrave : Repetitive Strain Injury (RSI) prevention tool
xournal : GTK+ Application for note taking
gnome-commander : nice and fast file manager for the GNOME desktop
gprename : Complete batch renamer for Linux
pyrenamer : mass file renamer written in PyGTK
GAMES
gweled : A “Diamond Mine” puzzle game
frozen-bubble : Pop out the bubbles!
wormux : funny fight game on 2D maps
gnugo : play the game of Go
pokerth : Texas hold’em game
GRAPHICS
inkscape : vector-based drawing program
albumshaper : Photo album creator and photo manipulator
scribus : Open Source Desktop Page Layout
dia : Diagram editor
xaralx : Heavyweight vector graphics, illustration and DTP Program

INTERNET
webhttrack : Copy websites to your computer, httrack with a Web interface
tsclient : front-end for viewing of remote desktops in GNOME
gwget : GNOME front-end for wget
thunderbird : mail/news client with RSS and integrated spam filter support
ethereal : dummy upgrade package for ethereal -> wireshark
xchat : IRC client for X similar to AmIRC
xchat-gnome : a new frontend to the popular X-Chat IRC client
sunbird : Sunbird stand-alone Calendar
finch : text base d instant messenging
iptraf : Interactive Colorful IP LAN Monitor
empathy : High-level library and user-interface for Telepathy
gobby : collaborative text editor
gftp : X/GTK+ FTP client
OFFICE
pdfedit : Editor for manipulating PDF documents
gnochm : CHM file viewer for GNOME
stardict : International dictionary
gnucash : A personal finance tracking program
PROGRAMMING
bluefish : advanced Gtk+ HTML editor
kompare : a KDE GUI for viewing differences between files
rapidsvn : A GUI client for subversion
netbeans : Integrated Development Environment
nvu : Transition package for Nvu –> KompoZer fork (macromedia dreamweaver like)
geany : A fast and lightweight IDE
SOUND & VIDEO
mplayer : The Ultimate Movie Player For Linux – Medibuntu package
gnome-mplayer : GNOME MPlayer is a simple GUI for MPlayer
smplayer : A great front-end for MPlayer
elisa : media center solution – runtime executables
audacious : small and fast audio player which supports lots of formats
totem-xine : A simple media player for the Gnome desktop based on xine
gtk-recordmydesktop : Graphical frontend for recordmydesktop
wink : Tutorial and Presentation Creating Software
audacity : A fast, cross-platform audio editor
hydrogren : Simple drum machine/step sequencer
ffmpeg : multimedia player, server and encoder
istanbul : Desktop session recorder producing Ogg Theora video
amarok : versatile and easy to use audio player for KDE
devede : program to create video DVDs
k3b : A sophisticated KDE CD burning application
Banshee : audio player, can encode/decode various formats and synchronize music with Apple iPods
mpg123 : MPEG layer 1/2/3 audio player
music123 : A command-line shell for sound-file players
exaile : flexible audio player, similar to Amarok, but written in GTK+
acidrip : ripping and encoding DVD tool using mplayer and mencoder
xawtv : TV application for X11. Supports video4linux
pyvnc2swf : screen recording tool to SWF movie
soundkonverter : audio converter frontend for KDE
winff : graphical video and audio batch converter using ffmpeg
hipo : iPod Management Tool
furiusisomount : An ISO, IMG, BIN, MDF and NRG image management utility
autorun4linuxcd : Menu for Debian Live under Windows
SYSTEM TOOLS
htop : interactive processes viewer
nfs-common : NFS support files common to client and server
ntfs-config : tools for doing neat things in NTFS partitions from Linux
ntfsprogs : tools for doing neat things in NTFS partitions from Linux
yakuake : a Quake-style terminal emulator based on KDE Konsole technology
virtualbox : x86 virtualization solution
wine : Microsoft Windows Compatibility Layer (Binary Emulator and Library)
mondo : powerful disaster recovery suite
chntpw : NT SAM password recovery utility
powertop : linux tool to find out what is using power on a laptop
nautilus-open-terminal : nautilus plugin for opening terminals in arbitrary local paths
nautilus-wallpaper : Nautilus extension. Add a “set as wallpaper” entry in context menu
nautilus-image-converter : nautilus extension to mass resize or rotate images
nautilus-script-audio-convert : A nautilus audio converter script
nautilus-gksu : privilege granting extension for nautilus using gksu
nautilus-script-manager : A simple management tool for nautilus scripts
jigdo : GTK+ download manager (beta version)
jigdo-file : Download Debian CD images from any Debian mirror
preload : adaptive readahead daemon
tree : displays directory tree, in color
grsync : GTK+ frontend for rsync
SYSTEM PREFERENCES
emerald : Decorator for compiz-fusion
compiz : OpenGL window and compositing manager
ink : tool for checking the ink level of your local printer
screenlets : Widget like mini applications for GNOME
gtweakui : A collection of simple dialogs as a front end to GConf
avant-window-navigator : A MacOS X like panel for GNOME
compizconfig-settings-manager : Compiz configuration settings manager
system-config-samba : GUI for managing samba shares and users
gnome-splashscreen-manager : manage your GNOME splash screen images
simple-ccsm : Simple Compizconfig settings manager
startupmanager : Grub and Splash screen configuration
lshw-gtk : graphical information about hardware configuration
SYSTEM ADMINISTRATION
build-essential : informational list of build-essential packages
rar : Archiver for .rar files
unrar : Unarchiver for .rar files (non-free version)
unrar-free : Unarchiver for .rar files
nmap : The Network Mapper
hwinfo : Hardware identification system
wavemon : Wireless Device Monitoring Application
samba : a LanManager-like file and printer server for Unix
gparted : GNOME partition editor
aptoncd : Installation disc creator for packages downloaded via APT
ntfs-config : Enable/disable write support for any NTFS devices
ntfsprogs : tools for doing neat things in NTFS partitions from Linux
hardinfo : GUI information hardware
pessulus : a graphical lockdown editor has been included to ease the task of disabling desktop settings.
pyvnc2swf : screen recording tool to SWF movie
system-config-samba : graphical setting samba share
pysdm : Graphical Storage Device Manager
qgrubeditor : graphical editor for GRUB boot manager settings (only hardy)
kgrubeditor : graphical editor for GRUB boot manager settings
usb-creator : Ubuntu USB desktop image creator
bootchart : boot sequence auditing and chart generator
sabayon : system administration tool to manage GNOME desktop settings
xcompmgr : X composition manager
hot-babe : A GTK-based monitoring app
knemo : network interfaces monitor for KDE’s systray
filelight : show where your diskspace is being used
grandr : gtk interface to xrandr
dpkg-repack : puts an unpacked .deb file back together
dpkg-www : Web based Debian package browser
saidar–curses : based program which displays live system statistics
Diberdayakan oleh Blogger.