...

View Full Version : First attempt at php with MySQL



Ranger56
09-12-2006, 02:50 AM
http://spiderseatbabies.com/testdb/index.php


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php
$username = "*****";
$password = "******";
$database = "itunes";

mysql_connect(mysql.spiderseatbabies.com,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT * FROM tracks ORDER by artist, album, tracknumber";
$result=mysql_query($query);

mysql_close();

echo $result;
?>
</body>
</html>


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.

vinyl-junkie
09-12-2006, 03: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">
<tr>
<td class="toprow" colspan="4">$this->tabletitle</td>
</tr>

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

$current_page = $_SERVER['PHP_SELF'];

// Write a No Records Found message for zero results
if ($this->pagerecordcount == 0 && $current_page == "/NewArrivals.php") {
$Display .= <<<EOD
<tr>
<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.
</td>
</tr>
EOD;
}
else {
// Retrieve the query results
while ($row = mysql_fetch_array($this->pageresult))
{
++$RecordsShown;
$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

<tr>
<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">
$AlbumTitle</a></td>
<td class="$RowColor">{$row['format']}</td>
</tr>

EOD;
}
}

$Display .= <<<EOD
</table>
</div>
EOD;

$this->display = $Display;
$this->get_tblOutput();
}

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum