joebudden Posted March 1, 2007 Share Posted March 1, 2007 hi guys ok.. this is my problem i want to select 6 records from a table but have them all as different variables which i can then post using a form for example $player1 $player2 $player3 $player4 $player5 $player6 racking my brains trying to think how to do it so if anyone has a quick solution let me know!! thanx Link to comment https://forums.phpfreaks.com/topic/40753-help-needed/ Share on other sites More sharing options...
magnetica Posted March 1, 2007 Share Posted March 1, 2007 Ok if i understand correctly it would be somewhere along these lines <?php echo "<form action\"\" method=\"post\">"; echo "<input type=\"submit\" value=\"" . $player1 . "\">"; echo "</form>"; ?> And obviously change the input type and values accordingly Link to comment https://forums.phpfreaks.com/topic/40753-help-needed/#findComment-197287 Share on other sites More sharing options...
fert Posted March 1, 2007 Share Posted March 1, 2007 $count=1; while($row=mysql_fetch_array($result)) { $name="player".$count; $$name=$row['player']; $count++; } Link to comment https://forums.phpfreaks.com/topic/40753-help-needed/#findComment-197288 Share on other sites More sharing options...
joebudden Posted March 1, 2007 Author Share Posted March 1, 2007 no that isnt what i need to do, im ok with that stuff , its getting each player into a separate variable which is my problem... here is what i have so far... <?php // get my players $sql = "select playersurname from player,playsfor where player.playerid = playsfor.playerid and teamid = '$teamid'"; $res = mysql_query($sql) or die (mysql_error()); while($r = mysql_fetch_assoc($res)) { $player1 = $r['playersurname']; $player2 = $r['playersurname']; } echo $player1; echo $player2; but this just gets the first playername for both variables.. see what i mean ?? Link to comment https://forums.phpfreaks.com/topic/40753-help-needed/#findComment-197290 Share on other sites More sharing options...
joebudden Posted March 1, 2007 Author Share Posted March 1, 2007 ok i see what you were trying to do with that Fert, but does that enable me to have each playername in its own variable.. because im trying to echo $name4 or $player4 and its saying undefined :S Link to comment https://forums.phpfreaks.com/topic/40753-help-needed/#findComment-197296 Share on other sites More sharing options...
joebudden Posted March 1, 2007 Author Share Posted March 1, 2007 i take what i'm trying to do is not possible so i fort of doing it this way... if i get the six players names into a string but separate each by a `:` can i use the list and explode functions to get each name into a separate variable?? so far iv implemented this code.. <?php // get my players $sql = "select playersurname from player,playsfor where player.playerid = playsfor.playerid and teamid = '$teamid'"; $res = mysql_query($sql) or die (mysql_error()); while($r = mysql_fetch_assoc($res)) { $name = $r['playersurname']; $string = $name.":"; } list($p1, $p2, $p3, $p4, $p5, $p6) = explode(":", $string); ?> but it doesn't work and i get this error message: Notice: Undefined offset: 5 in C:\p3t\public_php\__PHPManager__\form.php on line 153 Notice: Undefined offset: 4 in C:\p3t\public_php\__PHPManager__\form.php on line 153 Notice: Undefined offset: 3 in C:\p3t\public_php\__PHPManager__\form.php on line 153 Notice: Undefined offset: 2 in C:\p3t\public_php\__PHPManager__\form.php on line 153 does anyone know i can fix it ?? or fink of a better way thanx Link to comment https://forums.phpfreaks.com/topic/40753-help-needed/#findComment-197371 Share on other sites More sharing options...
bwochinski Posted March 1, 2007 Share Posted March 1, 2007 Why do you want each name in a separate variable? What are you doing with the names? Link to comment https://forums.phpfreaks.com/topic/40753-help-needed/#findComment-197384 Share on other sites More sharing options...
joebudden Posted March 1, 2007 Author Share Posted March 1, 2007 sending them to a flash swf Link to comment https://forums.phpfreaks.com/topic/40753-help-needed/#findComment-197386 Share on other sites More sharing options...
Adika Posted March 1, 2007 Share Posted March 1, 2007 Hi joebudden, Do this and it will be what you were looking for: <?php // get my players $sql = "select playersurname from player,playsfor where player.playerid = playsfor.playerid and teamid = '$teamid'"; $res = mysql_query($sql) or die (mysql_error()); $i = 1; $name = array(); while($r = mysql_fetch_assoc($res)) { $name[$i] = $r['playersurname']; $i++; } echo $name[1]; // echoes the first name echo $name[4]; // echoes the forth name ?> You must use array! All the best, Adika Link to comment https://forums.phpfreaks.com/topic/40753-help-needed/#findComment-197430 Share on other sites More sharing options...
fert Posted March 1, 2007 Share Posted March 1, 2007 because im trying to echo $name4 or $player4 and its saying undefined :S it worked fine for me. Link to comment https://forums.phpfreaks.com/topic/40753-help-needed/#findComment-197433 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.