Jump to content


MySQL Help


  • Please log in to reply
3 replies to this topic

#1 Guest_PcGamerz13_*

Guest_PcGamerz13_*
  • Guests

Posted 21 March 2006 - 01:04 AM

It only shows 1 Gamer_Tag from the database instead of all the Gamer Tags. Can someone fix it plz.
I want all the Gamer Tags into one Option plz help

$sql3="SELECT * FROM clan_members";
$mysql_result3=mysql_query($sql3);
$num_rows3=mysql_num_rows($mysql_result3);
while ($row3=mysql_fetch_array($mysql_result3))
{
$Gamer_Tag=$row3["Gamer_Tag"];
}
echo "<center><font size='4'>Report Member</font></center>";
?>
<form method="POST" action="Report_Member.php?Report_Member=Yes">
<center>Gamer Tag: <select size="1" name="Reported_Gamer_Tag"><option><? echo $Gamer_Tag; ?></option></select></center>
<center>Reason: <textarea rows="2" name="Reason" cols="20"></textarea></center>
<center><input type="submit" value="Submit" name="B1">
</form>


#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 21 March 2006 - 01:40 AM

[!--quoteo(post=356812:date=Mar 21 2006, 01:04 AM:name=PcGamerz13)--][div class=\'quotetop\']QUOTE(PcGamerz13 @ Mar 21 2006, 01:04 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
It only shows 1 Gamer_Tag from the database instead of all the Gamer Tags. Can someone fix it plz.
I want all the Gamer Tags into one Option plz help

...
while ($row3=mysql_fetch_array($mysql_result3))
{
$Gamer_Tag=$row3["Gamer_Tag"];
}
...
[/quote]

here's a problem. you re-assign the value of $Gamer_Tag every time. if you want $Gamer_Tag to be an array, so you can just store all the values from the database, just use $Gamer_Tag[] instead:


...
$Gamer_Tag = array();

while ($row3=mysql_fetch_array($mysql_result3))
{
$Gamer_Tag[]=$row3["Gamer_Tag"];
}
...

and then for your dropdown/menu, use:

foreach ($Gamer_Tag as $tag)
{
   echo '<option>'.$tag.'</option>';
}

"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 Guest_PcGamerz13_*

Guest_PcGamerz13_*
  • Guests

Posted 21 March 2006 - 01:45 AM

i got this code now and all it shows in the drop down is Array. How do you make this code show the whole list of the Gamer Tags in the table?

$sql3="SELECT * FROM clan_members";
$mysql_result3=mysql_query($sql3);
$num_rows3=mysql_num_rows($mysql_result3);
$Gamer_Tag = array();
while ($row3=mysql_fetch_array($mysql_result3))
{
$Gamer_Tag[]=$row3["Gamer_Tag"];
}
?>
<form method="POST" action="Report_Member.php?Report_Member=Yes">
<center>Gamer Tag: <select size="1" name="Reported_Gamer_Tag"><option><? echo $Gamer_Tag; ?></option></select></center>
<center>Reason: <textarea rows="2" name="Reason" cols="20"></textarea></center>
<center><input type="submit" value="Submit" name="B1">
</form>


#4 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 21 March 2006 - 01:55 AM

whoops sorry i may have added to my post after you first read it. use the 'foreach' command (check my post above) which will just cycle through each item in the array and make a dropdown item from it

Cheers
Mark

EDIT: or more specifically:

<select size="1" name="Reported_Gamer_Tag">
   <?php
   foreach ($Gamer_Tag as $tag)
   {
      echo '<option>'.$tag.'</option>';
   }
   ?>
</select>

hope that helps
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users