I have three php arrays that i am filling up with information returned from a msql query. The first two arrays fill up perfectly with the information need but the last array does not fill up. The only thing that gets entered is a ‘v’. It works perfectly if i don’t make it an array and just a single value but when i make it an array it stops working. If you have any ideas thanks.
$query = mysql_query("SELECT * FROM chanels WHERE cname = '$cname' ");
$numrows = mysql_num_rows($query);
while($row = mysql_fetch_array($query))
{
$videolocation[$counter2] = $row['videolocation'];
$title[$counter2] = $row['title'];
$imagelocation[$counter2] = $row['videoimagelocation'];
$counter2++;
}
ImageLocation array is the one that does not work while the other two fill up perfectly. I have checked spelling and everything is entered perfectly.
Instead of using
fetch_arrayuse mysql_fetch_assoc for your method so that you bring back the rows with keys in the array named as the columns in the results – like this:Also, you should probably move away from the old
mysql_*functions and tinker with the new shiny PDO functions. These will let you connect in a much safer manner as well as providing much more flexibility.Edit: When you bring back an assoc array, it is still a single row of the database. However, your current code returns something like this:
And Assoc Array will work like this:
Edit 2: It seems that I chased down a bit of a red herring with the array vs assoc issue. The first thing that I could check is the spelling, but you have done that, the next is check the case of the column names. On windows, the case is by default not important, but on Linux machines it is.
I find the easiest way is to do this:
If a column is the wrong case, this should return an error for you.