substitution in variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Hancey

    #1

    substitution in variables

    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>".$$fl dname1."</td><td>".$$fldn ame2."<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
  • Chung Leong

    #2
    Re: substitution in variables


    "Phil Hancey" <phancey@2bytes .co.uk> wrote in message
    news:53393c11.0 406290349.1306d 980@posting.goo gle.com...[color=blue]
    > 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 =[/color]
    "<tr><td>". $rs->Fields[0]->value."</td><td>".$rs->Fields[3]->value."<td></tr[color=blue]
    >"
    >
    > while (!$rs->EOF)
    > {
    > echo $row;
    > }[/color]

    Use a function:

    function PrintRow($col1, $col2) {
    echo "<tr><td>$c ol1</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.


    Comment

    Working...