0

I'm having the following PHP code:

$Query1 = "Select ReportId,MailingFrequency from reports_scheduler WHERE UserId='$UserId'";
    $result1 = db::sql($Query1);
    $X = array();
    while($x = mysql_fetch_assoc($result1)) {
        $this->smarty->assign("X",$x['ReportId']);// This gives '1'
        $this->smarty->assign("X",$x['MailingFrequency']);//This gives 'Saturday'
    }

My HTML code:

{html_table loop=$X}
      <table id="resulttable" border="1">
      <tr> 
          <td>$X[0]</td>
          <td>$X[1]</td>
      </tr>
  </table>
When I run my code, instead of displaying values '1' and 'Saturday', only 'Saturday' is displayed. Please help.

1 Answer 1

1

You overwrite smarty $X variable, not creating an array. On 6th line you set $X to 1, on 7th line you set $X to 'Saturday'. The previous value is overwritten.

First create new array, then put that into Smarty template.

$X = array();

while($x = mysql_fetch_assoc($result1)) {
    $X[0] = $x['ReportId'];
    $X[1] = $x['MailingFrequency'];

    $this->smarty->assign("X", $X);
}

When you have only 1 rows from DB, you don't need to use while loop, access directly to result, eg:

$x = mysql_fetch_assoc($result1); // instead of line with while()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.