PDA

View Full Version : Trying to write my first "hack"...


NeroTheWarlord
10-12-2004, 09:54 PM
Ok, this isn't exactly integrated into vbadvanced.. yet. I hope to be able to do so in the near future though. But before I even start trying to do that, I need to get this script running the way I want it first.

I call it the Character Database Hack, and it is exactly what it sounds like.. a database of information for character biographies. (useful for comic book biographies, RPG biographies, etc)

It allows users to submit biographies or bios for short, of their favorite characters. In my case it's comic book characters. And then displays them by company, and then alphabetically by name. Once you choose a character you wish to view, you click on the corresponding link and you can view that character's bio.

Now I've run into a couple problems, that I was hoping someone here might be able to help me with.

Problem #1:

The "Sorry, no records were found!" under Darkhorse Comics shows up as it's supposed to, but the same text under Crossgen and Image link to DC's Superman bio (id1). I don't see my error...What gives?

URL to view it live:

http://www.neropolis.com/index.php?page=bios

Problem #2:

When you click on a character to view their bio, it shows the bio fields for each company instead of just the one that the character belongs to.

I've attached the code I'm using for the listing of the character names and bios to this thread.

I'm still new to SQL and php but I'm slowly but surely teaching myself, from web tutorials and a book called "PHP, fast and easy web development" by Julie C Meloni.

Is there anyone who could please help me work on this project? These bugs are driving me nuts...

Ghostsuit
10-12-2004, 11:05 PM
Ehh no attachment. Plus at the moment doesn't seem much of an addon for CMPS so might be better in a How to forum or in a PHP/MYSQL forum.

Still I like the idea of what your trying to do.

Our Sponsors
 

NeroTheWarlord
10-12-2004, 11:36 PM
oops, lol.. here's the txt file of the script...

And I found a way to make it more of an add on as a module on a new page with a hack here on vbadvanced.com to use php in templates (still working some pages of it though).

All I have left is to make the pages for the different comic company submissions. But I'll probably do those tomorrow.. I gotta hit the sack.

NeroTheWarlord
10-12-2004, 11:42 PM
oook.. just realized I'd have to create a page and module for each character submitted if I wanted to do it this way. Think I'm gonna pass on that and put it back the way it was... tomorrow.

Our Sponsors
 

Ghostsuit
10-13-2004, 06:31 AM
Problem #1:

The "Sorry, no records were found!" under Darkhorse Comics shows up as it's supposed to, but the same text under Crossgen and Image link to DC's Superman bio (id1). I don't see my error...What gives?

URL to view it live:

http://www.neropolis.com/index.php?page=bios

Your not closing you href tags. You have<a href='/cbd/bioslist.php?id=1'>Superman
When it should be
<a href='/cbd/bioslist.php?id=1'>Superman</a>
Looking at the page source you seem to have missed it on them all.
Problem #2:

When you click on a character to view their bio, it shows the bio fields for each company instead of just the one that the character belongs to.

after a quick look I'd say this is the problem
if ($id)

You use it for all the if statements and thats why the bio fields appear for all the companies since if you have an id it's positive so the if statement carries out but since there isn't a line in most of the companies for that id you only see the bio fields until it get's to the one that needs it.

It looks like your using a seperate table for each company, I think you'd be better to create a category/company table and link that to the bios.

For example Tables..
Company
id
Name
etc

Bio
id
companyid
etc

You have Marvel in the company table as id 1
You have DC in the company table as id 2
Wolverines bio companyid is 1
Supermans bio companyid is 2

Then you should be able to join the tables to print a characters details along with the company name and any additional info you require. You would also not need most of the IF statements you use.

Hope that helps or makes sense.

NeroTheWarlord
10-13-2004, 01:11 PM
Well Ghostsuit, thanks for the reply, and I already have a field for company name, so I think I'm going to try and use that.

After reading my php book some more, I think I can fix the bug with all the companies showing up for every bio no matter what company the bio belongs to by adding an && operator to the if statement like this.



echo "<b><u>Darkhorse Comics Characters</u></b><br>";

// display individual record
if (($id) && ($company == "Darkhorse Comics"))
{
$result = mysql_query("SELECT * FROM cbd_darkhorse WHERE id=$id", $db);
$myrow = mysql_fetch_array($result);
printf("<p align=center> %s\n<br /></p>", $myrow['image']);
printf("<b>Company:</b> %s\n<br>", $myrow['company']);
printf("<b>Name:</b> %s\n<br>", $myrow['name']);
printf("<b>Real Name and Aliase(s):</b> %s\n<br>", $myrow['realname']);
printf("<b>Legal Status:</b> %s\n<br>", $myrow['legalstatus']);
printf("<b>First Appearance:</b> %s\n<br>", $myrow['firstappearance']);
printf("<b>Group Affiliation:</b> %s\n<br>", $myrow['team']);
printf("<b>Height:</b> %s\n<br>", $myrow['height']);
printf("<b>Weight:</b> %s\n<br>", $myrow['weight']);
printf("<b>Hair Color:</b> %s\n<br>", $myrow['hair']);
printf("<b>Eye Color:</b> %s\n<br>", $myrow['eyes']);
printf("<b>Identifying Features:</b> %s\n<br>", $myrow['featurest']);
printf("<b>Powers and Abilities:</b> %s\n<br><br>", $myrow['powers']);
printf("<b>Known Weaknesses:</b> %s\n<br><br>", $myrow['weakness']);
printf("<b>History/Comments:</b> %s\n<br>", $myrow['history']);
// single quotes marks array pointers
}
else
{
// show character list
$result = mysql_query("SELECT * FROM `cbd_darkhorse` ORDER BY 'company',`name` ASC", $db);


I'll have to add that && operator (changing the variable for each company) to each if statement in the script, but I think it should work.


I can't try it now, because I'm not at home and don't have ftp access, but I've been reading my php book and I think I found a way to fix that bug! :):):)

Also, on the closing out of the Superman link...

I can't close it out the way you're describing, because the code that draws that link is this:


echo "<a href='$PHP_SELF?id=" . $myrow['id'] . "'>" . $myrow['name'] . " \n<br /><br />";

Where would I put the kill tags? And why isn't anything else affected like this? They're all using the same code to create their perspective links.

And thanks for explaining that to me about all the if statements being true, because the character drawn has an id # now. Makes alot of sense to me now. And I think adding those && operators should fix it. Only problem I can see is people only entering partial company names when submitting bios. i.e. Putting DC instead of DC Comics, etc.

Zachery
10-13-2004, 01:24 PM
For starters, when you are writing things for vBulletin you should use templates
also, you never opend any php tags, yet you have php statments.

If you need abit of help with the basics of vB3 i suggest looking at this
http://www.vbulletin.org/forum/showthread.php?t=59939

NeroTheWarlord
10-13-2004, 03:12 PM
For starters, when you are writing things for vBulletin you should use templates
also, you never opend any php tags, yet you have php statments.

If you need abit of help with the basics of vB3 i suggest looking at this
http://www.vbulletin.org/forum/showthread.php?t=59939


That's only part of the script. The rest of it (with the php tags) is in the attachment.

And I'm trying to find a way to integrate it into vbulletin without having to set up a page for every single bio. As it is right now, it is using some templates, only because I haven't changed it back to the inline frame I was using.

Ghostsuit
10-13-2004, 03:37 PM
Ok why do you have a Company field in each table if each table is a Company?

Either you want just the one table with all the details and a company field or you want a Company table and a Comicbios table that link to each other.

You might want to take a look in the book/internet for "normalization" trust me when I started out designing databases I made these same mistakes but it's amazing how much it helps to understanding normalization.

Also why not pass the company name or company id at the same time as you pass the bio id. This way you really only need one statement that will create the bio for you and won't have to repeat it multiple times.

NeroTheWarlord
10-13-2004, 03:41 PM
Well when i first made it, I only had one table, which included all fields, and I listed them alphabetically by company, and then by name but I couldn't figure out how to seperate them and put each company name in there. I have more to post, but I gtg for a bit..

NeroTheWarlord
10-13-2004, 05:47 PM
Damn, that and operator didn't work.. just made things worse.. wouldn't pull up any bios. just refreshed the page.... GRRRRRR

NeroTheWarlord
10-13-2004, 07:09 PM
Ok, they're all back in one table now.. and the new script code I'm using to call for the list of bios is attached to this post.

You can view the page at:

http://www.neropolis.com/index.php?page=bios

Now, how can I seperate the characters that belong to different companies and insert the company name before each list of characters that fall under that company name? (like this)

DC Comics
Flash (III)
Green Lantern (Kyle Rayner)
Superman

Marvel Comics
Abomination
Captain America
Quasar

T.R.I.B.E Studios
A-1
A-10
A-11
A-12
A-13
A-14
A-2
A-3
A-4
A-5
A-6
A-7
A-8
A-9


That's why I originally changed it in the first place, so I could call for each table and list the companies seperately.

NeroTheWarlord
10-14-2004, 04:58 PM
Ok, I think I have a way to do it in this edited script, but I just need to find the correct variable for the company.

Right now, I'm using $myrow['company']

But unfortunately that doesn't seem to be the correct variable, so the statement shows up false every time.

Any ideas?

NeroTheWarlord
10-15-2004, 05:03 PM
Nevermind, got it all figured out, thanks to you guys and some people over at vb.org and phpBuilder.com.

Many thanks for your help it was very informative and appreciated.

Next step for me: Try to figure out how to integrate it into vbulletin. :D:D:D.. but that can wait 'till after I get back from my vacation. ;)