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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.