Jump to content
xisto Community
Sign in to follow this  
derouge

Php/mysql Data Display

Recommended Posts

Okay .. got a bit of a question here, so I'll do some explaining.

 

I was asked to do a site for an online roleplaying game, specifically, a "blackbook" site. I accepted and began my quest for knowledge of PHP. I've gotten quite "far" to the point that I can now take a user inputted search value and query the database with that value, and then display the values in a table.

 

My MySQL table setup is as below:

 

|Name|Reports|Type1|Type2|Quote|Confirmed|

When queried it displays the following:

 

Violator Name: ['Name']# Reports: ['Reports']Offense(s): ['Type1, Type2']Quote: ['Quote']Confirmed?: ['Confirmed']

Now the problem area is the "Offense(s):" row. I can get it to output the various offenses, but they're all stuck in one string, with nothing seperating them so it looks like crap. What I want to happen is for Type1 to be displayed, the a comma, and then Type2. But, I also need it so that the comma is only displayed if there is a Type2 value. How?

 

I'll put the code below that relates to displaying the date:

 

$search = mysql_query( "SELECT ID, VioName, ReportNum, TypeOne, TypeTwo, TypeThree, TypeFour, QuoOne, QuoTwo, Confirmed FROM `blist` WHERE VioName LIKE '$name' LIMIT 0, 30 ");print ("<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2>\n");if ($output = mysql_fetch_array($search)) {	print "<TR>\n";  print "<TD><B>Name</B>: </TD><TD>".$output['VioName']."</TD>\n";	print "</TR>\n";	print "<TR>\n";  print "<TD WIDTH=60><B>Reports</B>: </TD><TD>".$output['ReportNum']."</TD>\n";	print "</TR>\n";	print "<TR>\n";	print "<TD><B>Offense(s)</B>:</TD><TD>".$output['TypeOne']."</TD>";        print "<TD>,".$output['TypeTwo']."</TD>";        print "<TD>,".$output['TypeThree']."".$output['TypeFour']."</TD>\n";	print "</TR>\n";	print "<TR>\n";  print "<TD><B>Quote</B>: </TD><TD>".$output['QuoOne']."</TD>\n";	print "</TR>\n";	print "<TR>\n";  print "<TD><B>Quote</B>: </TD><TD>".$output['QuoTwo']."</TD>\n";	print "</TR>\n";        print "<TR>\n";                print "<TD><B>Confirmed? </B></TD><TD>"."</TD>\n";        print "</TR>\n";}else {print "Player '$name' not found in the blacklist. Please check your spelling and search again. Or, if you feel this is an error please report it at the Error Report form.";}print ( "</TABLE>\n" );

So yeah, gah! Any help is appreciated, even if it doesn't directly relate to my question. As you can probably tell from above I'm a newb to PHP. B)

Share this post


Link to post
Share on other sites

I've run into this before, and fortunately, it's just a formatting problem (not semantic). You need to do a check to see how many offenses there really are. The easist way to do this (given your structure), is to set both types of offenses as 'null' when a new row is created. Then, when you're displaying the data, you check to see if Type 2 is null. This is going to be in a standard if statement. If the type 2 is not null (i.e. something's there), then you display a comma and Type 2. If it's null (nothing there), you skip that part and end the line.display "Offenses:" [Type 1if Type 2 != nullDisplay ", Type 2"end ifdisplay ]The main problem will be if there's more than 2 offenses. You only have it set up for 2 right now, but you can just keep adding records for more offenses if needbe.

Share this post


Link to post
Share on other sites

Thought I'd give you a little update, and ask a new question.

 

First off, the script worked perfectly. Extremely simple but it makes all the difference. Thanks! B)

 

Second, my question. I have a "bug report" page set up where users can report errors they find. They fill out a little form, click send, and the script adds what they put in the forms into a database. Now, the question - is this gonna do anything, err, 'bad' to my site? I was worried that maybe somehow a user could abuse this in some form to screw up my database. On that note .. another question:

 

How would I limit how many reports per day could be made from an IP? This way I could prevent some jerk from overloading the table with 800 reports, and in the process save me and my staff a major headache. A sorta outline of what I figure I need is below:

 

Every time a user sends a report I need to record their IP, and then each time after that I need to update their total reports sent. If a user hits a certain number I'll need to alert them that they can no longer send reports. I then need to block this IP from sending reports. After 24 hours I need ALL the IPs to be cleared and reset to zero, thus allowing another fun filled day of bug reporting.

 

I'm sure it's possible, but if someone could point me in the direction of some commands to use, and if it would be something I'd have to do through PHP, or if there is a way to rig up a MySQL database to limit entries from certain IPs.

 

Thanks in advance! :P

Share this post


Link to post
Share on other sites

One solution for this situation might be to make sure you set a cookie for your user when/while they are logged in to your site, then make the PHP check for an authentic user cookie before passing info to the database (this should sift out form searching DOS attack bots) and check for the existence of form already used cookie, then pass form already used cookie 24 hr expire after form is inputted, which lets the script check to see if this user has already entered info in it and redirect them to another page explaing only one per day, or whatever. This should eliminate the need to ban and make the form relatively secure ;) .

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.