Results 1 to 9 of 9

Thread: Need help with PHP and Mysql coding.

  1. #1
    Join Date
    Aug 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Need help with PHP and Mysql coding.

    I am making a GM system where i can monitor activity from website so i dont have to log the Host server to check things.


    Ok so heres where im having some issue, I want to pull mysql info from the server and display that information in either a text box or a neater system much like this : Click image for larger version. 

Name:	WVb12n2.jpg 
Views:	162 
Size:	14.6 KB 
ID:	5856 and i have made many systems such as our login system and so on yes the login systems password is MD5 then salted so no need to worry there . Now the way i see the data is here : Click image for larger version. 

Name:	EzH8p0A.jpg 
Views:	182 
Size:	6.6 KB 
ID:	5857 , i want to Add text to where the values are being posted but dont know how to do that with the current code im using which i got from this website : http://www.homeandlearn.co.uk/php/php13p2.html




    Heres the code i used , its the same as on the websites only my values.

    Code:
    <?PHP
    
    $user_name = "root";
    $password = "xxxxxxxxxx";
    $database = "log_gmoperator";
    $server = "127.0.0.1";
    
    $db_handle = mysql_connect($server, $user_name, $password);
    $db_found = mysql_select_db($database, $db_handle);
    
    if ($db_found) {
    
    $SQL = "SELECT * FROM log_gmoperator";
    $result = mysql_query($SQL);
    
    while ( $db_field = mysql_fetch_assoc($result) ) {
    
    print $db_field['dwGmID'] . "<BR>";
    print $db_field['szCommand'] . "<BR>";
    print $db_field['bSuccess'] . "<BR>";
    print $db_field['time'] . "<BR>";
    
    }
    
    mysql_close($db_handle);
    
    }
    else {
    
    print "Database NOT Found ";
    mysql_close($db_handle);
    
    }
    
    ?>

    Any ideas from all you coder junkies???
    Last edited by Beverleyh; 03-17-2016 at 06:19 AM. Reason: Formatting

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    To structure your output like the first image, you would need to echo/print HTML markup to the page, along with the actual data variables. You currently only have <br> tags, which is why there is no neat layout, but if you were to build up a table around your data variables, it would look much neater.

    Your next request needs further clarification. You say you want to add text but do you mean that you want to add text to the page by pulling in data that already exists in the database? OR, do you mean that you want to add data to the database via a form (textarea and submit button) on the web page? Where and how do you want to add?

    If you clarify your requirement our members will be able to better assess how/whether they can help you.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Aug 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Your kidding me right??? why would i want to add data to the database when its a log sql file that is being logged from our server besides i know how to input data from php.


    As i stated above i want to pull the sql data then display that data in Neat text boxes such as a form , each form section will have their own identification such as ID , Command , Success , Time.


    And Its not my code as i posted the original link to the post i got the code from, Im not trying to sound rude or anything but , did you even understand what i meant?

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Quote Originally Posted by Zdeamon View Post
    Your kidding me right??? why would i want to add data to the database when its a log sql file that is being logged from our server besides i know how to input data from php.
    There's no need to get defensive. It's extremely unclear what you want.

    Quote Originally Posted by Zdeamon View Post
    As i stated above i want to pull the sql data then display that data in Neat text boxes such as a form , each form section will have their own identification such as ID , Command , Success , Time.
    In what context do you want to do this? In your original post, you made it seem like you wanted your output as depicted in the table-formatted image. If you just want to put the queried data in input fields, you can adjust your output. For example:

    Code:
    print "<input type='text' value='" . $db_field['dwGmID'] . "'>";
    If that's not what you want, you need to make it more clear. I don't know what you're trying to communicate.
    Jeremy | jfein.net

  5. #5
    Join Date
    Aug 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry about that , i didnt mean to make you guys assume i was being defensive as thats not the cause at all , my goal is to see about having the data displayed in a form like environment that would auto populate without having to manually add the form as you see in firat image as i had to create that manually then added the info , now the reason i want to do this is cause i am also makeing a online item mall with the same script so users can see it from our website. Sorry for going off tho , havent had much luck with things these days.

  6. #6
    Join Date
    Aug 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok so i have bean playing around with the code quite a bit and thank you Nile for your code. im getting closer to what i need. So i made the page smaller and i see exactly the format i need but need the boxes to be wider for the text.

    http://i.imgur.com/p9qiKAr.png

    I need the page to display as it is on the link but only displays like that when you make the page smaller , This is what i have bean asking but don't know how to correctly ask for it.

    And i actually don't want users to be able to delete the text in the boxes so if there is away to make a table view exactly like this , it would be exactly what i needed.

    The text forms are a good idea and i like it , however i just need the data that's being pulled from mysql into a table view with the ability to add text in the column's that the data is being displayed in so i can help our staff members understand what each column is.

    <?PHP


    $user_name = "root";
    $password = "xxxxxxxxx";
    $database = "Inxxxxxxx Pxx";
    $server = "127.0.0.1";

    $db_handle = mysql_connect($server, $user_name, $password);
    $db_found = mysql_select_db($database, $db_handle);

    if ($db_found) {

    $SQL = "SELECT * FROM log_gmoperator";
    $result = mysql_query($SQL);

    while ( $db_field = mysql_fetch_assoc($result) ) {

    print "<input type='text' value='GMID - " . $db_field['dwGmID'] . "'>";
    print "<input type='text' value='Command- " . $db_field['szCommand'] . "'>";
    print "<input type='text' value='Suceeded-" . $db_field['bSuccess'] . "'>";
    print "<input type='text' value='Time-" . $db_field['time'] . "'>";

    }

    mysql_close($db_handle);

    }
    else {

    print "Database NOT Found ";
    mysql_close($db_handle);

    }

    ?>
    Last edited by Zdeamon; 03-19-2016 at 02:46 AM. Reason: Added more details again...

  7. #7
    Join Date
    Aug 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok i was able to solve my problem , i had the wrong MySQL type and should of used MySQLI.


    Heres my final Result http://69.64.52.65/test/GM-OP-Log.php

    I would like to thank you guys for trying to help me , I didn't think about having to use MySQLI for this.

    W3Schools.com version of this code : http://www.w3schools.com/php/showphp...elect_oo_table

    IF you get to this post and my link for the test page doesn't work here's the code that i found on W3Schools but my version

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <style>
    table, th, td {
         border: 1px solid black;
    }
    </style>
    </head>
    <body>
    
    <?php
    $servername = "127.0.0.1";
    $username = "root";
    $password = "Input your Mysql Password here";
    $dbname = "Input your Database Name here";
    
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
         die("Connection failed: " . $conn->connect_error);
    }
    
    $sql = "SELECT dwGmID, szCommand, bSuccess, time FROM log_gmoperator";
    $result = $conn->query($sql);
    
    if ($result->num_rows > 0) {
         echo "<table><tr><th>GM ID</th><th>Command</th><th>Succeeded</th><th>Time<tr>";
         // output data of each row
         while($row = $result->fetch_assoc()) {
             echo "<tr><td>" . $row["dwGmID"]. "</td><td>" . $row["szCommand"]. "</td><td>" . $row["bSuccess"]. "</td><td>" . $row["time"]. "</td></tr>";
         }
         echo "</table>";
    } else {
         echo "0 results";
    }
    
    $conn->close();
    ?> 
    
    </body>
    </html>

  8. #8
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default

    Im not entirely sure if your ids are in order but if not add this to the end
    ORDER BY dwGmID ASC

    Also, If i may suggest adding a few things (not sure if you plan to link database table) but try something like this:

    First, change the table name to something like this tbl_GmOperatorLog

    Code:
    SELECT
      gol.dwGmID, gol.szCommand, gol.bSuccess, gol.time
    FROM tbl_GmOperatorLog gol
    ORDER BY gol.dwGmID
    However, I think you can just call it this way
    Code:
    SELECT
      gol.*
    FROM tbl_GmOperatorLog glo
    ORDER BY gol.dwGmID
    This is assuming that the ID column is called dwGmID
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  9. #9
    Join Date
    Aug 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Actually it is in order , we have more than one GM on the server so if i use a command then they use one it will log in that order.


    what you see there is exactly how it shows in the database.

Similar Threads

  1. Statistic / analysis mysql coding
    By haniey_pisces in forum MySQL and other databases
    Replies: 1
    Last Post: 04-01-2012, 03:50 AM
  2. Replies: 0
    Last Post: 01-04-2011, 01:17 PM
  3. Replies: 1
    Last Post: 10-20-2010, 06:18 AM
  4. Replies: 1
    Last Post: 12-27-2009, 01:12 AM
  5. Replies: 0
    Last Post: 03-07-2009, 07:27 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •