Your code looks well. But is the variable $db the name of your database or
your link-identifier. When it is the name of your database i'm not really
surpised your code wouldn't work. mysql_query requires as second argument a
link identifier.

Rolf van de Krol

-----Oorspronkelijk bericht-----
Van: Mike Baerwolf [mailto:[EMAIL PROTECTED]
Verzonden: vrijdag 28 november 2003 6:06
Onderwerp: select inside a while loop


I have two mysql tables songs and artists. They look like this:

CREATE TABLE `artists` (
   `artist_id` int(10) unsigned NOT NULL auto_increment,
   `artist_name` varchar(100) default NULL,
   `artist_img` varchar(50) default NULL,
   PRIMARY KEY  (`artist_id`),
   UNIQUE KEY `artist_name` (`artist_name`),
   KEY `artist_id` (`artist_id`)

CREATE TABLE `songs` (
   `song_id` int(11) NOT NULL auto_increment,
   `song_title` tinytext,
   `artist_id` tinytext,
   PRIMARY KEY  (`song_id`)

Currently I have the artist_id in the songs table setup has a text field
with artist names in them temporarily. First I want to select all the
artist_ids(with the names) and find the artist_id for that name in the
artist table. Then update the artist_id in the song table with the
artist_id in the artist table. Then convert the artist_id in the song
table to int.

So with all that said here is what i have done that doesn't work,

$result = mysql_query("SELECT artist_id FROM songs",$db) or

   if ($row = mysql_fetch_row($result)){
       do {

$artist_name = $row["artist_id"];
$result_1 = mysql_query("SELECT artist_id,artist_name FROM
artists WHERE artist_name = '$artist_name'",$db);
$row_1 = mysql_fetch_array($result_1);
print "$row_1[artist_id]-$row_1[artist_name]";

        }while ($row = mysql_fetch_array($result));

I haven't even been able to get to the update part. I'm pretty sure the
above fails because of the var $artist_name after the first run through.
Any help would be appreciated.


PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to