www.webdeveloper.com
Results 1 to 7 of 7

Thread: [RESOLVED] Help with altering tabular layout

  1. #1
    Join Date
    Jun 2014
    Posts
    4

    resolved [RESOLVED] Help with altering tabular layout

    I help with running a hobby web site and need to alter a simple tabular layout, but know nothing about PHP.

    This is an image of the present tabular layout:
    i935.photobucket.com/albums/ad197/meridklt/tabular_zps31ebe1e7.jpg

    I need to have the last time and date field moved to the second field with all the other fields staying in the same order as they are. Whilst I can do the html part at the top of the code below, I'm lost with the PHP part.



    <table border="1"><tr><td>&nbsp;</td><td width="60">V Code</td><td width="70">Member</td><td>Name</td><td>Ring</td>
    <td width="70">Time</td><td width="40">Race</td><td width="40">&nbsp;</td><td width="170">Created</td></tr>


    <?php
    $row_template = '<tr><td class="check_selector"><input type="checkbox" name="recordid_%s" /></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%02d:%02d:%02d %02d/%02d/%4d</td></tr>';
    /*
    * Fetch matching data from database
    */
    while ($row = $db->db_getRowAsArray()) {
    /*
    * Extract date and time data from created field
    */
    list($c_year,
    $c_month,
    $c_day,
    $c_hour,
    $c_minute,
    $c_second) = sscanf($db->db_desanitize($row['created']), '%d-%d-%d %d:%d:%d');
    printf($row_template, $db->db_desanitize($row['id']),
    code_initial_value+$db->db_desanitize($row['id']),
    $db->db_desanitize($row['member_id']),
    $db->db_desanitize($row['name']),
    $db->db_desanitize($row['ring']),
    $db->db_desanitize($row['time']),
    $db->db_desanitize($row['w_mark']),
    $db->db_desanitize($row['ob_yb']),
    $c_hour, $c_minute, $c_second, $c_day, $c_month, $c_year);
    }
    ?>
    </table>

  2. #2

  3. #3
    Join Date
    Jun 2014
    Posts
    4
    Thank you for replying mike, but as I said in my Post I know nothing about PHP. However, this morning I have had a reply to an email address I was given and sent out last night and the chap has kindly edited the code for me and it now works just as I wanted.

  4. #4
    Join Date
    May 2014
    Posts
    915
    Don't know what your $db is, but it doesn't seem to be PDO or mySQLi...

    But really it might help if you had semantic markup, formatted markup, properly constructed tables, got rid of the attributes like BORDER that have no place in any code written after 1997, used htmlspecialchars instead of some stupid method on your $db object, got rid of the scanf date reformatting nonsense, and stopped using the painfully slow and often confusing printf.

    You probably shouldn't be having to sanitize for output values that are auto-gen by the database or inherently numeric -- like your row id's. You need to sanitize those for output, you screwed up BAD someplace. The only thing you'd need to clean for output would be values the USER can enter, and numeric ID's shouldn't be that.

    Likewise that date formatting -- can I assume the originating field is SQL datetime? If so, use strtotime and date() to format it.

    Code:
    <table class="describeThis">
    	<thead>
    		<tr>
    			<td></td>
    			<th scope="col">V Code</th>
    			<th scope="col">Member</th>
    			<th scope="col">Name</th>
    			<th scope="col">Ring</th>
    			<th scope="col">Time</th>
    			<th scope="col">Race</th>
    			<td></td>
    			<th scope="col">Created</th>
    		</tr>
    	</thead><tbody>
    <?php
    	while ($row = $db->db_getRowAsArray()) echo '
    		<tr>
    			<td class="check_selector">
    				<input type="checkbox" name="recordid_', $row['id'], '" />
    			</td>
    			<th scope="row">', code_inital_value + $row['id'], '</th>
    			<td>', $row['member_id'], '</td>
    			<td>', htmlspecialchars($_row['name']), '</td>
    			<td>', htmlspecialchars($_row['ring']), '</td>
    			<td>', htmlspecialchars($_row['time']), '</td>
    			<td>', htmlspecialchars($_row['w_mark']), '</td>
    			<td>', htmlspecialchars($_row['ob_yb']), '</td>
    			<td>', date('H:i:s d-m-Y', strtotime($_row['created'])), '</td>
    		</tr>';
    ?>
    	</tbody>
    </table>
    Which should make it a LOT easier for you to re-arrange the column order how you like -- EVERYTHING else being done there belongs in the stylesheet, NOT the markup!

    Though that $db object strikes me as suspicious... don't know what that is, but it's... it feels wrong.
    Last edited by deathshadow; 06-14-2014 at 05:42 PM.
    Java is to JavaScript as Ham is to Hamburger.

  5. #5
    Join Date
    Jun 2014
    Posts
    4
    Well deathshadow not knowing anything about PHP and just the bare half hour reading HTML for Beginners, your answer is a foreign language to me. However, I do know the database is MySQL and most important for me the edited code I was sent works perfect and for your interest this is what he sent:-

    PHP Code:
    <table border="1">
        <tr>
            <td>&nbsp;</td>        
            <td width="60">V Code</td>
            <td width="170">Created</td>
            <td width="70">Member</td>
            <td>Name</td>
            <td>Ring</td>
            <td width="70">Time</td>
            <td width="40">Race</td>
            <td width="40">&nbsp;</td></tr>

     <?php
                $row_template 
    '<tr>
                    <td class="check_selector"><input type="checkbox" name="recordid_%s" /></td>                
                    <td>%s</td>
                    <td>%02d:%02d:%02d %02d/%02d/%4d</td>
                    <td>%s</td>
                    <td>%s</td>
                    <td>%s</td>
                    <td>%s</td>
                    <td>%s</td>
                    <td>%s</td>
                </tr>'
    ;

                
    /*
                 * Fetch matching data from database
                 */
                
    while ($row $db->db_getRowAsArray()) {
                        
    /*
                         * Extract date and time data from created field
                         */

                        
    list($c_year,
                                
    $c_month,
                                
    $c_day,
                                
    $c_hour,
                                
    $c_minute,
                                
    $c_second) = sscanf($db->db_desanitize($row['created']), '%d-%d-%d %d:%d:%d');

                        
    printf($row_template$db->db_desanitize($row['id']),                                                                    
                                                                        
    code_initial_value+$db->db_desanitize($row['id']),
                                                                        
    $c_hour$c_minute$c_second$c_day$c_month$c_year,
                                                                        
    $db->db_desanitize($row['member_id']),
                                                                        
    $db->db_desanitize($row['name']),
                                                                        
    $db->db_desanitize($row['ring']),
                                                                        
    $db->db_desanitize($row['time']),
                                                                        
    $db->db_desanitize($row['w_mark']),
                                                                        
    $db->db_desanitize($row['ob_yb'])
                                                                        );

                }
        
    ?>
                    </table>

  6. #6
    Join Date
    May 2014
    Posts
    915
    Uhg that code is just dreadful -- it's like the person who wrote it didn't know enough HTML to be writing PHP...

    But that seems to be a common failing amongst PHP developers.
    Java is to JavaScript as Ham is to Hamburger.

  7. #7
    Join Date
    Jun 2014
    Posts
    4
    The original code was written by a club member who was an architect and who unfortunately died very young from cancer and I never, ever heard him profess to being a PHP developer. However as the old saying goes, "Many roads lead to Rome" and at the end of the day even if his code is dreadful, it has worked perfectly for our club.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles