Jump to content

help needed


joebudden

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.