Page 1 of 2

Making a call to a database

Posted: 06 Jun 2010, 15:29
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.

Re: Making a call to a database

Posted: 07 Jun 2010, 07:20
by Stoker
You can do it like its done here: viewtopic.php?f=4&t=3
Ask if you need more help.

Re: Making a call to a database

Posted: 07 Jun 2010, 19:38
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

Re: Making a call to a database

Posted: 07 Jun 2010, 19:42
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!

Re: Making a call to a database

Posted: 07 Jun 2010, 20:05
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]

Re: Making a call to a database

Posted: 07 Jun 2010, 20:40
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!

Re: Making a call to a database

Posted: 08 Jun 2010, 17:07
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?

Re: Making a call to a database

Posted: 08 Jun 2010, 20:19
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?

Re: Making a call to a database

Posted: 08 Jun 2010, 20:35
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

Re: Making a call to a database

Posted: 08 Jun 2010, 21:00
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!