CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: MYSQL table row styling

  1. #1
    Join Date
    Feb 2015
    Posts
    1

    MYSQL table row styling

    I am brand new to php, MySQL, coding, etc and I am in serious need of some help you the wise ones on this site. I have the following code and I am trying to style it, IE make it look pretty with some css or something. The problem is I have no idea how to do it and all attempts so far to figure it out on my own have failed.


    Code:
    // display data in table
    						        echo "<table border='1' cellpadding='10'>";
    						        echo "<tr> <th>ID</th> <th>First Name</th><th>Middle Name</th> <th>Last Name</th><th>Client ID</th><th>Diagnosis</th><th>Gender</th><th>Level of Care</th><th>Counselor</th><th>Active</th><th>Aftercare</th></tr>";
    						
    						        // loop through results of database query, displaying them in the table 
    						        for ($i = $start; $i < $end; $i++)
    						        {
    						        	// make sure that PHP doesn't try to show results that don't exist
    					                if ($i == $total_results) { break; }
    					                
    						        	// find specific row
    						        	$result->data_seek($i);
       	 								$row = $result->fetch_row();
       	 								
       	 								// echo out the contents of each row into a table
    					                echo "<tr>";
    					                echo '<td>' . $row[0] . '</td>';
    					                echo '<td>' . $row[3] . '</td>';
    					                echo '<td>' . $row[1] . '</td>';
    					                echo '<td>' . $row[2] . '</td>';
    					                echo '<td>' . $row[4] . '</td>';
    					                echo '<td>' . $row[5] . '</td>';
    					                echo '<td>' . $row[6] . '</td>';
    					                echo '<td>' . $row[7] . '</td>';
    					                echo '<td>' . $row[8] . '</td>';
    									echo '<td>' . $row[12] . '</td>';
    									echo '<td>' . $row[15] . '</td>';
    									echo '<td><a href="records.php?id=' . $row[0] . '">Edit</a></td>';
    					                echo '<td><a href="delete.php?id=' . $row[0] . '">Delete</a></td>';
    					                echo "</tr>";
    						        }
    
    						        // close table>
    						        echo "</table>";]
    Last edited by PeejAvery; March 14th, 2015 at 09:17 PM. Reason: Fixed the code tags

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,943

    Re: MYSQL table row styling

    First off, you should use echo as little as possible. Just echo your actual variables. That will make your code much cleaner.

    Second, what kind of styling are you trying to achieve? It's just outputting a table. Any CSS can be applied.

    Third, your loop statment is really bad PHP. You should almost never have to prematurely break a database query unless you've done the query wrong.
    Last edited by PeejAvery; March 14th, 2015 at 09:22 PM.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,943

    Re: MYSQL table row styling

    Here's an example of how much cleaner/simpler/efficient your code could be...

    PHP Code:
    <table cellpadding="10" cellspacing="1" border="0">
      <tr>
        <th>First</th>    
        <th>Middle</th>
        <th>Last</th>
      </tr>
    <?php
    $start 
    0;
    $numberOfRows 50;

    $query "SELECT * FROM clients LIMIT $start$numberOfRows";

    if (
    $result $mysqli->query($query)) {
      while (
    $row $result->fetch_object()) {
    ?>
      <tr>
        <td><?php echo $row->firstName?></td>
        <td><?php echo $row->middleName?></td>
        <td><?php echo $row->lastName?></td>
      </tr>
    <?php
      
    }
    }
    ?>
    </table>
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)