Re: [PHP] Variables in stored txt

2005-05-31 Thread Richard Lynch
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 "  
>  
>  
>  test
>  
>  
>   cellpadding='0' height='50'>
>  
>   alt='' height='40' width='147' border='0'>
>  
>  
>  
>  
>   cellpadding='0'>
>  
>  
>  ".$show_var."
>  
>  
>  
>  
>  ";
>  print "
>  
>  window.print();
>  ";
>  }

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  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



Re: [PHP] Variables in stored txt

2005-05-31 Thread Niels Riis Kristensen

Oh, I get it. I have been very poor at explaining my problem.

I have a table, table1, in which I have standard text for letters. I  
would like to put data from table2 in the letters, so that the data  
is automatically placed in the letter through code in the standard  
text. It sounds complicated, I know, but I hope I make myself clear.  
English is not my native language.


What happens is, that the $show_var IS displayed. What I in my  
frustration haven't conveyed properly is, that the text in table1 in  
the the form



ordinary text to output to html ". 
$var_from_the_result_query_on_table2." some more html text



shows up just like that, no data from table2 is processed. I know  
that I am probably using the wrong function, but I can't seem to find  
one.


And the reason I use SELECT * is that there is more than one field I  
need to output. There is only one in the example so that the post  
wouldn't be to voluminous.






Niels Riis Kristensen
([EMAIL PROTECTED])

NRK Group
- Electronic Music Engraving
- Webhosting
- Dynamic Web design
- E-Lists hosting


On 31/05/2005, at 22.53, [EMAIL PROTECTED] wrote:


which are you saying doesn't work?

  - outputting the value of "$show_var" in the html that follows

 or

  - outputting values from this query:

   mysql_query("SELECT * FROM table2 WHERE kind LIKE '20'")


from what i can tell, you never actually retrieve values from this
second query.

if the issue is displaying "$show_var", you should put a debug in
between these two points, e.g.:

 {
 $show_var = $record['text'];
 }

   $debug = 4;

   if ($debug > 3) {
 print "show_var: $show_var\n";
   }


  $result = mysql_query("SELECT * FROM table2 WHERE kind LIKE '20'");


so that you actually know that your first data query/retrieval has
worked.
separately, why are you doing a "select * " when, in the first case
at least, you seem to only want the value from the field "text". if
you only want values from specific fields you should enumerate them
on the select as a "select * " is very inefficient. also, using the
"like" operator, when you really should be using the "=" operator
isn't efficient either.


 Original Message 


Date: Tuesday, May 31, 2005 09:18:42 PM +0200
From: Niels Riis Kristensen <[EMAIL PROTECTED]>
To: php-general@lists.php.net
Cc:
Subject: [PHP] Variables in stored txt

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'];
 }


$result = mysql_query("SELECT * FROM table2 WHERE kind LIKE '20'");
 while($record=mysql_fetch_assoc($result))
 {
 echo "  
 
 
 test
 
 
 
 
 
 
 
 
 
 
 
 
 ".$show_var."
 
 
 
 
 ";
 print "
 
 window.print();
 ";
 }

_

Needles to say, I hope, that it doesn't work!


Niels Riis Kristensen
([EMAIL PROTECTED])

NRK Group
- Electronic Music Engraving
- Webhosting
- Dynamic Web design
- E-Lists hosting

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



-- End Original Message --





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



RE: [PHP] Variables in stored txt

2005-05-31 Thread Jay Blanchard
Quite sending this over and over.it is taking a while for the e-mail
to get to the list

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