View Full Version : First attempt at php with MySQL

09-12-2006, 03:50 AM

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
$username = "*****";
$password = "******";
$database = "itunes";

@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT * FROM tracks ORDER by artist, album, tracknumber";


echo $result;

I obviously have no idea what I'm doing! I have this database with my iTunes library all parsed and nice in it, but I just want it to display on the page and I don't know how.

09-12-2006, 04:54 AM
I have something similar on my site that will perhaps be of some help. I'm using PHP classes, but I think you can still sort of get an idea how to take your MySQL data and display it.

function tblArtistAlbums()

$Display .= <<<EOD
<div class="center">
<table class="dbs_table" rules="cols" frame="vsides" cellspacing="0">
<td class="toprow" colspan="4">$this->tabletitle</td>

<td class="row2left34">Artist Name</td>
<td class="row2mid58">Album Title</td>
<td class="row2mid8">Format</td>

$current_page = $_SERVER['PHP_SELF'];

// Write a No Records Found message for zero results
if ($this->pagerecordcount == 0 && $current_page == "/NewArrivals.php") {
$Display .= <<<EOD
<td colspan="3">
What?! No New arrivals? Yes, it's true. I've gone a whole month without adding a single
thing to my collection. Check back in a few days, and this page will probably have my
latest acquisition.
else {
// Retrieve the query results
while ($row = mysql_fetch_array($this->pageresult))
$Mod2 = $RecordsShown % 2;

if ($Mod2 == 1) {
$RowColor = "color1";
else {
$RowColor = "color2";

if ($row['artist_the'] == null) {
$ArtistName = $row['artist'];
else {
$ArtistName = $row['artist_the'] . " " . $row['artist'];

$ArtistName = str_replace("&","&amp;",$ArtistName);
$ArtistName = str_replace('"',"&quot;",$ArtistName);
$AlbumTitle = $row['albumtitle'];
$AlbumTitle = str_replace("&","&amp;",$AlbumTitle);
$AlbumTitle = str_replace('"',"&quot;",$AlbumTitle);

$Display .= <<<EOD

<td class="$RowColor"><a href="/MusicDBSearch.php?BrowseArtistID={$row['artistid']}"
title="Search By Artist - $ArtistName">$ArtistName</a></td>
<td class="$RowColor"><a href="/AlbumID{$row['albumid']}.php"
title="Track List: $Artist - $AlbumTitle">
<td class="$RowColor">{$row['format']}</td>


$Display .= <<<EOD

$this->display = $Display;

09-12-2006, 02:25 PM
Also make sure you properly normalize your tables. Have a look at my linked article on categories/subcategories below.