Categories > TinyButStrong general >

cany anyone see my error?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: ny10021
Date: 2005-03-03
Time: 06:38

cany anyone see my error?

I sure cannot!  Please help...

here is my php:

<?php
include '/home/virtual/admin34/var/www/html/includes/dbconn.inc.php';
include_once('/home/virtual/admin34/var/www/html/includes/tbs_class.php');

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate('test5.html');

$sql = mysql_query("SELECT * FROM menu LIMIT 4, 6") or die ("Could not query");
    
while($row = mysql_fetch_array($sql, MYSQL_ASSOC)){
$menu['id'] = $row['id'];
// echo $menu['id'].", ";
$menu['name'] = $row['name'];
// echo $menu['name'].", ";
$menu['type'] = $row['type'];
// echo $menu['type']."<br>";
$menu['descr'] = $row['descr'];
//  echo $menu['descr']."<br>";
$menu['price'] = $row['price'];
//  echo $menu['price']."<P>";    
}

$TBS->MergeBlock('menu', $menu);

?>

and here is my html:

<table>
<tr>
  <td>[menu.id;block=tr]</td>
  <td>[menu.name]</td>
  <td>[menu.type]</td>
  <td>[menu.descr]</td>
  <td>[menu.price]</td>
</tr>
</table>

and here is what I get:

<br /><b>TinyButStrong Error</b> (Array value): Can't merge &#91;menu.price] because there is no key named 'price'. <em>This message can be cancelled using parameter 'noerr'.</em><br />
<br /><b>TinyButStrong Error</b> (Array value): Can't merge &#91;menu.descr] because there is no key named 'descr'. <em>This message can be cancelled using parameter 'noerr'.</em><br />
<br /><b>TinyButStrong Error</b> (Array value): Can't merge &#91;menu.type] because there is no key named 'type'. <em>This message can be cancelled using parameter 'noerr'.</em><br />
<br /><b>TinyButStrong Error</b> (Array value): Can't merge &#91;menu.name] because there is no key named 'name'. <em>This message can be cancelled using parameter 'noerr'.</em><br />
<br /><b>TinyButStrong Error</b> (Array value): Can't merge &#91;menu.id] because there is no key named 'id'. <em>This message can be cancelled using parameter 'noerr'.</em><br />
By: ny10021
Date: 2005-03-03
Time: 06:40

Re: cany anyone see my error?

by the way, when print out each value in the while loop, i get the correct result.  so i know it's an error either in the html side or in my Mergeblock statement.
By: Skrol29
Date: 2005-03-03
Time: 11:50

Re: cany anyone see my error?

Yes,

It shouldn't be
$menu['id'] = $row['id']
but :
$menu[]['id'] = $row['id']
$menu must be and array of records.

By the bay, you loop could be more simple if you code:
while($row = mysql_fetch_array($sql, MYSQL_ASSOC)){
  $menu[] = $row;
}

And don't forget that TBS can do it for you if you just need data retreiving.
By: Skrol29
Date: 2005-03-03
Time: 11:52

Re: cany anyone see my error?

$menu[]['id'] = $row['id']
This is not quite correct in fact, because other fields (name, type,...) will be added to another records.

  $i++;
  $menu[$i]['id'] = $row['id']
  $menu[$i]['name'] = $row['name']
   ...
is better
By: ny10021
Date: 2005-03-03
Time: 19:01

Re: cany anyone see my error?

Yes!  Now it works perfectly.  Thank you so much!

This is a great tool, by the way.  I have to say that, as I learn php, TBS has been a godsend because I concurrently learning html.  Separating the two makes it much easier to find errors in my code and it makes the learning process go faster. 

Thanks for such an elegent and easy to use class!
By: Skrol29
Date: 2005-03-04
Time: 01:29

Re: cany anyone see my error?

Don't hesitate to express yourself on the Testimonials page :)