Jump to content

Need query help


Vizionz

Recommended Posts

CREATE TABLE `Artists` (
  `ID` int(6) unsigned NOT NULL auto_increment COMMENT 'The unique ID',
  `Artist` varchar(200) default NULL COMMENT 'The Artist',
  `ArtistID` varchar(200) default NULL COMMENT 'The Artist Id',
  `Formed` varchar(200) default NULL COMMENT 'Band Formed',
  `Picture` varchar(200) default NULL COMMENT 'The band Artist Picture',
  `Members` text COMMENT 'The Band Members',
  `Genres` int(4) default '0' COMMENT 'Genre of the artist',
  `Bio` text COMMENT 'The Biography',
  `Website` varchar(200) default NULL COMMENT 'The Artists Website',
  `Myspace` varchar(200) default NULL COMMENT 'The Artists Myspace',
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

 

CREATE TABLE `Genres` (
  `ID` int(4) unsigned NOT NULL auto_increment COMMENT 'The unique ID of the section',
  `name` varchar(20) default NULL COMMENT 'The Genre name',
  `parentid` int(4) default '0' COMMENT 'The ID of the parent section',
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=16 DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;

 

$result = $connector->query('SELECT Artist,Genres,Bio FROM Artists  WHERE ID = '.$HTTP_GET_VARS['id']);

 

now as is the last code. that will get me the artist  the bio and the genre from the artist table. but i need to  take that genre from artist and then take that result and replace it with the relevant  row in the genre table. as of now it just gives me the id from the Artists (genres row)  i need the name

from the genres table so i can echo  but dont know how to query that

 

<?php echo $row['Genres'];?>

 

and if you find anything wrong with the way the tables are in mysql please help i am trying to learn to write  code and i am novice

Link to comment
Share on other sites

$result = $connector->query('SELECT Artist,Genres,Bio FROM Artists  WHERE ID = '.$HTTP_GET_VARS['id']);

 

to get the genre name instead of the id

 

<?php
$result = $connector->query('SELECT Artists.Artist,Artists.Bio,Genres.Name 
FROM Artists 
INNER JOIN Genres ON Artists.Genres=Genres.Id 
WHERE ID = '.$HTTP_GET_VARS['id']);

 

you can also do it like

<?php
$result = $connector->query('SELECT Artist,Bio,Name 
FROM Artists 
INNER JOIN Genres ON Artists.Genres=Genres.Id 
WHERE ID = '.$HTTP_GET_VARS['id']);

i just like to use the table.field format for ease of reading. oh and because of the name used in the genres table you will have to echo Name instead of Genre

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.