Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

display an image from a field value


Mighty Mike

Recommended Posts

Hi

 

What i am looking to do is have a field in my database with numerical values in it ie 12,16,18 and so on. And when this field is called upon it would generate an image

 

ie. 12=display image 12

 

Any ideas how i would do this?

 

Thanks

 

Mike

Link to comment
Share on other sites

If you are usig PHP what you do:

 

you make sure that all your images are the sime type (.gif, or .jpg)

then you write

<img src="ImagPath/<?php echo $row_tableName['imagename']; ?>.jpg" />

at the end of the day the code will be good

Link to comment
Share on other sites

If you are usig PHP what you do:

 

you make sure that all your images are the sime type (.gif, or .jpg)

then you write

<img src="ImagPath/<?php echo $row_tableName['imagename']; ?>.jpg" />

 

 

Ok

 

For example lets call the field rating

 

So if i wanted to do this on the product_info file for example i could put it in the query something like this

 

$rating = select rating from table products where products_id = products_id ??

 

then to do the display, it would be like this

 

<img src="ImagPath/<?php echo $rating['imagename']; ?>.jpg" />

 

does that sound correct or am i talking rubbish here?

 

Cheers

 

Mike

Link to comment
Share on other sites

Ok

 

For example lets call the field rating

 

So if i wanted to do this on the product_info file for example i could put it in the query something like this

 

$rating = select rating from table products where products_id = products_id ??

 

then to do the display, it would be like this

 

<img src="ImagPath/<?php echo $rating['imagename']; ?>.jpg" />

 

does that sound correct or am i talking rubbish here?

 

Cheers

 

Mike

 

No it would be this

 

<img src="ImagePath/<?php echo $rating['rating']; ?>.jpg" />

 

Why? because your field is called 'rating' not 'imagename'

 

as an aside

 

I just want to check that you know thats not how to do a query

Link to comment
Share on other sites

No it would be this

 

<img src="ImagePath/<?php echo $rating['rating']; ?>.jpg" />

 

Why? because your field is called 'rating' not 'imagename'

 

as an aside

 

I just want to check that you know thats not how to do a query

 

 

yes i think so, still a newbie tho

 

but something like this i would imagine

 

$rating_query = tep_db_query("select rating, products_id from " . TABLE_PRODUCTS . " where rating = products_id");

 

the where clause is where i always get stuck tho...

 

:-"

 

thanks

 

mike

Link to comment
Share on other sites

yes i think so, still a newbie tho

 

but something like this i would imagine

 

$rating_query = tep_db_query("select rating, products_id from " . TABLE_PRODUCTS . " where rating = products_id");

 

the where clause is where i always get stuck tho...

 

:-"

 

thanks

 

mike

 

So I see :) that where clause is trying to join a field in the same table to a field in the same table.

 

the where clause would be something like

 

$ThisIsTheProductIWant = 12;

$Query = "select products_id, rating from ".TABLE_PRODUCTS." where products_id = $ThisIsTheProductIWant";

$Result = tep_db_query($Query);

while ($Record = tep_db_fetch_array($Result)){
    $ImageIWant = $Record['rating'];
}

<img src="ImagePath/<?php echo $ImageIWant; ?>.jpg" />

 

Sorry if this seems a bit long winded but I prefer to program that way, makes it easier to debug.

 

For instance if it wasnt working first thing I would do is print the query like this

 

print $Query;

 

to check if it was constructed correctly, when you just issue it straight the the query function you dont get the chance to do things like this.

 

Mike

 

just looking at your name I should change mine to the Mighty Quinn

Link to comment
Share on other sites

So  I see :)  that where clause is trying to join a field in the same table to a field in the same table.

 

the where clause would be something like

 

$ThisIsTheProductIWant = 12;

$Query = "select products_id, rating from ".TABLE_PRODUCTS." where products_id = $ThisIsTheProductIWant";

$Result = tep_db_query($Query);

while ($Record = tep_db_fetch_array($Result)){
    $ImageIWant = $Record['rating'];
}

<img src="ImagePath/<?php echo $ImageIWant; ?>.jpg" />

 

Sorry if this seems a bit long winded but I prefer to program that way, makes it easier to debug.

 

For instance if it wasnt working first thing I would do is print the query like this

 

print $Query;

 

to check if it was constructed correctly, when you just issue it straight the the query function you dont get the chance to do things like this.

 

Mike

 

just looking at your name I should change mine to the Mighty Quinn

 

 

Cheers Mighty Quinn :D

 

That looks great!

 

The only bit i am not sure about is "$ThisIsTheProductIWant = 12;" would that not just return the same result all of the time? ie it is looking for "12" :huh:

 

Anyway, its been a long day for me here in London gotta go and get some shut eye.

 

Ill give it a go 2moro.

 

Once again, Thanks :thumbsup:

Link to comment
Share on other sites

Cheers Mighty Quinn  :D

 

That looks great!

 

The only bit i am not sure about is "$ThisIsTheProductIWant = 12;" would that not just return the same result all of the time? ie it is looking for "12"  :huh:

 

Anyway, its been a long day for me here in London gotta go and get some shut eye.

 

Ill give it a go 2moro.

 

Once again, Thanks  :thumbsup:

 

That was only for example purposes, you would need to pass a real variable in there to get what you wanted out :thumbsup:

 

Yeah its been quite a day, we had a controlled explosion on a suspect package on a bus up here in Edinburgh.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...