Re: Re: Formatting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Nov 25, 2012, at 11:56 AM, Jim Giner wrote:

On 11/25/2012 12:46 PM, Ethan Rosenberg, PhD wrote:
Dear list -

When I run the following code, the results are preceded by at least one screen full of blank lines. I am showing you a large code block since I
do not know where the error is:

    if(isset($_REQUEST['Sex'])&& trim($_POST['Sex']) != '' )
    {
        if ($_REQUEST['Sex'] === "0")
        {
            $sex = 'Male';
        }

        else
        {
            $sex = 'Female';
        }

     }
            $allowed_fields = array
                ('Site' => 's',  'MedRec' => 'i', 'Fname' => 's',
'Lname' => 's','Phone'=> 's',   'Height' => 'i',   'Sex' => 's',
                'Hx' => 's','Bday' => 's',  'Age' => 'i'
                );

            if(empty($allowed_fields))
            {
                 echo "ouch";
            }

            // Configure the query and the acceptable params to put
into the WHERE clause
            $sql12 = 'SELECT * FROM Intake3 WHERE 1';

           // Magically put everything together
            $types = '';
            $args = array();
            foreach( $allowed_fields as $k => $type )
            {
             if( !array_key_exists( $k, $allowed_fields ) )
                    continue;
                else
                {
                    if( ($_POST[$k]) != '')
                    {
$args[] = &$_POST[$k]; // Note the addition of
the ampersand here
                        $types .= $type;
                        $sql12 .= " AND ($k = ?)";
                    }
                }
            }
            $stmt = mysqli_stmt_init($cxn);
            mysqli_stmt_prepare( $stmt, $sql12 );

            if( !$stmt )
                throw new Exception( 'Error preparing statement' );

            // Put the statement and types variables at the front of
the params to pass to mysqli_stmt_bind_param()
            array_unshift( $args, $stmt, $types ); // Note that I've
moved this call. Apparently it doesn't pass back the result. I guess
sometimes I just forget these things.

            // mysqli_stmt_bind_param()
if( !call_user_func_array( 'mysqli_stmt_bind_param', $args ) )
            throw new Exception( 'Failed calling
mysqli_stmt_bind_param' );

            if( !mysqli_stmt_execute( $stmt ) )
throw new Exception( 'Error while executing statement' );

            mysqli_stmt_bind_result( $stmt,  $Site, $MedRec, $Fname,
$Lname, $Phone, $Height, $Sex, $Hx, $Bday, $Age);




            if(count($errors_array) == 0)
            {


?>
<center><b>Search Results</b></center><br />
<center>
<!--  This is the block that prints about one screen full down bellow
the Search Results header -->

<table border="4" cellpadding="5" cellspacing="55"  rules="all"
frame="box" style="table-layout: fixed;">
<tr class="heading">
<th>Site</th>
<th>Medical Record</th>
<th>First Name</th>
<th>Last Name</th>
<th>Phone</th>
<th>Height</th>
<th>Sex</th>
<th>History</th>
<th>Birthday</th>
<th>Age</th>
</tr>
</div>

<?php             $i = 0;
                do
                {
                    {
                        $vara2 = array(array($Site, $MedRec, $Fname,
$Lname, $Phone, $Height, $Sex, $Hx, $Bday, $Age));

                        $vara2[$i][0]    = $Site;
                        $vara2[$i][1]    = $MedRec;
                        $vara2[$i][2]    = $Fname;
                        $vara2[$i][3]    = $Lname;
                        $vara2[$i][4]    = $Phone;
                        $vara2[$i][5]    = $Height;
                        $vara2[$i][6]    = $Sex;
                        $vara2[$i][7]    = $Hx;
                        $vara2[$i][8]    = $Bday;
                        $vara2[$i][9]    = $Age;

                        echo "<tr>\n";
                        $_SESSION['exe'] = 2;
?>
<td> <?php echo $vara2[$i][0]?> </td><br />
<td> <?php echo $vara2[$i][1]?> </td><br />
<td> <?php echo $vara2[$i][2]?> </td><br />
<td> <?php echo $vara2[$i][3]?> </td><br />
<td> <?php echo $vara2[$i][4]?> </td><br />
<td> <?php echo $vara2[$i][5]?> </td><br />
<td> <?php echo $vara2[$i][6]?> </td><br />
<td class="first-col"><?php echo $vara2[$i][7] ?></td><br />
<td> <?php echo $vara2[$i][8]?> </td><br />
<td> <?php echo $vara2[$i][9]?> </td><br />
<?php                     echo "</tr>\n";
                        $i = $i +1;

                    }
                } while (mysqli_stmt_fetch($stmt)); //end do-while
                    $imax = $i;
                    echo "</table>";
                    echo "</center>";
                    echo "</form>";

            }    //    end count($errors_array)

Help and advice, please

Ethan

If this is the ACTUAL code you are executing you need to remember to NOT include any blank lines. Each and every one gets echoed to the client and with all the blank lines I see above, that could very well be a full but empty page.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Ethan

What is up with this line of code?
...
<th>Age</th>
</tr>
</div>

Why is that closing div inside your table? Big no no. That closing div is breaking your table structure.
Should be more like:
...
<th>Age</th>
</tr>
</table>
</div>

if your wrapping your table with a div that is, and if that </tr> is the end of the table. Otherwise remove that </div> or move it to after the </table> it wraps.

Also, why are you using <center>? Set the align attribute <table align="center"> or inline style attribute to <table style="text- align:center;"> or better yet, set a class or id to the table and set the style of the table in your css.
css:
.recordsTable { text-align:center; }
html:
<table class="recordsTable">

Your also using a combination of <th> and <td>. I am thinking that you have columns and that they lay next to each other.
Lose the <th> and just use <td>

For this line:
<center><b>Search Results</b></center><br />

You could do something like

<p style="text-align:center;"><b>Search Results</b></p><br />
or even
<font style="text-align:center;"><b>Search Results</b></font><br />

Also, you may want to read up on using <ul> instead of <table> as they are quicker at loading.

My 2¢

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux