Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder Ranger56's Avatar
    Join Date
    Mar 2005
    Location
    Kent, WA.
    Posts
    783
    Thanks
    0
    Thanked 0 Times in 0 Posts

    First attempt at php with MySQL

    http://spiderseatbabies.com/testdb/index.php

    PHP Code:
    <!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.

  • #2
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,092
    Thanks
    2
    Thanked 23 Times in 23 Posts
    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.

    Code:
    	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();
    	}
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #3
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Also make sure you properly normalize your tables. Have a look at my linked article on categories/subcategories below.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •