Solved

formatting php output in to a variable

Posted on 2009-05-06
13
193 Views
Last Modified: 2012-05-06
Hi,

I have been trying unsuccessfully to get the output from the code below into a single variable. I need to be able to pass the output from the  info shown here in an email receipt. I have been trying to get the output into a hidden form field which I could then pass along. Would this be a good way to do it? If so how?
<?php
  for($i=0; $i<=4; $i++)
    if($_REQUEST['L_QTY'.$i]>=1)
    {
      ?>
      <tr>
        <td align="left" valign="top"><?=$_REQUEST['L_QTY'.$i]?></td>
        <td align="left" valign="top"> </td>
        <td align="left" valign="top"><?=$_REQUEST['L_NAME'.$i]?></td>
        <td align="left" valign="top"> </td>
        <td align="left" valign="top"><?=$_REQUEST['L_DESC'.$i]?></td>
      </tr>
      <?php
    }
  ?>

Open in new window

0
Comment
Question by:jackie777
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
13 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24314328
You mean

<?php
  $htmlString = "<table>";
  for($i=0; $i<=4; $i++) {
    if($_REQUEST['L_QTY'.$i]>=1)
    {
      $htmlString .= '<tr>';
      $htmlString .= '<td align="left" valign="top">'.$_REQUEST['L_QTY'.$i].'</td>';
      $htmlString .= '<td align="left" valign="top"> </td>';
      $htmlString .= '<td align="left" valign="top">'.$_REQUEST['L_NAME'.$i].'</td>';
      $htmlString .= '<td align="left" valign="top"> </td>';
      $htmlString .= '<td align="left" valign="top">'.$_REQUEST['L_DESC'.$i].'</td>';
      $htmlString .= '</tr>';
    }
  }
  $htmlString.='</table>';
  echo $htmlString;
?>

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24314346
or even

<?php
  $htmlString = "<table>";
  for($i=0; $i<=4; $i++) {
    if($_REQUEST['L_QTY'.$i]>=1)
    {
      $htmlString .= '<tr valign="top">';
      $htmlString .= '<td>'.$_REQUEST['L_QTY'.$i].'</td>';
      $htmlString .= '<td>&nbsp;</td>';
      $htmlString .= '<td>'.$_REQUEST['L_NAME'.$i].'</td>';
      $htmlString .= '<td>&nbsp;</td>';
      $htmlString .= '<td>'.$_REQUEST['L_DESC'.$i].'</td>';
      $htmlString .= '</tr>';
    }
  }
  $htmlString.='</table>';
  echo $htmlString;
?>

Open in new window

0
 

Author Comment

by:jackie777
ID: 24314574
Thanks mplungjan

I think that might be the right idea, but I still cannot seem to get the value for $htmlString to pass to the next page. Here is how I formatted my hidden input.




<input type="hidden" name="products" value="<? $htmlString ?>" />

Open in new window

0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:jackie777
ID: 24314698
I don't need to pass along the entire <table>, only the values of ['L_QTY'.$i] ['L_NAME'.$i] ['L_DESC'.$i]
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24314928
how about



<?php
  for($i=0; $i<=4; $i++) {
    if($_REQUEST['L_QTY'.$i]>=1)
    { ?>
      <input type="hidden" name="L_QTY[]" value="<? echo $_REQUEST['L_QTY'.$i]; ?>">
      <input type="hidden" name="L_NAME[]" value="<? echo $_REQUEST['L_NAME'.$i]; ?>">
      <input type="hidden" name="L_DESC[]" value="<? echo $_REQUEST['L_DESC'.$i]; ?>">
    <? } 
  }?>

Open in new window

0
 

Author Comment

by:jackie777
ID: 24315585
No, that didn't work either, I did manage to figure out how to pass along all the variables, however I am now having trouble writing an if statement to only pass along the variables that have a L_QTY value that is greater than 0
<input type="hidden" name="L_QTY0" value="<? echo $_REQUEST['L_QTY0']; ?>" />
<input type="hidden" name="L_NAME0" value="<? echo $_REQUEST['L_NAME0']; ?>" />
<input type="hidden" name="L_DESC0" value="<? echo $_REQUEST['L_DESC0']; ?>" />
<input type="hidden" name="L_QTY1" value="<? echo $_REQUEST['L_QTY1']; ?>" />
<input type="hidden" name="L_NAME1" value="<? echo $_REQUEST['L_NAME1']; ?>" />
<input type="hidden" name="L_DESC1" value="<? echo $_REQUEST['L_DESC1']; ?>" />
<input type="hidden" name="L_QTY2" value="<? echo $_REQUEST['L_QTY2']; ?>" />
<input type="hidden" name="L_NAME2" value="<? echo $_REQUEST['L_NAME2']; ?>" />
<input type="hidden" name="L_DESC2" value="<? echo $_REQUEST['L_DESC2']; ?>" />
<input type="hidden" name="L_QTY3" value="<? echo $_REQUEST['L_QTY3']; ?>" />
<input type="hidden" name="L_NAME3" value="<? echo $_REQUEST['L_NAME3']; ?>" />
<input type="hidden" name="L_DESC3" value="<? echo $_REQUEST['L_DESC3']; ?>" />
<input type="hidden" name="L_QTY4" value="<? echo $_REQUEST['L_QTY4']; ?>" />
<input type="hidden" name="L_NAME4" value="<? echo $_REQUEST['L_NAME4']; ?>" />
<input type="hidden" name="L_DESC4" value="<? echo $_REQUEST['L_DESC4']; ?>" />

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24318819
If you add the [], php makes it into an array for you

