Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Senior Member Blackhawk095's Avatar
    Join Date
    May 2011
    Location
    Kentucky (USA)
    Posts
    384
    Member #
    27969
    Liked
    45 times
    I'm trying to output database results into a table (as rows), but when I echo out the results, they appear at the top of the page, instead of in the table toward the bottom of the page. If I switch "echo" with "return", the content does show in the table, but only displays the first result.

    Here is a snippet of the class which displays the results from the database
    PHP Code:
    public function __construct(.....)
    {
    ......
    $this->award $this->getAwards($this->id);
    .......
    }

    ....
    skipping down......
     
    private function 
    getAwards($id)
    {
    include_once(
    CORE '-- PATH--');
    $row = new m_Award($id); //the m_Award class queries the database and returns results

    if(is_array($row->award)) // check if m_Award class returned database results, or returned false
    {
    foreach(
    $row as $key => $value// if results exist, break the multidimentional array down into single arrays
    {
    foreach(
    $value as $key => $row)
    {
    //when I use echo, the results appear at the top of the page, not in the <table>
    echo '
    <tr>
    <td>' 
    $row['title'] . '</td>
    <td>
    <ul>
    <li><strong>Level:</strong> ' 
    $row['level'] . '</li>
    <li><strong>Location:</strong> ' 
    $row['location'] . '</li>
    </ul>
    </td>
    <td>' 
    $row['date'] . '</td>
    </tr>
    '
    ;
    }
    }
    }
    else 
    // if no results are returned, echo this message
    {      // this displays inside of the <table> because it uses "return", instead of "echo"
    return '
    <tr>
    <td colspan="3">No Awards Available</td>
    </tr>
    '
    ;
    }

    Snippet from the view:
    PHP Code:
    echo '
    <table>
    <tr>
    <th>Title</th>
    <th>Competition</th>
    <th>Date Awarded</th>
    </tr>
    $Profile->award '
    </table>
    '

    Database class snippet:
    PHP Code:
    if($stmt $this->connection->prepare($query))
    {
    $stmt->execute($param);
    $numRows $stmt->rowCount();

    if(
    $numRows 0)
    {
    while(
    $row $stmt->fetch(PDO::FETCH_ASSOC))
    {
    $result[] = $row;
    }

    return 
    $result;
    }
    else
    {
    return 
    false;

    For security reasons, I removed sections of the code which could reveal sensitive information about the site structure/functions.

    Please assist me in finding a solution for this issue.

    Thanks
    [COLOR=rgb(0, 51, 102)]Student Web Designer[/COLOR]
    [COLOR=rgb(0, 51, 102)]If you thought something I said was helpful. LIKE IT![/COLOR]

  2.  

  3. #2
    Senior Member Blackhawk095's Avatar
    Join Date
    May 2011
    Location
    Kentucky (USA)
    Posts
    384
    Member #
    27969
    Liked
    45 times
    I still haven't found the solution.
    [COLOR=rgb(0, 51, 102)]Student Web Designer[/COLOR]
    [COLOR=rgb(0, 51, 102)]If you thought something I said was helpful. LIKE IT![/COLOR]


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:43 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com