3

i have a function to display all the data, in table. the number of row return is correct(based on edit n delete button) but the value are not displayed.

public function viewAll()
    {
        $sql = "SELECT 'id','titleAnn','dateOpen','dateClose' FROM annoucement";
        $query = mysql_query($sql);
            while($row = mysql_fetch_array($query)) 
            {
                $id = $row['id'];
                $title = $row['titleAnn'];
                $dateOpen = $row['dateOpen'];
                $dateClose = $row['dateClose']; 
                echo '<tr>
                    <td><?php echo $title ?></td>   
                    <td><?php echo $dateOpen ?></td>   
                    <td><?php echo $dateClose ?></td>   
                    <td><a href="editAnnouncement.php?id=<?php echo $id;?>"><input type="button" name = "editAnn" value = "Edit" /></a></td>
                    <td><a href="deleteAnn.php?id=<?php echo $id;?>" onclick="confirm("Delete this announcement?");"><input type="button" name = "deleteAnn" value = "Delete"/></td>
                  </tr>';
            }
            $this->numrows= mysql_num_rows($query);
        }

only blank space appear next to the buttons

John Conde
  • 217,595
  • 99
  • 455
  • 496
ohlala
  • 135
  • 9
  • 1
    You are putting some PHP in you echo statement: `echo '...'` => `echo ''.$title.'...'.` –  Jun 08 '15 at 15:57
  • 2
    Once more, with feeling this time! http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – CD001 Jun 08 '15 at 15:58

2 Answers2

6

You were echoing PHP within an echo.... concatenate and echo like so:

public function viewAll()
    {
        $sql = "SELECT 'id','titleAnn','dateOpen','dateClose' FROM annoucement";
        $query = mysql_query($sql);
            while($row = mysql_fetch_array($query)) 
            {
                $id = $row['id'];
                $title = $row['titleAnn'];
                $dateOpen = $row['dateOpen'];
                $dateClose = $row['dateClose']; 
                echo '<tr>
                    <td>'.$title.'</td>   
                    <td>'.$dateOpen.'</td>   
                    <td>'.$dateClose.'</td>   
                    <td><a href="editAnnouncement.php?id='.$id.'"><input type="button" name = "editAnn" value = "Edit" /></a></td>
                    <td><a href="deleteAnn.php?id='.$id.'" onclick="confirm("Delete this announcement?");"><input type="button" name = "deleteAnn" value = "Delete"/></td>
                  </tr>';
            }
            $this->numrows= mysql_num_rows($query);
        }
OllyBarca
  • 1,501
  • 1
  • 18
  • 35
3
public function viewAll()
{
    $sql = "SELECT 'id','titleAnn','dateOpen','dateClose' FROM annoucement";
    $query = mysql_query($sql);
        while($row = mysql_fetch_array($query)) 
        {
            $id = $row['id'];
            $title = $row['titleAnn'];
            $dateOpen = $row['dateOpen'];
            $dateClose = $row['dateClose']; 
            echo '<tr>
                <td>'. $title .'</td>   
                <td>'. $dateOpen .'</td>   
                <td><'. $dateClose .'</td>   
                <td><a href="editAnnouncement.php?id='. $id.'"><input type="button" name = "editAnn" value = "Edit" /></a></td>
                <td><a href="deleteAnn.php?id='. $id.'>" onclick="confirm("Delete this announcement?");"><input type="button" name = "deleteAnn" value = "Delete"/></td>
              </tr>';
        }
        $this->numrows= mysql_num_rows($query);
    }
monxas
  • 2,475
  • 2
  • 20
  • 36