Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Data from db to webpage using php

    ok i have 2 problems first one is when i pull up the page with this coding on it it comes up as a blank page no errors just blank

    2nd problem is i know this script wont make the name results alphabetical which is what i would like to do any input is greatly appreciated
    thank you in advance to any help you can give

    Code:
    <html>
    <head>
    <title> Email List</head>
    <style type="text/css">
    table {
           border: 2px solid red
           background-color: #ffc;
           }
    
    th {
          border-bottom: 5px solid#000;
          }
          
    td {
        border bottom: 2px solid #666;
        }
    </style>
    </head>
    <body>
    
    <h1> Email List </h1>
    
    <?php
    $dbcon = mysql_connect("localhost","dbs_dbs","password","dbs_forms") or die("Can not connect: " . mysql_error());
    $sqlget = "SELECT * From playersemails"
    $sqldata = mysql_query ($dbcon, $sqlget)or die("Can not connect: " . mysql_error());
    
    echo "<table>";
    echo "<tr><th>Players Name</th><th>Email address></th></tr>
    while($row = mysql_fetch_array($sqldata, MYSQL_ASSOC)) {
    
    echo "<tr><td>";
    echo $row[`playersname`];
    echo </td><td>
    echo $row[`email`];
    echo "</td></tr>;
    }
    echo "</table>";
    ?>
    </body>
    </html>

  • #2
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    upon looking more nline i got this code working now the issue is i need the results to be alphabetical
    Code:
    <html>
    
    
    
    <body>
    
    
    
    <?php
    
    
    
    $db = mysql_connect("localhost", "dbs_dbs","dbs4evr");
    
    
    
    mysql_select_db("dbs_forms",$db);
    
    
    
    $result = mysql_query("SELECT * FROM playersemails",$db);
    
    
    
    echo "<table border=1>";
    
    
    
    echo "<tr><td>Players Name</td><td>Email</tr>";
    
    
    
    while ($myrow = mysql_fetch_row($result)) {
    
    
    
    		printf("<tr><td>%s</td><td>%s</td></tr>",
    
    		$myrow[1], $myrow[2], $myrow[3]);
    
    
    
    }
    
    
    
    echo "</table>";
    
    
    
    ?>
    
    
    
    </body>
    
    
    
    
    
    </html>

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,340 Times in 4,306 Posts
    second problem is easy fix.

    Code:
    SELECT playersname, email FROM playersemails ORDER BY playersname
    I *think* first problem is easy fix, too.
    Look at the documentation:
    http://www.php.net/manual/en/function.mysql-query.php

    You have the order of your arguments to mysql_query backwards. The SQL is supposed to come first. And you can simply omit the connection.
    SO:
    Code:
    $sqldata = mysql_query($sqlget)or die("query failed: " . mysql_error());
    But do note that mysql_query is now obsolete, as that doc page tells you.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    sircubesalot (04-24-2013)

  • #4
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    is there a particular place i should put
    Code:
    SELECT playersname, email FROM playersemails ORDER BY playersname
    in the 2nd code

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,340 Times in 4,306 Posts
    Replace
    Code:
    $result = mysql_query("SELECT * FROM playersemails",$db);
    with
    Code:
    $sql = "SELECT playersname, email FROM playersemails ORDER BY playersname";
    $result = mysql_query( $sql,$db) or die( "query failed: " . mysql_error() );
    You don't have to put the query into a separate PHP variable, but it's a really good idea to do so; it can make later debugging much easier. And you should ALWAYS add the or die just in case.

    And you should always avoid using SELECT * unless you truly will need *ALL* the fields from the table. In this case, since you are only using two fields, you should definitely specify them in the SELECT. It can make a huge performance difference especially with big tables.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    That's simply a change to the query you had to specify an ORDER BY to make it alphabetical.
    Your first problem was parser error:
    PHP Code:
    $sqlget "SELECT * From playersemails" 
    You're missing a semi-colon. No error would have been displayed since the error_reporting is either set low, or display_errors directive is disabled.

    These are also errors:
    PHP Code:
    echo $row[`email`]; 
    PHP will attempt to execute a command line application called email (PHP is set by default to interpret accent grave as shortform system() piping).
    There are a few more places where you are missing quotes and semi-colons as well. You'll need to correct all of these before it would pass the parser.
    And that is why you're first one produced nothing but white output
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,340 Times in 4,306 Posts
    Ahhh...I didn't catch those were ` instead of ' !!!

    No wonder nothing worked!

    Well, as I keep saying, I don't code in PHP. (But I would have mentioned the wrong quoting if I'd noticed it.)
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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