Making a call to a database

Support for PhpBB3 BBCodes. Post here to get help with any BBCode related issue here
There is no support here! Only Read Access!
Forum rules
In order the get any support, you will have to do following:
1. Use a describing title!
2. Describe exactly what it is you want.
3. Tell us what version of phpBB3 you are currently using.
Else your topic may be ignored or locked!
Drexlin
BBCoder II
BBCoder II
Posts: 5
Joined: 06 Jun 2010, 15:18

Making a call to a database

Post by Drexlin »

I'm hoping someone here will be able to help me.

I have a fan site for a trading card game. I created a database with all the cards and images in it. Now I want to write a custom BBCode that searches my database for the card image given the name. Something like this:

Code: Select all

[card="Card Name"]Card Name[/card]
So is there a way to get the embedded html to make a call to the database and replace the card name with a url so it displays an image?

I hope this is clear.
User avatar
Stoker
Site Admin
Site Admin
Posts: 3536
Joined: 12 May 2008, 23:26
BBCodes: 239
Favourite BBCode: Anipro
Favourite MOD: PrettyPhoto
Location: Denmark
Contact:

Re: Making a call to a database

Post by Stoker »

You can do it like its done here: viewtopic.php?f=4&t=3
Ask if you need more help.
Board rules! No PM support
Drexlin
BBCoder II
BBCoder II
Posts: 5
Joined: 06 Jun 2010, 15:18

Re: Making a call to a database

Post by Drexlin »

Hey Stoker,

Thanks for the response, but that's not exactly what I'm looking for. That would work great assuming the poster knows the url of the image. But since they more than likely won't know the url, I would like to look it up in the database.

So I guess my real question is: Is there a way to do this using PHP or javascript? I actually tried using PHP already in the "HTML Replacement" field, but it didn't work because when I try to run the $rs->execute($query), I'm guessing the "greater than" sign is causing a parsing problem, and I don't get the expected result.

Anyway, if there is any insight you can provide, it is much appreciated.

Thanks!
Drex
cisco007
BBCoder VI
BBCoder VI
Posts: 1015
Joined: 16 Mar 2010, 18:14
Location: Don't really know!

Re: Making a call to a database

Post by cisco007 »

what Stoker is saying is simple, if you have the images of the cards, just upload them in a particular folder inside your images folder and use the html replacement similar to what Stoker pointed to, that way you use the bbcode just like the country flag bbcode uses!
User avatar
Stoker
Site Admin
Site Admin
Posts: 3536
Joined: 12 May 2008, 23:26
BBCodes: 239
Favourite BBCode: Anipro
Favourite MOD: PrettyPhoto
Location: Denmark
Contact:

Re: Making a call to a database

Post by Stoker »

Yes, with the flag bbcode I can just post this:

Code: Select all

[flag]dk[/flag]
and then it will display the danish flag: [flag]dk[/flag]
Board rules! No PM support
Drexlin
BBCoder II
BBCoder II
Posts: 5
Joined: 06 Jun 2010, 15:18

Re: Making a call to a database

Post by Drexlin »

Maybe I'm just not explaining correctly...

The problem is my card images are not stored including the name. They are stored something like "./images/cards/ST4.jpg", where "ST" is the abbreviation for the set name, and 4 is the card number.

So here's what I'd like to have happen. The poster types something like:

Code: Select all

[card]Infiltrate[/card]
And the code would take the card name, and look up the set and number in the database so I can create the url. So it would look up "Infiltrate" and find that the set is "ST" and the number is 4. Then I can create the string: "./images/cards/ST4.jpg".

Is that more clear?

Thanks in advance for the help!
User avatar
Stoker
Site Admin
Site Admin
Posts: 3536
Joined: 12 May 2008, 23:26
BBCodes: 239
Favourite BBCode: Anipro
Favourite MOD: PrettyPhoto
Location: Denmark
Contact:

Re: Making a call to a database

Post by Stoker »

I probably doesnt understand what you want.
But if you use this when posting:

Code: Select all

[card]ST4[/card]
it will display that card if you use the correct html. Like in the Flag bbcode.
Do you understand what I mean?
Board rules! No PM support
Drexlin
BBCoder II
BBCoder II
Posts: 5
Joined: 06 Jun 2010, 15:18

Re: Making a call to a database

Post by Drexlin »

Yes, but the user will not know "ST4", he will only know that the name of the card is "Infiltrate". I need some way of looking it up without the user knowing the set and number.

Am I making sense?
cisco007
BBCoder VI
BBCoder VI
Posts: 1015
Joined: 16 Mar 2010, 18:14
Location: Don't really know!

Re: Making a call to a database

Post by cisco007 »

you are making sense but you are not understanding what Stoker is saying! If the user puts [card]Infiltrate[/card]

and you put in the correct html the post will show....

http://yoursite.com//images/cards/ST4.jpg
Drexlin
BBCoder II
BBCoder II
Posts: 5
Joined: 06 Jun 2010, 15:18

Re: Making a call to a database

Post by Drexlin »

cisco007 » 08 Jun 2010, 20:35 wrote:and you put in the correct html the post will show....
This is exactly what I need help accomplishing!

Ok, let me start over...

I have a card database consisting of over 300 cards. Each card has a unique image. For example, "Infiltrate" is ST4.jpg, "Forge" is ST20.jpg, etc. But the user does not know the image names, he only knows that there exists a card named "Infiltrate" and a card named "Forge".

So the user types:

Code: Select all

[card]Infiltrate[/card]
[card]Forge[/card]
Now here's where the magic happens. And I'm not sure how to do this. I need to be able to take the user's input, ie. the card name, and search a database to get the image name so that I can display the correct image. Once this is done, the above would be replaced with:

Code: Select all

<a href="http://my-site.com/forum/images/cards/ST4.jpg" class="preview">Infiltrate</a>
<a href="http://my-site.com/forum/images/cards/ST20.jpg" class="preview">Forge</a>
I hope this is making sense, because I'm really at a loss and don't know what to do.

Thanks again!
Locked