Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Php/mysql Data Display
derouge
post Sep 18 2005, 03:56 PM
Post #1


Advanced Member
Group Icon

Group: Members
Posts: 111
Joined: 26-August 05
Member No.: 8,098



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:

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


When queried it displays the following:

CODE
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:

CODE
$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. wink.gif

Go to the top of the page
 
+Quote Post
Soleq
post Sep 18 2005, 04:24 PM
Post #2


Advanced Member
Group Icon

Group: Members
Posts: 145
Joined: 4-December 04
From: California
Member No.: 1,608



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 1

if Type 2 != null

Display ", Type 2"

end if

display ]

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.


Go to the top of the page
 
+Quote Post
derouge
post Sep 23 2005, 10:55 PM
Post #3


Advanced Member
Group Icon

Group: Members
Posts: 111
Joined: 26-August 05
Member No.: 8,098



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! smile.gif

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! smile.gif
Go to the top of the page
 
+Quote Post
jidun
post Nov 13 2005, 09:03 AM
Post #4


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 1
Joined: 13-November 05
Member No.: 9,596



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 smile.gif .
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. IE6 display:block hides other image BUG(1)
  2. MySQL Realtime Replication(4)
  3. Recover Tables From A MySQL .frm File(8)
  4. New Nvidia Display Driver Was Released On 1/6(2)
  5. Disable Display Properties Tabs(3)
  6. Convert Fat32 To Ntfs Without Data Loss (dos-mode)(8)
  7. [PHP + MySQL] Encrypting Data(11)
  8. MySQL For EasyPHP Users(5)
  9. MySQL Output Database Question(18)
  10. Important: Basics Of Using PHP And MySQL(10)
  11. CuteNews: PHP-based Blog System - No MySQL(11)
  12. Games For Samsung D900(3)
  13. PHP & MySQL: Displaying Content From A Given ID(6)
  14. Navcat For MySQL(9)
  15. Qupis : Free Cpanel Web Hosting (one Line Text Ad At Bottom)(10)
  1. Ajax + Php + Sql = Simply Superb! ( With Visitor Tracking )(11)
  2. Data Recovery(15)
  3. Php Tutorial: Making A Shoutbox(12)
  4. Skydrive(9)
  5. How To: Display A Members/user List.(3)
  6. Any Website Provide Free Host Mysql Host?(4)
  7. Parse PHP And Display PHP Generated Output(8)
  8. What You Need Before You Can Create A Text-based Game..(7)
  9. Hard Drive Data Recovery Review(7)
  10. Mysql Overhead(3)
  11. Which Language Is Easy And Secure Today For Web Development(2)
  12. Login System(6)
  13. Small Issues About Mysql Connector/j 5.1(2)


 



- Lo-Fi Version Time is now: 22nd November 2008 - 04:48 PM