If you need to check a string you might want to make it a number first - I do not have the php syntax to do that
0
 
LVL 3

Expert Comment

by:webvogel
ID: 24320917
I don't know exaktly where the problem is. You have to make a hidden input field for every variable and not for the hole html code.

If you need this html code more than once, you can make a function.

But if it is only a display site, you can send your mail direktly or not?

Try this:
<?php
  for($i=0; $i<=4; $i++)
    if($_REQUEST['L_QTY'.$i]>=1)
    {
      ?>
      <input type="hidden" name="<?=$_REQUEST['L_QTY'.$i]?>" value="<?=$_REQUEST['L_QTY'.$i]?>" />
      <input type="hidden" name="<?=$_REQUEST['L_NAME'.$i]?>" value="<?=$_REQUEST['L_NAME'.$i]?>" />
      <input type="hidden" name="<?=$_REQUEST['L_DESC'.$i]?>" value="<?=$_REQUEST['L_DESC'.$i]?>" />
      <?php
    }
  ?>

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24320953
That does not make sense. To pass the value as name.
0
 
LVL 3

Expert Comment

by:webvogel
ID: 24321034
Sorry, I'am tired
<?php
  for($i=0; $i<=4; $i++)
    if($_REQUEST['L_QTY'.$i]>=1)
    {
      ?>
      <input type="hidden" name="<?='L_QTY'.$i?>" value="<?=$_REQUEST['L_QTY'.$i]?>" />
      <input type="hidden" name="<?='L_NAME'.$i?>" value="<?=$_REQUEST['L_NAME'.$i]?>" />
      <input type="hidden" name="<?='L_DESC'.$i?>" value="<?=$_REQUEST['L_DESC'.$i]?>" />
      <?php
    }
  ?>

Open in new window

0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 24322960
But that is what I did, I just used the smarter [] notation which creates PHP arrays

Try this - convert the quantity to an integer using intval:



<?php
  for($i=0; $i<=4; $i++) {
    if(intval($_REQUEST['L_QTY'.$i])>=1)
    { ?>
      <input type="hidden" name="L_QTY[]" value="<? echo $_REQUEST['L_QTY'.$i]; ?>">
      <input type="hidden" name="L_NAME[]" value="<? echo $_REQUEST['L_NAME'.$i]; ?>">
      <input type="hidden" name="L_DESC[]" value="<? echo $_REQUEST['L_DESC'.$i]; ?>">
    <? } 
  }?>
 
e.g.
 
<input type="hidden" name="L_QTY[]" value="First filled quantity">
<input type="hidden" name="L_NAME[]" value="First filled name">
<input type="hidden" name="L_DESC[]" value="First filled description">
<input type="hidden" name="L_QTY[]" value="Second filled quantity">
<input type="hidden" name="L_NAME[]" value="Second filled name">
<input type="hidden" name="L_DESC[]" value="Second filled description">

Open in new window

0
 

Author Closing Comment

by:jackie777
ID: 31578420
That worked, Thanks!
0
 
LVL 3

Expert Comment

by:webvogel
ID: 24326386
My english is not very good.

I like the [] notation too. But maybe he need the combination of the name (1,2,3,4) and the value.

<?php
  for($i=0; $i<=4; $i++) {
    if(intval($_REQUEST['L_QTY'.$i])>=1)
    { ?>
      <input type="hidden" name="L_QTY[<?=$i?>]" value="<? echo $_REQUEST['L_QTY'.$i]; ?>">
      <input type="hidden" name="L_NAME[<?=$i?>]" value="<? echo $_REQUEST['L_NAME'.$i]; ?>">
      <input type="hidden" name="L_DESC[<?=$i?>]" value="<? echo $_REQUEST['L_DESC'.$i]; ?>">
    <? } 
  }?>

Open in new window

0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question