Well, you didn't give much detail about what your error is, but this is how I do it and it works for me:
$string="SELECT id,name FROM foo";
$db=new mydb;
$db->query("$string");
while($db->next_record()) {
$id=$db->f('id');
$name=$db->f('name');
print "<tr><td>$id</td><td>$name</td></tr>";
}
Note I use $db->f, not $db->p. using ->p inside Echo() might cause some problems.