PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am trying to get a quick 1-dim array of the data from a mysql query. It's only 1 field that I'm querying but I have had a 'brain-fart' all day today. Below is what I have..that isnt working. The error I am getting is "parse error, unexpected ']'"
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Try this and see if you are getting any other errors. Also, make sure to look just above this code (or just above the line that you are getting the error on) because the code you posted looks clean at first.
<?php
$query = 'SELECT `state` FROM `states`';
if (!$result = mysql_query($query,$db))
{
die('Could not get the state list: ' . mysql_error());
}
while ($myrow = mysql_fetch_array($result))
{
$starray[] = $myrow;
}
?>
I also noticed you were trying to use mysql_fetch_assoc on your query, not the result. The error you got may be because you were trying to fill an array with non-existent mysql result.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Below is the code. The line I am getting the error on is [b]$starray[] = $myrow['state'];[/b]. The get variables are populating just fine.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by kbrown3074 on Mon Jul 24, 2006 11:33 am, edited 1 time in total.