?
Solved

Formatting PHP results into table

Posted on 2005-04-01
2
Medium Priority
?
874 Views
Last Modified: 2010-05-18
I need to place query results into a table. I tried doing a rowcount using OCIRowcount, but it returns zero even though there are rows there. As this is, it prints the first row ok in the table, but the second and subsequent results get printed below the table..

$queryminushowauth = "select cd.id as ID, cd.filename as FILENAME, cd.location as LOCATION, db_or_filesys as DBORFILESYS, file_type as FILE_TYPE from compiled_data cd, datacatalog_relateddata dr where dr.rd_id = cd.id and dr.dc_id = '$dcid'";
                        
                        $statement = OCIParse ($c1, $queryminushowauth);
                        ?>
                        <table width="501" border="1">
                  <tr>
                    <td width="92"><b>Filename</b>&nbsp;</td>
                    <td width="127"><b>Location</b></td>
                    <td width="127"><b>Database or Filesystem</b>&nbsp;</td>
                    <td width="127"><b>Filetype</b></td>
                  </tr>
                  <tr>
                          <?php
                        OCIExecute ($statement);
                        
                        $committed1 = ocicommit($c1);
                        echo OCIRowCount($statement);
                         while (OCIFetch ($statement)) {
                              $filename = OCIResult($statement, "FILENAME");
                              $location = OCIResult($statement, "LOCATION");
                              $dborfilesys = OCIResult($statement, "DBORFILESYS");
                              $filetype = OCIResult($statement, "FILE_TYPE");
                         ?>
                        
                         
                     <td> <?php echo $filename;?> </td>
                     <td> <?php echo $location;?> </td>
                     <td> <?php echo $dborfilesys;?></td>
                     <td> <?php echo $filetype;?></td>
                  </tr>
                 </td>
                 </table>
                        <?php   }?>
0
Comment
Question by:dprasad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
The_Systech earned 2000 total points
ID: 13683637
Change your code to look more like this...

$statement = OCIParse ($c1, $queryminushowauth);
                    ?>
                    <table width="501" border="1">
                  <tr>
                    <td width="92"><b>Filename</b>&nbsp;</td>
                    <td width="127"><b>Location</b></td>
                    <td width="127"><b>Database or Filesystem</b>&nbsp;</td>
                    <td width="127"><b>Filetype</b></td>
                  </tr>
                      <?php
                    OCIExecute ($statement);
                   
                    $committed1 = ocicommit($c1);
                    echo OCIRowCount($statement);
                      while (OCIFetch ($statement)) {
                         $filename = OCIResult($statement, "FILENAME");
                         $location = OCIResult($statement, "LOCATION");
                         $dborfilesys = OCIResult($statement, "DBORFILESYS");
                         $filetype = OCIResult($statement, "FILE_TYPE");
                     ?>
                   
                     <tr>
                     <td> <?php echo $filename;?> </td>
                     <td> <?php echo $location;?> </td>
                     <td> <?php echo $dborfilesys;?></td>
                     <td> <?php echo $filetype;?></td>
                  </tr>
                   <?php   }?>
                  </table>

You were opening the table row outside of the while statement and then closing the whole table inside the while statement.  Moving the table row opening into the while statment and the table closing outside of it should fix your issue.
0
 

Author Comment

by:dprasad
ID: 13683666
ohhh yeah, thanks man you rock
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question