while() and MySQL

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

    while() and MySQL

    I have a database where I use the while() command to iterate through each
    row and their resultant arrays to populate a table as the while() command
    is executed.

    I would like to have in the database a "pointer" that says something like
    $MyString, but in the PHP $MyString is given a URL of an image. So every
    time during the while() command it comes across the text $MyString it
    instead substitutes it for the URL instead of echoing $MyString.

    I have tried putting the URL of the image in a few fields directly into the
    database, whilst this method does work, it is not the solution I want as
    the database fields would start becoming large to cope with the URL instead
    of a short VARCHAR declaration.

    Does anyone have an idea how to get the text to be substituted while the
    while() command is going through an array? The array cannot be "messed"
    around with, it has to stay in the order it is being read out of for
    display into a table.

    My current code looks like:

    $Yes = '<img src="tick.png"> ';

    while ($row = @mysql_fetch_ar ray($result))
    {
    $FName = $row['FeatureName'];
    $AccountType1 = $row['Coll-1'];
    $AccountType2 = $row['Coll-2'];
    $AccountType3 = $row['Coll-3'];
    $AccountType4 = $row['Coll-4'];

    $entry .= "<tr class=\"BottomL ine\"><td
    style=\"text-align:left;\">< B>$FName</B></td><td>$Account Type1</td>
    etc.etc.
    }

    Thanks

    Dariusz
  • Virgil Green

    #2
    Re: while() and MySQL

    "Dariusz" <ng@lycaus.plus YOURSHIT.com> wrote in message
    news:41471198$0 $41970$ed2619ec @ptn-nntp-reader01.plus.n et...[color=blue]
    > I have a database where I use the while() command to iterate through each
    > row and their resultant arrays to populate a table as the while() command
    > is executed.
    >
    > I would like to have in the database a "pointer" that says something like
    > $MyString, but in the PHP $MyString is given a URL of an image. So every
    > time during the while() command it comes across the text $MyString it
    > instead substitutes it for the URL instead of echoing $MyString.[/color]

    I had a hard time following this and still don't know what it means.
    [color=blue]
    > I have tried putting the URL of the image in a few fields directly into[/color]
    the[color=blue]
    > database, whilst this method does work, it is not the solution I want as
    > the database fields would start becoming large to cope with the URL[/color]
    instead[color=blue]
    > of a short VARCHAR declaration.[/color]

    This makes no sense to me. What are you trying to store where?
    [color=blue]
    > Does anyone have an idea how to get the text to be substituted while the
    > while() command is going through an array? The array cannot be "messed"
    > around with, it has to stay in the order it is being read out of for
    > display into a table.[/color]

    The text from where?
    [color=blue]
    > My current code looks like:
    >
    > $Yes = '<img src="tick.png"> ';[/color]

    This is the only reference I see to an IMG tag.
    [color=blue]
    > while ($row = @mysql_fetch_ar ray($result))
    > {
    > $FName = $row['FeatureName'];
    > $AccountType1 = $row['Coll-1'];
    > $AccountType2 = $row['Coll-2'];
    > $AccountType3 = $row['Coll-3'];
    > $AccountType4 = $row['Coll-4'];[/color]

    Which of these fields is giving you trouble? What's in them?
    [color=blue]
    > $entry .= "<tr class=\"BottomL ine\"><td
    > style=\"text-align:left;\">< B>$FName</B></td><td>$Account Type1</td>
    > etc.etc.
    > }[/color]

    I didn't see $MyString anywhere in that example. Nor did I see an example of
    the expected input and output.

    Try again with a clearer example. Short, complete. I, for one, have no idea
    what you tried to ask.

    - Virgil


    Comment

    • Alvaro G. Vicario

      #3
      Re: while() and MySQL

      *** Dariusz escribió/wrote (Tue, 14 Sep 2004 15:43:16 GMT):[color=blue]
      > I would like to have in the database a "pointer" that says something like
      > $MyString, but in the PHP $MyString is given a URL of an image. So every
      > time during the while() command it comes across the text $MyString it
      > instead substitutes it for the URL instead of echoing $MyString.[/color]

      Do you mean str_replace() ??


      --
      -+ Álvaro G. Vicario - Burgos, Spain
      +- http://www.demogracia.com (la web de humor barnizada para la intemperie)
      ++ Las dudas informáticas recibidas por correo irán directas a la papelera
      -+ I'm not a free help desk, please don't e-mail me your questions
      --

      Comment

      • Dariusz

        #4
        Re: while() and MySQL

        In article <L1G1d.1757$Gy7 .691@newssvr22. news.prodigy.co m>, "Virgil Green" <vjg@DESPAMobsy dian.com> wrote:
        Okay, I'll try re-writing the text.

        Basically, if I have in the database "$MyString" entered as text, when the
        while() loop is processing the array to make a HTML table, every time it
        comes across "$MyString" text from ANY part of ANY array, it should write
        the contents of the $MyString variable already declared instead of just
        writing the text "$MyString" into the table which the loop constructs as it
        reads the database. The way the table is constructed can't be changed.

        So when the PHP is processed, the HTML should read:

        <td><img src="yes.png"></td>
        <td>sometext</td>
        <td>moretext</td>
        <td><img src="yes.png"></td>

        and not

        <td>$MyString </td>
        <td>sometext</td>
        <td>moretext</td>
        <td>$MyString </td>

        Hope that is a bit clearer.

        Dariusz

        Comment

        • Polaris

          #5
          Re: while() and MySQL

          > So when the PHP is processed, the HTML should read:[color=blue]
          >
          > <td><img src="yes.png"></td>
          > <td>sometext</td>
          > <td>moretext</td>
          > <td><img src="yes.png"></td>
          >
          > and not
          >
          > <td>$MyString </td>
          > <td>sometext</td>
          > <td>moretext</td>
          > <td>$MyString </td>[/color]

          echo or print or whatever command you use with double quotes"text" instead
          of single quotes 'text'.
          $name="Dariusz" ;
          echo 'Hi, my name is $name';
          results in: Hi, my name is $name
          but
          echo "Hi, my name is $name";
          results in Hi, my name is Dariusz

          Polaris.







          Comment

          • Dariusz

            #6
            Re: while() and MySQL

            In article <41474fc7$0$623 55$5fc3050@drea der2.news.tisca li.nl>, "Polaris" <ask4polaris@ho tmail.com> wrote:[color=blue]
            >echo or print or whatever command you use with double quotes"text" instead
            >of single quotes 'text'.[/color]

            I have already thought of this problem, but it was not it.

            However, I have since done a LOT of digging and found a partial solution
            which if solved would be ideal.

            Current code:

            while ($row = @mysql_fetch_ar ray($result))
            {
            $FName = $row['FeatureName'];
            if (in_array("Yes" , $row))
            {
            $row = '<img src="tick.png" width="38" height="18">';
            }
            $AccountType1 = $row['Coll-1'];
            $AccountType2 = $row['Coll-2'];
            $AccountType3 = $row['Coll-3'];
            $AccountType4 = $row['Coll-4'];

            $display_entry .= "<tr class=\"BottomL ine\">
            <tdstyle=\"te xt-align:left;\">< B>$FName</B></td>
            <td>$AccountTyp e1</td>
            <td>$AccountTyp e2</td>
            <td>$AccountTyp e3</td>
            etc...


            So now as the array is being read, every time the word "Yes" is
            encountered, it is replaced in Coll-1, Coll-2, Coll-3, Coll-4. The problem
            is though that is is not 100% working. Instead of replacing the entire
            string (which in this case is a URL for an image), it is just echoing "<"
            (minus quotes). Playing about I find that it is only echoing the first
            character of the string.

            So I have a table that had a lot of Yes's replaced by < instead of the url
            which would show that graphic.

            Any suggestions?

            Dariusz

            Comment

            • Virgil Green

              #7
              Re: while() and MySQL

              "Dariusz" <ng@lycaus.plus YOURSHIT.com> wrote in message
              news:41474674$0 $47806$ed2619ec @ptn-nntp-reader02.plus.n et...[color=blue]
              > In article <L1G1d.1757$Gy7 .691@newssvr22. news.prodigy.co m>, "Virgil Green"[/color]
              <vjg@DESPAMobsy dian.com> wrote:[color=blue]
              > Okay, I'll try re-writing the text.
              >
              > Basically, if I have in the database "$MyString" entered as text, when the
              > while() loop is processing the array to make a HTML table, every time it
              > comes across "$MyString" text from ANY part of ANY array, it should write
              > the contents of the $MyString variable already declared instead of just
              > writing the text "$MyString" into the table which the loop constructs as[/color]
              it[color=blue]
              > reads the database. The way the table is constructed can't be changed.
              >
              > So when the PHP is processed, the HTML should read:
              >
              > <td><img src="yes.png"></td>
              > <td>sometext</td>
              > <td>moretext</td>
              > <td><img src="yes.png"></td>
              >
              > and not
              >
              > <td>$MyString </td>
              > <td>sometext</td>
              > <td>moretext</td>
              > <td>$MyString </td>
              >
              > Hope that is a bit clearer.[/color]

              Just barely. Where did the text '<img src="yes.php">' come from? Is the
              variable name you want to use always $MyString? Is that the only variable?
              Are you trying to use any "variable" placed inside the data in your
              database? Where does $MyString get populated?

              That said, I suspect you want to use a regular expression to find any string
              in your data that starts with $ up to the next space. That can then be
              extracted into a variable. You can then use $$ syntax to reference a field
              of the same name. That can be used to so a str_replace into the original
              data.

              $myfield = (some regular expression extraction I don't want to look up right
              now);
              $mydata = $$myfield;
              $newdata = str_replace($my field, $mydata, $dbfdata);
              echo $newdata;

              Just a thought and a guess. No testing has even been attempted.

              - Virgil


              Comment

              Working...