Nov 8, 2009

Php/mysql Data Display

free web hosting
Open Discussion & 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

 

 

 


Comment/Reply (w/o sign-up)

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.



Comment/Reply (w/o sign-up)

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

 

 

 


Comment/Reply (w/o sign-up)

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 .

Comment/Reply (w/o sign-up)


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*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Phpmysql Data Display

  1. [PHP + MySQL] Encrypting Data - To protect the password of your DB, for example. (13)
    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
    $password = "abc"; $new_password = md5($password); echo $new_password; ?> The password "abc"
    was codfied using md5() This will be: 900150983cd24fb0d6963f7d28e17f72 CODE $normal_pass =
    "abc"; $encripted_pass = "900150983cd24fb0d6963f7d28e17f72"; if(md5($normal_pass) ==
    $encripted_pass)   echo "Login Sucessful!"; else   echo "Incorrect password."; ?> This c...
  2. Reading Xml Data - Within PHP (2)
  3. Letting Users Add Mysql Data With Php - (1)
    I'm curious as to the best methods of letting users submit data to a MySQL database, displaying
    that data, and removing any unwanted tags etc. from it. Currently, there's a handful of PHP
    functions that I know of to help with this: mysql_real_escape_string() - perhaps the best known
    and most commonly used function, it should be used in pretty much any MySQL query. It escapes
    characters that have SQL significance. QUOTE(php.net) ...which prepends backslashes to the
    following characters: \x00, \n, \r, \, ', " and \x1a I like to think I made a pretty...
  4. Php, Sql Lite: Storing Session's Data? - how so store session in SQLITE? (1)
    normally, in windows, session data is saved in the location as directed by the "session.save_path"
    directives. they only show how to store session data in file. is it possible to store it inside the
    SQLite? anyone?...
  5. Getting Certain Parts Of A Record - The character data (17)
    Ok I need help on this puzzling problem. At first I thought that this person stored the dates in the
    MySQL database like this: August 27, 2007 That kinda freaked me out a little, because string dates
    are hard to manipulate. Then I found out that he stored both th string data and numerical date,
    which I found a little bit odd, but it was like this: 2007-08-27 I need to build a PHP program to
    manipulate the data, but I need to access the year, month and day respectively by themselves. I
    think that isolating the first 4 characters for the year, last 2 characters for da...
  6. Sql Injection Prevention (passing Numerical Data Across Pages). - PHP/mySQL (9)
    Even if your building something as simple as a basic news page for your website, if your passing
    along url variable strings like (mysite/index.php?page=1), you may be vulnerable to SQL injection
    attacks. For cases like these (passing numerical data in url strings), I have a handy dandy little
    function to thwart these attempts silly: CODE // For checking if value is a number, if not
    return 1. function isNum($val) {   if (!is_numeric($val)) { $val = 1; }   return ($val); } I
    have this function, within my functions.php file, which I use as an include in files w...
  7. Retrieving Data And Displaying In Boxes - How do I make a grid of boxes? (6)
    I have successfully setup a MySQL Database with a few tables in it to store user input! /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> /biggrin.gif"
    style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> Woohoo! Now the problem is
    displaying the data. I want 4 boxes echoing across with 3 rows down so that makes 12 boxes (12 of
    the most recent records). I have no clue how to do this because I cannot use the W3Schools example
    of echoing into a table. Here is the code I used but it echoes the same information across th...
  8. Proper Way To Grab User Data? - (1)
    I'm working on a script where there is a custom user profile and I was wondering if there was a
    more efficient way to grab data stored in a database than this method: CODE $sql = "SELECT *
    FROM users WHERE `access_name` = \""  .$active_user. "\""; $row =
    mysql_fetch_array(mysql_query($sql)); //Link the two tables together; grab the most common thing
    that is the *SAME* $user_id = $row ; $sql2 = "SELECT * FROM content WHERE `cid` = \""  .$user_id.
    "\""; $row2 = mysql_fetch_array(mysql_query($sql2)); Then on the pages, I just do a where ever
    something is supp...
  9. Data Passing - Re An Assignment For School - Please Help :) - (8)
    I'm working on a small assignment due tomorrow and am having some trouble. I have a functioning
    form that you input the data on one php page, and then it does a little math and displays the result
    on a new page. The assignment is to make this work on ONE page, and to add some error handling.
    I'm having trouble with the basics of passing the data that has been input on the form, back to
    itself. I am stuck with a few questions but I'll start with one. I have the data passing back
    to itself so that when I start the error checking, the fields won't have ...
  10. Send XML Data To PHP Page - (0)
    Hi, i'm trying to send my xml file "xmlDoc" to a php page so I can save it. Does anyone have the
    code for this?...
  11. Need An Alternative To $http_post_data For PHP4 - (5)
    Hi, my client's host site currently hosts just 4.0. I tried using the
    file_get_contents("php://input") and $HTTML_post_data php file to save the XML file from Flash but
    when loaded, it returns nothing. I need hlep...
  12. Storing Data Into Xml With A Php Form - Need Help! (2)
    Hi, I just learned how to read an xml file with PHP. The problem now is that I don't know how to
    write onto it. I would like to read my news content and be able to add more to it when another story
    comes up but I don't know how to write into the xml via PHP. All I know how to do is to edit the
    XML file itself manually. Can anyone help me?...
  13. Reading Data From Sessions - (2)
    Hello everyone! Before I start let me just say that ive read many threads on here about php and
    sessions, several tutorials and the php manual but I still cant find a solution to my problem. My
    problem is that when i try to read data from a session it just comes up blank, and an if statement
    to see if the variable is null returns true. The code im using is for a login script which checks
    the input from a user and compares it with the data in a database to log the user in, this works
    fine, also reading the data from the session works perfectly on the page which the sess...
  14. Display Text If Line Not Empty In Config File - (8)
    I have been working on a new template and I would like it so that if in the global configuration
    file, I have a variable for a global site announcement that would go on every page. The line in the
    global configuration file is this: CODE $announcement = "ANNOUNCEMENT"; In my template file,
    I could easily add CODE but that would leave a blank space and with the announcement style
    (similar to the Invision Power Board error box). Is there some sort of script that could be put in
    the template page so I could have the global config file look something like t...
  15. Possible To Do? - Reading a remote website's data .. (7)
    What I need to know is how to do the following? I'm completely confused, although I sort of
    have a general feel of what I need to do, I just have no clue how to do it. I need to be able to
    take some data from one page, displayed on their site as an HTML table, and then output certain
    pieces of it to my site. I will disclaim here and now that what I intend to do does not violate
    any laws, as I'm not stealing a persons content. I am using this to act as an online counter, to
    see how long someone is online. I also have emailed the company to ask if what I'm...
  16. I Need Help - php display (2)
    this is the original script i made CODE # include file include ("connect.php");
    $db=mysql_select_db(unknow,$connection); $sql="SELECT id, Game_name, Game_link, Game_image
    ,Game_from   FROM `Games` ORDER BY id"; $mysql_result=mysql_query($sql);
    $num_rows=mysql_num_rows($mysql_result); if ( $num_rows == 0) { echo "Sorry there is no information
    in that database please come back later"; } else { # we have result #create table WHILE
    ($row=mysql_fetch_array($mysql_result)) {  $id=$row ;  $Game_name=$row ;  $Game_link=$row ;
     $Game_image=$row ;  echo " "; ...
  17. Displaying Data From Mysql? - (2)
    how can i display data from mysql with php, just that on one page i want to display only the first
    10 things and the next page the next 20 ...etc.. how can i do that?...
  18. Help With Multi Tier Mysql Application Over Net - receiving data connection from client (6)
    hi.. i want to make a connection from my desktop client into mysql database at web server.
    currently i think it can be provided by PHP. 1. i'm thinking like this: CLIENT -> PHP + MYSQL
    CLIENT {sent file} -> PHP {receive file, open connection to MYSQL, insert data from file} how it
    will be done ??? 2. the security do you know how to secure it ? thanks.....
  19. In Php, How To Not Display Mysql Connection Error? - Don't want mysql_connect() message (4)
    In PHP, if the mysql database server cannot be connected, for example database server is handed or
    turned off, an error message will be displayed: Warning: mysql_connect(): Unknown MySQL Server Host
    "mysql.example.com" ... My question is how to not display this warning message? or can I customise
    the error message? if so, how? Thank you....



Looking for php, mysql, data, display

See Also,

*SIMILAR VIDEOS*
Searching Video's for php, mysql, data, display
advertisement



Php/mysql Data Display

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com