Re: Variables in stored txt

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 31, 2005 12:18 pm, Niels Riis Kristensen said:
> Hi. I have a problem that consist of a desire to use preformatted
> text in a while-loop while inserting data from another search. The
> code is as follows:
>
>
> ________________
>
> $get_var1 = mysql_query("SELECT * FROM table1 WHERE id LIKE '1' LIMIT
> 1");
>      while($record=mysql_fetch_assoc($get_var1))
>          {
>          $show_var = $record['text'];
>          }

Your first problem is this:

You loop through every record in table1, and you stuff it into $show_var...

But you are REPLACING the contents of $show_var each time, so you only end
up with the *LAST* record in $show_var.

You need to either concatenate to $show_var to dump *all* the data into
one big long text, or you need to move all the code below *inside* the
loop to do whatever you are trying to do to EACH $show_var, one after
another.

> $result = mysql_query("SELECT * FROM table2 WHERE kind LIKE '20'");
>      while($record=mysql_fetch_assoc($result))
>          {
>          echo "  <html>
>                  <head>
>                  <meta http-equiv='content-type' content='text/
> html;charset=iso-8859-1'>
>                  <title>test</title>
>                  </head>
>                  <body bgcolor='#ffffff'>
>                      <table width='100%' border='0' cellspacing='2'
> cellpadding='0' height='50'>
>                          <tr>
>                              <td><img src='../../../Media/HMLogo.gif'
> alt='' height='40' width='147' border='0'></td>
>                              <td></td>
>                              <td></td>
>                          </tr>
>                      </table>
>                      <table width='100%' border='0' cellspacing='2'
> cellpadding='0'>
>                          <tr height='526'>
>                              <td width='100%' height='600'>
>                              ".$show_var."
>                              </td>
>                          </tr>
>                      </table>
>                  </body>
>                  </html>";
>              print "
>              <script type='text/javascript'>
>              window.print();
>              </script>";
>          }

These sems okay, I guess, though I'd get rid of the HTML inside of quotes
thing and use a heredoc or just break out of PHP and put <?php echo
$show_var?> in the middle of a good long chunk of HTML.

I'm not really sure what you're trying to *DO* mind you...  Maybe you only
wanted the LAST record from table1 in the first place...  I sure doubt it
though.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux