Click to See Complete Forum and Search --> : 2 MySQL questions


wietsed
08-24-2006, 05:39 PM
I have two questions about MySQL.
I'm only two days into MySQL and having great fun with it, but..I'm running into two problems.
I have build a database with my CD's.

The fields are:
band, album, songs, released.
So far so good :)

Now I also made a webpage with three frames (I know...I'm just playing with it), a topmenu, submenu on the left and the main window.

I have made a dropdown menu in the topmenu containing all the bands.
When I select a band, it's albums are being displayed in the submenu.

So far so good :)

Here is the PHP script that displayes the album (from the Band selected at the topmenu).


<html><head>
<link rel=stylesheet href="styles.css" type="text/css">
</head>
<body>
<div class="album_menu">
<?php
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("mp3albums") or die(mysql_error());


$bandselected=$_GET['SelectBand'];
$query = "SELECT * FROM albums";
$result = mysql_query("SELECT * FROM albums
WHERE band='$bandselected'") or die(mysql_error());

$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$selectedbandalbum=mysql_result($result,$i,"album");

echo $selectedbandalbum;
echo "<hr>";
$i++;
}
?>
</div>
</body>
</html>


Now my first MySQL question is this.

How do I create dynamic links from the album(s) displayed?
This is what I want it to do.
When I click on an album (in the submenu) I want more info about this CD to be displayed in the main window (songs, released etc)

Is this possible? If yes, how?

Now my second question.

Is it possible to store images in a database?
if yes, how?

OK, that's it for now.
Hope someone will take the time to help :D

Reli4nt
08-25-2006, 06:39 AM
I strongly recommend that you use a primary key in your db such as band_id. Having a unique value is the only way to reliably be able to find any records.

Then I would use the key in the links. so that your links look like http://mysite.com/page.php?band=1 you could call it as as you did here except instead of the band name you have a unique identifier in your $_GET variable. With an array like this:

while ($row = mysql_fetch_assoc($result))
{
$band[$row['band_id']]['band_id'] = $row['band_id'];
$band[$row['band_id']]['band'] = $row['band'];
$band[$row['band_id']]['album'] = $row['album'];
$band[$row['band_id']]['song'] = $row['song'];
$band[$row['band_id']]['released'] = $row['released'];
}


...you can access your bands particular information just by using $bandselected.

Let me knowe if that isn't clear.

Mysql can be used to store the link to and image or the name of an image if all images will be in the same directory. This is functionally the same as storing the actual image in the db in many ways but it keeps the db leaner and quicker.