Jump to content

MySQL Help


Guest PcGamerz13

Recommended Posts

Guest PcGamerz13
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

[code]$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>[/code]
Link to comment
https://forums.phpfreaks.com/topic/5379-mysql-help/
Share on other sites

[!--quoteo(post=356812:date=Mar 21 2006, 01:04 AM:name=PcGamerz13)--][div class=\'quotetop\']QUOTE(PcGamerz13 @ Mar 21 2006, 01:04 AM) [snapback]356812[/snapback][/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

[code]
...
while ($row3=mysql_fetch_array($mysql_result3))
{
$Gamer_Tag=$row3["Gamer_Tag"];
}
...
[/code]
[/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:


[code]
...
$Gamer_Tag = array();

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

and then for your dropdown/menu, use:

[code]
foreach ($Gamer_Tag as $tag)
{
   echo '<option>'.$tag.'</option>';
}
[/code]
Link to comment
https://forums.phpfreaks.com/topic/5379-mysql-help/#findComment-19190
Share on other sites

Guest PcGamerz13
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?

[code]$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>[/code]
Link to comment
https://forums.phpfreaks.com/topic/5379-mysql-help/#findComment-19192
Share on other sites

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

[b]EDIT:[/b] or more specifically:

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

hope that helps
Link to comment
https://forums.phpfreaks.com/topic/5379-mysql-help/#findComment-19195
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.