By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,968 Members | 1,684 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,968 IT Pros & Developers. It's quick & easy.

substitution in variables

P: n/a
I am trying to write a small function to display a recordset in
tabular form. I want to define a row only once but then display the
relevant data for each row but I got "undefined variable" when I tried
the following:

I do not necessarily want to display all fields in a recordset so my
row might look like this

$row = "<tr><td>".$rs->Fields[0]->value."</td><td>".$rs->Fields[3]->value."<td></tr>"

while (!$rs->EOF)
{
echo $row;
}
If I define the row like this then the substitution of the variables
takes place immediately and so all rows will be the same as the first.
So what I thought I'd try to do was:

$fldname1 = "rs->Fields[0]->value";
$fldname2 = "rs->Fields[3]->value";
while (!$rs->EOF)
{
$row = "<tr><td>".$$fldname1."</td><td>".$$fldname2."<td></tr>"
}

but here I get an undefined variable :rs->Fields(0)->value error.

I know it looks like I could just put the $row assignment within my
loop in the top example but in fact this row statement is built up
using a more complicated function which I don't want to have to call
for every record as the basic structure will be the same, it's just
the values in the middle that change.

thanks
Phil
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Phil Hancey" <ph*****@2bytes.co.uk> wrote in message
news:53**************************@posting.google.c om...
I am trying to write a small function to display a recordset in
tabular form. I want to define a row only once but then display the
relevant data for each row but I got "undefined variable" when I tried
the following:

I do not necessarily want to display all fields in a recordset so my
row might look like this

$row = "<tr><td>".$rs->Fields[0]->value."</td><td>".$rs->Fields[3]->value."<td></tr"

while (!$rs->EOF)
{
echo $row;
}


Use a function:

function PrintRow($col1, $col2) {
echo "<tr><td>$col1</td><td>$col2<td></tr>";
}

while (!$rs->EOF) {
PrintRow($rs->Fields[0]->value, $rs->Fields[3]->value);
}

COM will crash your server by the way.
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.