Php/mysql Data Display

free web hosting
Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Php/mysql Data Display

derouge
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

 

 

 


Reply

Soleq
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.



Reply

derouge
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

 

 

 


Reply

jidun
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 .

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. printing mysql data in php with style - 84.04 hr back. (1)
Similar Topics

Keywords : php, mysql, data, display

  1. Hard Drive Data Recovery Review
    (4)
  2. What You Need Before You Can Create A Text-based Game..
    Using PHP, HTML and MySQL (2)
    Please comment and rate, after you finished reading! /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> OK.. Many people here want
    to create text based games. Many of you ask us here on the forums: "how to create a text-based
    game", or "can you do a text-based game for me".. I think you guys should try to learn some basics
    first, and then create one on your own.. Then you wont miss all the fun /wink.gif"
    style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /> I don't blame you guys..
    I think that everyone, o....
  3. Parse PHP And Display PHP Generated Output
    How do you display your php output? (8)
    I will start writing my php files soon and would want to know how to see my output file(what it
    looks like). I have installed apache and when i put in the address for it, it just shows me my
    coding. How can i display what i have actually done without having to use my hosting service. I want
    to test it first? A little confused on that.....
  4. Mysql Multiple Tables
    (1)
    It is good practice to use multiple tables to sort out big amounts of data. But once you do that it
    becomes increasingly hard to cross reference the tables. Mysql has a little beautiful command
    structure that they have added. You can select multiple tables within one sql query. Example of a
    basic sql query CODE $sql = "SELECT * FROM table WHERE row=1"; If you noticed
    that I selected all of the rows in the table. Normally you will try to not select the entire table
    from the database unless you absolutely want all of the table. I would recommend against....
  5. Any Website Provide Free Host Mysql Host?
    (4)
    any website provide free host mysql host? i need it because i am using 000webhost.com now but it
    only provide 2 mysql database... can i know where or how can i get more databases regards....
  6. How To: Display A Members/user List.
    With PHP, Mysql, and HTML. (3)
    Alright, some of you might want to display your User's or Members on your site. Notes: 1.This
    is to fit in with Feelay's register and Log-in scripts you can find in the tutorial section. 2.I
    made this to show the members of my site who is a member and what their ID is. First off, we must
    set up a connection to our MySQL Database. CODE <?php $con =
    mysql_connect("localhost","database_username","database_username_password
    4;); if (!$con)   {   die('Could not connect: ' .
    mysql_error(....
  7. Reading Xml Data
    Within PHP (2)
    So I was idly pondering my next PHP venture today - more on that if/when I get it done - when I
    realised I needed to be able to read some data in from files. Sure, I could use simple binary files
    (each line having the relevant data on it, etc. etc.), but I figured I'd might as well learn how
    to use this snazzy XML stuff I keep hearing about. So, after looking at W3Schools for a bit I
    couldn't find an obvious way of reading XML files in PHP . There was plenty of information of
    how to do it in JavaScript, but as I want to read the files in on the server rather th....
  8. Mysql On Computer
    XD (9)
    I posted PHP on computer? , but for some reason it doesn't show :/. Anyways I am wondering if
    there is MYSQL on my computer, meaning can i make a data base on my computer? that way i make what i
    want and upload it when i get hosted =)....
  9. Can You Link Game Maker With Mysql/php
    Title says it :D (0)
    Hello, I am new to this service and i think I am going to like it =). Anyway, my main question is
    can you link executable games made by gamemaker (i have pro) to a database? And can i use the php
    server i get here to transfer data to that game? If so i would appreciate a little help with it
    because I am new to both =). Also is there anyway to get a www.mywebsite.com via credits from
    astahost? Finally is there any group here that works with gamemaker? we might have small contests
    or so /tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /....
  10. Mysql Database Entry By Excel Sheets
    (2)
    Hello .. I would like to ask if i can use use Microsoft excel files in order to make entries to
    mysql database. Thanks....
  11. Mysql Database Management
    (1)
    Hi i am new, I have a problem in understanding the query decomposition in D-DB. Can anyone help me
    to understand the first question of the exercise 25.21 of Elmasri-Navath 4th edition? Consider the
    following relations: BOOKS (Book#, Primary_author, Topic, Total_stock, $price) BOOKSTORE
    (Store#, City, State, Zip, Inventory_value) STOCK (Store#, Book#, Qty) Consider a distributed
    database for a bookstore chain called National Books with 3 sites called EAST, MIDDLE, and WEST.
    Consider that BOOKS are fragmented by $price amounts into: B1:BOOK1:up to $20.....
  12. Mysql And User File_priv
    (0)
    HI, I've hit the grain while trying to import file to mysql database - I need to enable file
    permissions of the database user but this seems not possible with most of the hosting providers.
    The problem is to set file_priv of the database user to "Y" . This is done in the "user" table of
    the maintanance database named "mysql". cPanel doesn't allow this. Via the cPanel you can only
    allow privileges on table querries but you cannot grant host file privileges to the database user -
    which makes querries like: "LOAD DATA INFILE 'filename' INTO TABLE tablen....
  13. Mysql With My Own Server
    few questions (4)
    Hi, I've only just joined the forum Can you link the mysql database here to your own website?
    If so how would I go about it Thanks =D....
  14. Mysql Storage Engine Error 28
    (5)
    Hello, On my website and forum, SDeckNET, the mySQL database is not working. I get the error "mySQL
    error: Got error 28 from storage engine mySQL error code: Date: Wednesday 02nd 2008f July 2008
    05:33:53 AM" from my forum. From what I know, error 28 means I'm out of disk space, how can this
    be? I was never told of a mySQL space limitation and all these cases of downtime are destroying my
    site's memberbase. EDIT: It now seems PhpMyAdmin is down too, with the error: "Warning:
    session_write_close() : SQLite: session write query failed: database is full in /usr/l....
  15. I Have An Error With My Mysql Connection
    mysql connection error (7)
    ok so here's my web page... http://lacrossems.t35.org/ it only lags cause its trying to
    connect to the my sql server...i followed this guide
    http://forum.ragezone.com/showthread.php?t=387249 and when i edit my config.php to my host and
    login info i always get the error cannot connect to the database here is my config.php if you can
    help me CODE <?php $host['naam'] =
    'CENSORED';                // my host $host['gebruikersnaam'] =
    'righto';       // my database username $host['wach....
  16. Login System Using A Mysql Db
    How do i do this? (5)
    Hi guys, ive got a registration system that looks something like the one below: Firstname:
    Lastname: Then i have inset.php, which looks like the following: $con =
    mysql_connect("localhost","autobot","abc123"); if (!$con) { die('Could not connect:
    ' . mysql_error()); }mysql_select_db("my_db", $con);$sql="INSERT INTO person
    (username, password) VALUES ('$_POST ','$_POST ')";if
    (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record
    added";mysql_close....
  17. Data Recovery
    what should i use? (14)
    I sent a computer in for a motherboard replacement. I could have done it myself, but i figured why
    not save some time. The computer came back from the shop with not only the motherboard replaced, but
    the hard drive reformatted and windows reinstalled as well. After yelling at the guy for his
    stupidity, I've now settled down to try to recover the lost data. The problem with what i'm
    using (R-studio) is that it will recover a formatted partition, but because windows has been
    installed again on top it only sees that one. What are my chances of recovering the data, a....
  18. Qupis : Free Cpanel Web Hosting (one Line Text Ad At Bottom)
    150 MB space, 10000 MB Bandwidth, php, mysql, CPanel (9)
    Hello Members, We are proud to introduce a new member to Xisto group of sites.
    Qupis : Free Web Hosting 150 MB space, 5000 MB Bandwidth, php,
    mysql, CPanel (Latest). Emails, FTP, Addon domains, Parked Domains etc.
    http://www.Qupis.com
    Feel free to add your reviews and comments about it. -AstaHost
    Management ....
  19. Navcat For MySQL
    is Navcat any good? (8)
    Hello all, i ve recently come across NavCat (GUI tool) for MySQL. I have not bought a copy yet, just
    played around with the demo. Has any one used it beore, if so please let me know if its worth
    buying. I already have PhpMyadmin, Just wanna know if NavCat is better than PhpMyAdmin in usibility
    and functionality. Regards....
  20. PHP & MySQL: Displaying Content From A Given ID
    (6)
    Okay so I got this sample link (not working): http://www.acosta.com/joo.asp?id=654 Now suppose
    I have a PHP file that would use MySql in order to get all values in the row where id 654 is found.
    Here's a sample DB: Table: demnyc ______________________________________ | id |
    Name | Age | Email | *----------------------------------------------------* | 1
    | Albert | 17 | no email |
    *----------------------------------------------------* | 2 | YaPow | 888 |
    no email | |__________....
  21. Games For Samsung D900
    Install games with data cable (3)
    Hello everyone. I have a problem and perhaps you can help me out? I have a samsung d900 and I want
    to install games using a data cable. Does anyone know how to do it? Thanks in advance!....
  22. MySQL, Multiple Tables
    (24)
    Ok, I'm coding a project which is a leap than what I'd normally do. Before, I've always
    learned ONE table... put EVERYTHING in one database table. I'm making a profile system so there
    needs to be at least two tables: 1 for users, 1 for content. My problem is, how do I link the two
    together? I could probably figure this out faster if someone explained and posted sample SQL code
    that shows how the two are linked together. Thanks!! F....
  23. MySQL Output Database Question
    (18)
    I am new to MySql and have just created a database after using a script. My problem is not the
    script, but what it says about putting it into the output file. I cant figure out the right terms
    to put it in, I keep getting errors. I try using; SELECT*FROM 'database name' WHERE
    'location' but it isnt working. I'm lost with this stuff, I really am. Can someone
    please help me out?....
  24. [PHP + MySQL] Encrypting Data
    To protect the password of your DB, for example. (9)
    Hi! This is my 2nd code of PHP + MySQL. This code is VERY simple: it encript the data in the
    MySQL DB. Here we go! ------------------------------------------------------------------------
    CODE <?php $password = "abc"; $new_password = md5($password);
    echo $new_password; ?> The password "abc" was codfied using md5() This will be:
    900150983cd24fb0d6963f7d28e17f72 CODE <?php $normal_pass = "abc";
    $encripted_pass = "900150983cd24fb0d6963f7d28e17f72"; if(md5($norm....
  25. Need Help With A PHP - MySQL Registration Script
    Wont INSERT into the database (13)
    hey well can some one helpme make this code work it won't INSERT INTO THE DATABSE CODE
    <?php # register1.php # common include file to MySQL include("DB.PHP");
    $Username=$_POST['Username'];
    $Password=$_POST['Password'];
    $Name=$_POST['Name']; $Last=$_POST['Last'];
    $Sex=$_POST['Sex']; $Month=$_POST['Month'];
    $Day=$_POST['Day']; $Year=$_POST['Year&....
  26. Convert Fat32 To Ntfs Without Data Loss (dos-mode)
    (5)
    Some computer's are sold with windows XP pre installed and with FAT32 FORMAT, so there is a way
    to change it without data loss. Go do MS-DOS and type convert c: /fs:ntfs, dont forget to change
    the drive c:\, d:\ , e:\ for the one that you wanna convert . PS : This process
    is impossible to return to FAT32, once you convert you can't turn back , unless you format your
    pc /biggrin.gif' border='0' style='vertical-align:middle' alt='biggrin.gif' /> cheers
    m8's /biggrin.gif' border='0' style='vertical-align:middle' alt='biggrin.gif'....
  27. Disable Display Properties Tabs
    (3)
    How to disable Display Properties Tabs for security purpose? 1) Run registery editor, for this,
    type regedit in Run dialog box from start menu. 2) Find following address: HKEY-CURRENT-USER \
    Software \ Microsoft \ Windows \ CurrentVersion \ Policies \ System
    3)Create a new DWORD (value of 1) and : 3-1) to disable ScreenSaver tab name it NoDispScrSavPage
    3-2) to disable Desktop tab name it NoDispBackgroundPage 3-3) to disable Themes tab name it
    NoThemesTab 3-4) to disable Setting tab name it NoDispSettingsPage 3-5) to dsable Appearance and T....
  28. Bash Script To Display Your Ip
    Script to display your ip (9)
    If your behind a router , and like me too lazy to open a browser and find a site that displays your
    ip , heres a simple Bash script (Bash is a shell in linux, main shell in Slackware Linux) Open a
    text editor , copy and paste the following: CODE #! /bin/bash exip=`lynx -dump
    http://www.whatismyip.com | head -n 2` echo "$exip" Save the txt ( for the
    sake of agrument we will refer the file as ip.sh) From console type: chmod a+x ip.sh Now run the
    script like so: ./ip.sh (which will display something like the following) ....
  29. Recover Tables From A MySQL .frm File
    (8)
    I have a couple of .frm files with no corresponding data or index files. Is it possible to recover
    the table structure (field names, types, sizes, rows,col, etc) from these files? The table type is
    innodb....
  30. MySQL - Trouble With Bulk Insert Statements
    (3)
    I'm trying to insert about 500 rows into mysql, but I keep getting errors. If I copy and paste
    too many (about 50) insert statements at a time I get errors sometimes. I sometimes even get errors
    but then the row is skipped so I don't know there was an error (I'm using linux and SSH).
    What's the best way to get my insert statements to put the data in MySQL? Is there anyway that I
    can have it tell me if there where any errors all the statements are executed? Thanks for your
    help.....

    1. Looking for php, mysql, data, display

Searching Video's for php, mysql, data, display
advertisement




Php/mysql Data Display



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE