0

I'm trying to view some information from a SQL db inside an HTML page, but it doesn't work. My code shows no results at all.

<?php 
    $host        = "DRHATEM-PC";          
    $user        = "sa";                 
    $pass        = "23635451";             
    $db          = "DR_HATEM_CLINIC";   
    @$connect = odbc_connect("Driver={SQL Server};Server={".$host."}; Database={".$db."}", "".$user."", "".$pass."") or die("<center><b style=\"border:1px dashed #FF0000;\">".str_replace("[Microsoft][ODBC SQL Server Driver][SQL Server]", "", odbc_errormsg())."</b></center>"); 
    $row = odbc_fetch_array(odbc_exec($connect, "select * from entrance"));
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <table style="border:1px solid #3f3f3f; border-radius: 8px 8px 8px 8px;padding: 4px;background-color:rgba(50,50,50,0.55);text-align:center;color: #fff;font-weight: bold; font-family: Arial, Helvetica, sans-serif;font-size:12px;" width="100%" cellpadding="0" cellspacing="0"> 
            <tr> 
                <td style="border:1px solid #3f3f3f;background:rgba(0,0,0,0.55);">ID</td> 
                <td style="border:1px solid #3f3f3f;background:rgba(0,0,0,0.55);">Attend time</td> 
                <td style="border:1px solid #3f3f3f;background:rgba(0,0,0,0.55);">Visit Reason</td> 
                <td style="border:1px solid #3f3f3f;background:rgba(0,0,0,0.55);">Name</td> 
            </tr> 
            <tr>
                <td style="border:1px solid #3f3f3f;"><?php $row['ID']; ?></td> 
                <td style="border:1px solid #3f3f3f;"><?php $row['date']; ?></td> 
                <td style="border:1px solid #3f3f3f;"><?php $row['vist_type']; ?></td>     
                <td style="border:1px solid #3f3f3f;"><?php $row['FullName']; ?></td>
            </tr>
        </table>
    </head>
</html>
3
  • You're only displaying the first row of the results. If you want to display all the results, you need to call odbc_fetch_array in a loop. Commented Nov 12, 2014 at 23:04
  • 1
    it doesn't work... can you elaborate a little? Commented Nov 12, 2014 at 23:04
  • it don't show any results at all Commented Nov 12, 2014 at 23:05

2 Answers 2

1

1) do a loop for each row 2) echo the rows. You only have <?PHP $row['...']; ?> which is nothing.

$qry = odbc_exec($connect, "select * from entrance");
while ($row = odbc_fetch_array($qry)) {
... 
html with php:  echo $row['my key'];
...
}
Sign up to request clarification or add additional context in comments.

Comments

0

Change <?php $row['ID']; ?> to <?php echo $row['ID']; ?> so the variable is printed out but you will still see only the first record. If there are more than one record you have to do like this:

<?php while($row = odbc_fetch_array(odbc_exec($connect, "select * from entrance")){ ?>
 <tr>
    <td style="border:1px solid #3f3f3f;"><?php $row['ID']; ?></td> 
    <td style="border:1px solid #3f3f3f;"><?php $row['date']; ?></td> 
    <td style="border:1px solid #3f3f3f;"><?php $row['vist_type']; ?></td>     
    <td style="border:1px solid #3f3f3f;"><?php $row['FullName']; ?></td>
</tr>
<?php } ?>

Hope that this will help you

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.