Reply to Re: [PHP] Variables in stored txt

Your name:

Reply:


Posted by "Richard Lynch" on 06/01/05 08:27

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация