Jump to content

Recommended Posts

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++;
}

Link to comment
https://forums.phpfreaks.com/topic/176126-solved-retrieving-info-from-database/
Share on other sites

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.

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: :confused:

 

 

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: :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.

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++;
}
   
?>

Thanks for the help.

 

mvfreelance...your suggestion worked a treat  :D

 

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

Thanks for the help.

 

mvfreelance...your suggestion worked a treat  :D

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.