Jump to content


Photo

small problem making a loop


  • Please log in to reply
3 replies to this topic

#1 Wasda

Wasda
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 02 December 2003 - 02:47 AM

hello, im hoping someone could help me with this little problem to me it is hard. let me first explain what my situation is.. i have a table=music, and 4 columns=singerID,url,dir,file... singerID stores identical numbers to each singer. url contains the actual http://www.mysite.com/ and dir is the name of the singer, Tom for example, and the file is mysong.mp3..mysong2.mp3..etc.....but..for singerID i have multiple of the same number, example 5. So every row of 5 have a different mp3 filename. I want to be able to make a loop and returns with a url link with each of the filename. take the top for example.. <a href=url/dir/file>file</a> so it will return each with <a href=http://www.mysite.com/Tom/mysong1,2,3,4..etc.mp3>Mysong..mp3</a>
i hope i explained it clear enough... below is my codes.. any help would be greatly appreciated! thank you in advanced..



$result = mysql_query( \"select url, dir, file from $table where singerid=5\");
while($row = mysql_fetch_row($result)) {
for($i=0; $i < mysql_num_fields($result); $i++) {
echo \"$row[$i]\";
}
}

#2 Deadmeat

Deadmeat
  • Members
  • PipPip
  • Member
  • 20 posts
  • Locationva

Posted 02 December 2003 - 04:33 AM

I\'ll give it a shot, mind you I\'m a beginner still.
[php:1:c5b8530f50]<?php
$result = mysql_query(\"SELECT url,dir,file FROM music WHERE singerid=5\");
while($singer=mysql_fetch_array($result)){
echo \'<a href=\'.$singer[url].\'/\'.$singer[dir].\'/\'.$singer[file].\'>\'.$singer[file].\'</a>\';
}
?>[/php:1:c5b8530f50]

I think this should work, if not, best of luck finding it out.
Free Photoshop Tutorials[br]TutorialMan.com[br]---------------------------[br]Need Webspace thats cheap and reliable?[br]Quik-Online.org

#3 Wasda

Wasda
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 02 December 2003 - 05:19 AM

Deadmeat, thanks for the help, your codes actually worked, but turn out to be another problem with the DIR.. . .in my table.. the column DIR was created with varchar(255).. now i dont know if that causes the problem.. them problem is that, i have for example Michael Foxer for DIR, result show only the first part of the name, it only show Michael. any idea ?

#4 Deadmeat

Deadmeat
  • Members
  • PipPip
  • Member
  • 20 posts
  • Locationva

Posted 02 December 2003 - 12:19 PM

when posting the dir for a link, use ereg_replace(\" \", %20, $dir)

[php:1:bfc4aa609f]<?php
$result = mysql_query(\"SELECT url,dir,file FROM music WHERE singerid=5\");
while($singer=mysql_fetch_array($result)){
echo \'<a href=\'.$singer[url].\'/\'.ereg_replace(\" \", %20, $singer[dir].\'/\'.$singer[file].\'>\'.$singer[file].\'</a>\';
}
?>[/php:1:bfc4aa609f]

What this does is replace all \" \" spaces with \"%20 in the given variable. %20 is the HTML code for space.
Free Photoshop Tutorials[br]TutorialMan.com[br]---------------------------[br]Need Webspace thats cheap and reliable?[br]Quik-Online.org




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users