RE: select inside a while loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

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:mike@xxxxxxxx]
Verzonden: vrijdag 28 november 2003 6:06
Aan: php-db@xxxxxxxxxxxxx
Onderwerp: select inside a while loop


Hello,

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`)
) TYPE=MyISAM;

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

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
die(mysql_error());

   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.

Thanks,
Mike

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux