getting this functionality

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rami
Forum Contributor
Posts: 217
Joined: Thu Sep 15, 2005 8:55 am

getting this functionality

Post by rami »

i have a player table with players(player_id,name) in mysql database

and i have game table(game_id,dates,players)

the players field is text filed
where the data is suppose to entered as
-1-5-4-7 .....ie id of the players who are playing...taken from the mutliselect box and used concatenation....(ie first biginning of page player="";
then after getting value from form players.=formplayer[] ....with for loop..there are 11players

after the players insertion into games table....


now i have a drop down box in which i want to diplay players name for a game who are playing in a drop down box..(entered in

player field of game table)

so for that i need to break each as
1
5
4
7 (removing - and take each as one value for query)
and use
select name from players where player_id=.....each one of those one by one

so how can i get this functionality
(make 1-4-5-7) breaking 1 4 5 7 and query for each name to display in drop down menu...


any idea or help
any function or breaking this effieciently and getting that functionality..i think the can be done with implode and explode but any efficient way of doing it and managing initail -

(i am storing as 1-4-7(string in text field) as string as it saves lots of space and donot need to enter row for each player

who is playing on a particular game,any suggestion)
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Look at the explode() function.
rami
Forum Contributor
Posts: 217
Joined: Thu Sep 15, 2005 8:55 am

Post by rami »

what abouts final - in the string and the sub query ..for each
any examplification any where
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

Please Clarify Your Question ( exactly what you need ) I dindn't understand your Question att all

If You Wanna convert 1-2-3-4-5 to 1 <br /> 2<br />3<br />4<br />5<br /> you can use explode()

Code: Select all

<?php
  $plyr_id = "0-1-2-3-4-5-6-7-8-9";
  $arr = explode("-",$plyr_id);
  //print_r($arr);
  for($i=0;$i<=count($arr);$i++)
    {
      echo $arr[$i]."<br />\n";
    }
?>
Post Reply