I am trying to populate a combobox with usernames pulled from mySQL.
This is the [color=seagreen]PHP [/color]code:
$sql = 'SELECT * FROM `' . $users . '`';
while($array = mysql_fetch_array($username); $i++){
print "&writename$i="; $name = mysql_result($fewComments, $i, 'name'); print''. $name .'';}
This is the [color=red]Flash[/color] code:
i=0;
while (this["writename"+i] != undefined){
names.addItemAt(i,this["writename"+i]);
i++;}
When I test it all I get is one entry that says.
“This is a entry”
Any help or directions to tutes on this would be appreciated…
system
July 30, 2004, 1:52am
2
are you sure that sql query returns everything correctly, try doing a print of the array
system
July 30, 2004, 2:12am
3
bugger it’s not…
I had copied the .fla and .php from another one that I knew worked and just added those bits…
I didn’t even consider that it wasn’t recieving data… I will get that working…
system
July 30, 2004, 2:13am
4
good, glad you know where the problem is
system
July 30, 2004, 5:07am
5
Ok I have it working now but I need work on my mySQL query skills.
$sql = 'SELECT name FROM `' . $table . '`';
$allnames = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
for($i=0; $i<=$allnames ; $i++){
print "&named$i="; $name = mysql_result($allnames, $i, 'name'); print''. $name .'';
This is returning only the first 6 names… When I expected it to return all 30.
When I use $numallComments (defined before) it returns all 30 names…
So while I have it working, I don’t understand why the above returned only 6 entries.
This is the script that defines $numallComments
$sql = 'SELECT * FROM `' . $table . '`';
$allComments = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
$numallComments = mysql_num_rows($allComments);
system
July 30, 2004, 5:10am
6
why not just use $row[‘username’] ?
system
July 30, 2004, 5:13am
7
mysql_num_rows($allComments);
Ok this is where it’s getting 30 from…
I will have rewrite mine to include this…
system
July 30, 2004, 5:17am
8
$row[‘username’]
Hey old…
My sql skills are very limited at the moment and I am using this PHP/mySQL project to learn along the way…
How would I use $row[‘username’] in my above script ?
system
July 30, 2004, 5:36pm
9
you already done it a couple of times… as i remember.
// query
echo '<select name="namelistbox">';
while($row = mysql_fetch_assoc($result))
{
echo '<option>'.$row['username'].'</option>';
}
echo '</select>';
system
July 30, 2004, 11:24pm
10
Thanks guys…
This project has been a bigger head ache and taking longer than I thought…
system
July 31, 2004, 12:45am
11
Well this is the php file I ended up with… No doubt it could be done better, but it’s the best I could do and it works…
<?
include 'gb_db.php';
// *******************************************************************************************************
$sql = 'SELECT name FROM `' . $table . '`';
$allComments = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
$numallComments = mysql_num_rows($allComments);
$allnames = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
// ********************************************************************************************************
for($i=0; $i<$numallComments ; $i++){
print "&named$i="; $name = mysql_result($allnames, $i, 'name'); print''. $name .'';}
// ********************************************************************************************************
?>