Jump to content

putting together a URL from a DB


Emil_RDW

Recommended Posts

Hello all,

 

i'm having a small problem that I've been at for a few hours now  :-\

 

I'm trying to display a URL of a picture into an RSS feed of a product.  The problem is that the URL is broken down so there is a constant part, a dynamic part based on a product id, and a constant part at the end.

 

so I'm trying to do this:

 

Constant: http://www.site.com/thumbnail.php?pic= 

 

Dynamic: img_101579_a11e855075f89869384e4e0872.jpg (stored in a database)

 

Constant: &w=100&sq=Y&b=Y at the end

 

 

So far this is that I have but all it does it generate a capital S instead of the dynamic ashdfalsjd.jpg

 

 

$photourl = "SELECT * FROM media WHERE product_id='".$row['product_id']."' LIMIT 1");

$photo_link = utf8_encode('http://www.site.com/thumbnail.php?pic='.$photourl['media_url'].'&w=100&sq=Y&b=Y');


<image_link>$photo_link</image>

 

To clarify the example, the url that I need plugged in is in "media_url" of the media table of the DB

 

 

and like I said above if I run this I get <image>http://www.site.com/thumbnail.php?pic=S&w=100&sq=Y&b=Y</image>

 

Am I missing something?  If I replace the DB call with a constant number it work perfect so I know I'm missing something and not calling the right DB value right.

 

I hope I was clear enough

 

Thank you

 

 

Link to comment
https://forums.phpfreaks.com/topic/265595-putting-together-a-url-from-a-db/
Share on other sites

You've assigned the query string to the variable $photourl. You haven't executed a query, or fetched any results.

 

I see what you mean that I've assigned the query to the $photourl but in the second line aren't I executing it by asking it to fetch me the "media_url" from that and placing it in between the 2 constants?

 

Thanks

actually do you mean something like

 

$photourl = "SELECT * FROM media WHERE product_id='".$row['product_id']."' LIMIT 1");

$photofetch = mysql_query($photourl) or die(mysql_error());

$photo_link = utf8_encode('http://www.site.com/thumbnail.php?pic='.$photofetch['media_url'].'&w=100&sq=Y&b=Y');

 

 

Or am I way off?  :-\

 

Ok, I finally figured out what you mean!  :D

 

My final code that works is:

 

 

function getSqlNumber($sqlQuery) {
$query=@mysql_query($sqlQuery);
$result=@mysql_num_rows($query);
@mysql_free_result($query);
return $result;
}

function getSqlRow($query) {
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
mysql_free_result($result);
return $row;
}

$photo = getSqlNumber("SELECT media_id FROM media WHERE product_id='".$row['product_id']."'");

if ($photo) 
{
$photodetails = getSqlRow("SELECT * FROM media WHERE product_id='".$row['product_id']."' LIMIT 1");

$photo_link = utf8_encode('http://www.site.com/thumbnail.php?pic='.$photodetails['media_url'].'&w=100&sq=Y&b=Y');
} else {
$photo_link = "http://www.site.com/images/no_image.gif";
}

<image>$photo_link</image>

 

 

Thank you Pikachu2000 for pointing me in the right direction!

Archived

This topic is now archived and is closed to further replies.

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