Page 2 of 2

Re: Pulling image name from DB with PHP

Posted: Mon Sep 07, 2009 3:47 pm
by jackpf
No, you need to do it the way that I showed you. Don't rush it or anything...you should take your time, sit down for a while, and read a tutorial properly :)

Follow the examples...see if you can do it yourself...try to understand how the language works, not just if you can piece together enough of it to get a half working script :)

I don't mean offense by this...I'm just trying to encourage you. Not put you off...

Re: Pulling image name from DB with PHP

Posted: Mon Sep 07, 2009 4:59 pm
by nkzle
lol i didnt know if you was smart mouthing or what but it was no prob, I did do what you suggested and it's much appreciated. And i did sit back read through all those tabs of tutorials and did some extra research and i got it. This is what i came up with:

$con = mysql_connect("localhost","name","pw");
if (!$con)
{
die('Could not connect, D: ' . mysql_error());
}

mysql_select_db("db name", $con);

$sql = "SELECT `media`.`med_file`
FROM `media`
INNER JOIN `Profiles` AS `P` ON `P`.`ID` = `media`.`med_prof_id`
INNER JOIN `RayMusicFiles` AS `Ray` ON `Ray`.`Owner` = `media`.`med_prof_id`
INNER JOIN `Profiles` AS `PP` ON `PP`.`PrimPhoto` = `media`.`med_id`
WHERE `Ray`.`{$this->aTableFields['medProfId']}` = 1
";

$result = mysql_query($sql);
$imgid = mysql_fetch_object($result);

if (!$result)
{
die('U F*d Up Somewhere, D: ' . mysql_error(). " Actual query: " . $sql);
}

$sImage = '<div class="lastFilesPic"><a href="'.$sHref.'"><img src="'.$this->sThumbUrl.$aData['medProfId'].'/thumb_'.$imgid->med_file.'"></a></div>';
break;

---- my issue was not only the object but also this part: <img src="'.$this->sThumbUrl.$aData['medProfId'].'/thumb_'.$imgid->med_file.'"> // i had the image var like $imgid['med_file'] but switched it to $imgid->med_file. Worked beautifully.

That was the biggest issue and i suspect my next issue should be a piece of cake, i might actually figure it out before you or anyone else read this but still want to know your suggestions or anyone else if any to suggest :mrgreen: =D.

All i simply need to know now is on the WHERE clause i have "1" for profile "1" and it shows up for the thumbnails that are from profile 1 but how can i leave it to where the profile number is inserted as it's called for so the thumbnails for profile 2 and 3, etc can show up as well? I tried a few different ways already but like i said, i am a bit slow :mrgreen: . And thanks for all the help, it's very very very appreciated

Re: Pulling image name from DB with PHP

Posted: Mon Sep 07, 2009 5:41 pm
by nkzle
I GOT IT!!

WHERE `Ray`.`{$this->aTableFields['medProfId']}`= {$aData['medProfId']} is what i had to add so it'll fetch the member ID properly. YESSSSSS!!!!!!!!!!!!!!!!!!!!!!!!!!!

Re: Pulling image name from DB with PHP

Posted: Mon Sep 07, 2009 5:57 pm
by jackpf
Well done! See!!! If you chill out and do a bit of research it's a piece of cake ;)

Yeah, arrays and objects are different. Elements are accessed in a different way:

Code: Select all

$array = array('something' => 'some_value');
 
echo $array['something']; //outputs "some_value"
 
$object = new stdclass;
 
$object->something = 'some_value';
 
echo $object->something; // should ouput "some_value" as well
So yeah...if you want to have an array of your mysql data, you can use mysql_fetch_array() (or _assoc(), or _row())...

But yeah, nice one.