Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 1 of 1
  1. #1
    Junior Member weblebowski's Avatar
    Join Date
    Mar 2012
    Posts
    19
    Member #
    31067
    Liked
    1 times
    one thing i'm having trouble with now is outputting data to an html table. for instance, using the while loop seems to constrict me in terms of format of html table. for instance, as of now, html table shows up like this:



    it makes sense to me why this happens, but i obviously don't want the username to echo out 3 times, only once. i also want the games ($row['home_team']." ".$row['spread']." vs. ".$row['away_team']) to show up as headers across the top. i want my html table to display like so:



    Right now, code looks like this:

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>

    <style>

    body { font-family: Verdana, Arial, sans-serif; }

    table, th, tr, td { border-collapse: collapse; }
    .su_win { background-color: yellow; }
    .ats_win { background-color: #94d67a; }
    .loss { color: red; border-color: black; text-decoration: line-through; }

    </style>

    </head>

    <body>

    <?php

    //connects to Db
    $db_host "localhost";
    $db_username "root";
    $db_pass "";
    $db_name "pete_pool";

    @
    mysql_connect("$db_host","$db_username","$db_pass") or die("Could not connect to MySQL");
    @
    mysql_select_db("$db_name") or die("No database");

    $query =    "SELECT * FROM picks
        INNER JOIN schedules
            ON picks.game_id = schedules.game_id
        INNER JOIN players
            ON picks.user_id = players.user_id WHERE week=14"
    ;

    $result mysql_query($query) or die(mysql_error());

    echo 
    "<table border cellpadding=3>";
    echo 
    "<tr>";
    echo 
    "<th>User</th>";
    echo 
    "<th>Game</th>";
    echo 
    "<th>SU</th>";
    echo 
    "<th>ATS</th>";
    echo 
    "</tr>";

    while(
    $row mysql_fetch_array($result)){

    // display picks in html table
        
    echo "<tr><td>".$row['user_name']."</td> ";
        echo 
    "<td>".$row['home_team']." ".$row['spread']." vs. ".$row['away_team']." (".$row['ml_odds'].")</td> ";

    if (
    $row['su'] == $row['home_team']) {
        if (
    $row['home_score'] > $row['away_score']) {
            if(
    $row['su_grade'] == NULL) {
                
    mysql_query("UPDATE picks SET su_grade = 1 WHERE pick_id = ".$row['pick_id']);
            }
            echo 
    "<td class='su_win'>"// highlight su wins yellow
        
    } else {
            if(
    $row['su_grade'] == NULL) {
                
    mysql_query("UPDATE picks SET su_grade = 0 WHERE pick_id = ".$row['pick_id']);
            }
            echo 
    "<td class='loss'>"// strikethrough losses
        
    }
    } else if (
    $row['su'] == $row['away_team']) {
        if (
    $row['home_score'] < $row['away_score']) {
            if(
    $row['su_grade'] == NULL) {
                
    mysql_query("UPDATE picks SET su_grade = 1 WHERE pick_id = ".$row['pick_id']);
            }
            echo 
    "<td class='su_win'>";    // highlight su wins yellow
        
    } else {
            if(
    $row['su_grade'] == NULL) {
                
    mysql_query("UPDATE picks SET su_grade = 0 WHERE pick_id = ".$row['pick_id']);
            }
            echo 
    "<td class='loss'>"// strikethrough losses
        
    }
    }

        echo 
    $row['su']."</td> ";

    if (
    $row['ats'] == $row['home_team']) {
        if (
    $row['home_score'] + $row['spread'] > $row['away_score']) {
            if(
    $row['ats_grade'] == NULL) {
                
    mysql_query("UPDATE picks SET ats_grade = 1 WHERE pick_id = ".$row['pick_id']);
            }
            echo 
    "<td class='ats_win'>"// highlight ats wins green
        
    } else {
            if(
    $row['ats_grade'] == NULL) {
                
    mysql_query("UPDATE picks SET ats_grade = 0 WHERE pick_id = ".$row['pick_id']);
            }
            echo 
    "<td class='loss'>"// strikethrough losses
        
    }
    } else if (
    $row['ats'] == $row['away_team']) {
        if (
    $row['home_score'] + $row['spread'] < $row['away_score']) {
            if(
    $row['ats_grade'] == NULL) {
                
    mysql_query("UPDATE picks SET ats_grade = 1 WHERE pick_id = ".$row['pick_id']);
            }
            echo 
    "<td class='ats_win'>"// highlight ats wins green
        
    } else {
            if(
    $row['ats_grade'] == NULL) {
                
    mysql_query("UPDATE picks SET ats_grade = 0 WHERE pick_id = ".$row['pick_id']);
            }
            echo 
    "<td class='loss'>"// strikethrough losses
        
    }
    }

        echo 
    $row['ats']."</td></tr>";

    }

    echo 
    "</table>";

    ?>

    </body>
    </html>
    Any ideas?

  2.  


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:31 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com