php_beginner_83 Posted October 1, 2009 Share Posted October 1, 2009 Hi Everyone I'm trying to get info from a table, 'pictures', in my database. The fields in my table that I want to retrieve are 'Description', 'Path', 'Thumbnail'. However, the only info that is being saved in the array is 'Path'. I don't understand why this is happening and have been trying to get it to work. Can anyone see what the problem is?? Thanks $result = mysql_query("SELECT * FROM pictures"); //arrays to hold the titles, descriptions and paths separately $descriptions = array(); $paths = array(); $thumbnails = array(); $counter = 0; //fetch tha data from the database while ($row = mysql_fetch_assoc($result)) { $descriptions[$counter] = $row['Description']; $paths[$counter] = substr(strrchr($row['Path'],92),1); $thumbnail[$counter] = $row['Thumbnail']; $counter++; } Quote Link to comment https://forums.phpfreaks.com/topic/176126-solved-retrieving-info-from-database/ Share on other sites More sharing options...
.josh Posted October 1, 2009 Share Posted October 1, 2009 what does your query string look like? Spell the fields right (case sensitive even)? How do you know the other arrays do not contain it? Where are you outputting them? Quote Link to comment https://forums.phpfreaks.com/topic/176126-solved-retrieving-info-from-database/#findComment-928068 Share on other sites More sharing options...
leafer Posted October 1, 2009 Share Posted October 1, 2009 Hi Everyone I'm trying to get info from a table, 'pictures', in my database. The fields in my table that I want to retrieve are 'Description', 'Path', 'Thumbnail'. However, the only info that is being saved in the array is 'Path'. I don't understand why this is happening and have been trying to get it to work. Can anyone see what the problem is?? Thanks $result = mysql_query("SELECT * FROM pictures"); //arrays to hold the titles, descriptions and paths separately $descriptions = array(); $paths = array(); $thumbnails = array(); $counter = 0; //fetch tha data from the database while ($row = mysql_fetch_assoc($result)) { $descriptions[$counter] = $row['Description']; $paths[$counter] = substr(strrchr($row['Path'],92),1); $thumbnail[$counter] = $row['Thumbnail']; $counter++; } Try a print_r($row) and see what comes up. Quote Link to comment https://forums.phpfreaks.com/topic/176126-solved-retrieving-info-from-database/#findComment-928070 Share on other sites More sharing options...
php_beginner_83 Posted October 1, 2009 Author Share Posted October 1, 2009 I've been echoing the values to the screen to see if the arrays contain anything and only $paths does. When I do this this is what I get.... path: alcatraz1.jpg description: thumbnail: Thanks for the suggestion leafer...This was the output I got.. Array ( [iD] => 15 [Description] => Welcome to Alcatraz. [Path] => images\alcatraz1.jpg [Thumbnail] => thumbs\alcatraz1.jpg ) So I see that the values are there but why isn't my code working :confused: Quote Link to comment https://forums.phpfreaks.com/topic/176126-solved-retrieving-info-from-database/#findComment-928077 Share on other sites More sharing options...
.josh Posted October 1, 2009 Share Posted October 1, 2009 what does your query string look like? Spell the fields right (case sensitive even)? How do you know the other arrays do not contain it? Where are you outputting them? Quote Link to comment https://forums.phpfreaks.com/topic/176126-solved-retrieving-info-from-database/#findComment-928078 Share on other sites More sharing options...
leafer Posted October 1, 2009 Share Posted October 1, 2009 I've been echoing the values to the screen to see if the arrays contain anything and only $paths does. When I do this this is what I get.... path: alcatraz1.jpg description: thumbnail: Thanks for the suggestion leafer...This was the output I got.. Array ( [iD] => 15 [Description] => Welcome to Alcatraz. [Path] => images\alcatraz1.jpg [Thumbnail] => thumbs\alcatraz1.jpg ) So I see that the values are there but why isn't my code working :confused: The values names look correct. Try feeding the values into a variable like this: $descriptions[] = $row['Description']; $paths[] = substr(strrchr($row['Path'],92),1); $thumbnail[] = $row['Thumbnail']; Remove the counter altogether. Quote Link to comment https://forums.phpfreaks.com/topic/176126-solved-retrieving-info-from-database/#findComment-928081 Share on other sites More sharing options...
mvfreelance Posted October 1, 2009 Share Posted October 1, 2009 try <? $result = mysql_query("SELECT Description, Path, Thumbnail FROM pictures"); //arrays to hold the titles, descriptions and paths separately $desc = array(); $paths = array(); $thumbs = array(); $cnt = 0; //fetch tha data from the database while ($row = mysql_fetch_array($result , MYSQL_NUM )) { $desc[$cnt] = $row[0]; $paths[$cnt] = substr(strrchr($row[1],92),1); $thumbs[$cnt] = $row[2]; $cnt++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/176126-solved-retrieving-info-from-database/#findComment-928084 Share on other sites More sharing options...
php_beginner_83 Posted October 1, 2009 Author Share Posted October 1, 2009 Thanks for the help. mvfreelance...your suggestion worked a treat Though now I've tried to use a new sql statement.. $result = mysql_query("SELECT ID, Description, Path, Thumbnail FROM pictures INNER JOIN pics_in_albums ON pictures.ID = pics_in_albums.PicID INNER JOIN albums ON pics_in_albums.AlbumID = albums.ID WHERE albums.ID = 1 GROUP BY pictures.ID") or die(mysql_error()); and this is what I get, using the same code just this sql is different,..... "Column 'ID' in field list is ambiguous" Do you know what the problem is with this?? Quote Link to comment https://forums.phpfreaks.com/topic/176126-solved-retrieving-info-from-database/#findComment-928104 Share on other sites More sharing options...
leafer Posted October 1, 2009 Share Posted October 1, 2009 Thanks for the help. mvfreelance...your suggestion worked a treat Though now I've tried to use a new sql statement.. $result = mysql_query("SELECT ID, Description, Path, Thumbnail FROM pictures INNER JOIN pics_in_albums ON pictures.ID = pics_in_albums.PicID INNER JOIN albums ON pics_in_albums.AlbumID = albums.ID WHERE albums.ID = 1 GROUP BY pictures.ID") or die(mysql_error()); and this is what I get, using the same code just this sql is different,..... "Column 'ID' in field list is ambiguous" Do you know what the problem is with this?? IIRC it means the the column name ID exists in both tables. Quote Link to comment https://forums.phpfreaks.com/topic/176126-solved-retrieving-info-from-database/#findComment-928115 Share on other sites More sharing options...
php_beginner_83 Posted October 1, 2009 Author Share Posted October 1, 2009 Thanks for your help. I finally got it sorted. Quote Link to comment https://forums.phpfreaks.com/topic/176126-solved-retrieving-info-from-database/#findComment-928153 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.