PHP trouble

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi, I'm trying to use PHP to to a lot of repetetive work for me on a
site. I've gotten most of it working fine - EXCEPT:

the PHP is generating a table. It's looping through a CSV file until
it reaches the end. Each row is a product that one can buy.  I'm
trying to make the last column of the table a customized paypal button
based on the current variables.  To do this I've tried two different

   1. Break the php code and insert the HTML form (remember though,
this HTML break is inside a for loop) and use <?php [variable] ?> to
insert the variables where I need them.

   2. DON'T break the code and echo the form.  and delimit the quotes.

I've isolated variables out of the problem...delimiting...everything.
it all works outside of the loop.  Does php not work in a loop? I'll
post code for anyone intersted

Re: PHP trouble

Quoted text here. Click to load it

Post the code and we'll take a look.

Re: PHP trouble

Quoted text here. Click to load it

One way I tried:
   <table border=3D"2" cellspacing=3D"0" cellpadding=3D"5"
"r");                                  //retrieves and opens CSV*/
      $row =
1;                                                        //Creates a
counter for row*/
      while(($line=3Dfgetcsv($handle,1000,",")) !
=3D=3DFALSE)                //Cycles through whole CSV*/
        $num = count($line);                                      //
$num = Number of values in the current line of the CSV*/
        $row++;                                                   //
Increments $row*/
        $numsizes = ($num-1)/2;                                   //
$num is 1 label + $numsizes * (size,price)*/
        echo"<tr><td rowspan=3D$numsizes>$line[0]</td>";            //
generates a row with label*/

        for ($c=3D1; $c < $num; $c+=3D2)                               //
Cycles through each size, price pair*/
       $p = $c + 1;
       $paypalbutton=3D'<form action=3D" /
webscr" method=3D"post">
                    <input type=3D"hidden" name=3D"cmd" value=3D"_xclick">
                    <input type=3D"hidden" name=3D"business"
                    <input type=3D"hidden" name=3D"item_name" value=3D"Candle">
                    <input type=3D"hidden" name=3D"item_number" value=3D"001">
                    <input type=3D"hidden" name=3D"amount" value=3D"10.00">
                    <input type=3D"hidden" name=3D"shipping" value=3D"15.00">
                    <input type=3D"hidden" name=3D"no_shipping" value=3D"0">
                    <input type=3D"hidden" name=3D"no_note" value=3D"1">
                    <input type=3D"hidden" name=3D"currency_code" value=3D"USD">
                    <input type=3D"hidden" name=3D"lc" value=3D"US">
                    <input type=3D"hidden" name=3D"bn" value=3D"PP-BuyNowBF">
                    <input type=3D"image" src=3D" /
btn_buynow_SM.gif" border=3D"0" name=3D"submit" alt=3D"Make payments with
PayPal - it's fast, free and secure!">
                    <img alt=3D"" border=3D"0" src=3D" /
pixel.gif" width=3D"1" height=3D"1">
            echo "<td>$line[$c]</td>";                              //
generates a size cell*/
            echo "<td>$line[$p]</td>";                              //
generates a price cell*/
            echo "<td>$paypalbutton</td>";
            echo"</tr>";                                            //
        fclose($handle);                                            //
Closes csv

Now values such as the item_name and price, in the paypal button, will
be variables. I believe I know how to make that work. the problem
still occurs though when I keep them static. In this attempt I tried
to store the button to a variable then use the variable. I've also
used it with the echo command, and I've used it as straight HTML by
breaking the PHP mid-loop, inserting HTML, and then starting the PHP
again to finish the loop. Thanks guys


Re: PHP trouble

Quoted text here. Click to load it

you need to escape this:

it\'s fast

Re: PHP trouble

On Feb 3, 2:43=A0pm, wrote:
Quoted text here. Click to load it
Quoted text here. Click to load it
Quoted text here. Click to load it
Quoted text here. Click to load it
Quoted text here. Click to load it
Quoted text here. Click to load it

Whoa. I can't believe I missed that. I admit I'm not a PHP expert. I
only have some basic and general coding knowledge and know-how. I'm
about to start adding variables into the paypal button. so instead of
it reading:

     <input type=3D"hidden" name=3D"amount" value=3D"10.00">

According to what knowledge I've gathered and what I'm planning on
inserting the variable as such

    <input type=3D"hidden" name=3D"amount" value=3D"<?php $line[$c]?>">

Is that right? Will it work? Is there a better way? Thanks guys


Re: PHP trouble

AceX wrote:

Quoted text here. Click to load it

No, that won't work. This will:

value="<?php echo $line[$c]; ?>"

Quoted text here. Click to load it

I usually prefer to echo() the entire HTML, like as:

echo "<input type='hidden' name='amount' value=''>";

It's a matter of coding style, anyway. It won't have any (noticeable) impact
on performance, but (arguably) may improve code readability.

In other words: stick with the conding style more comfortable for you.

(Related reading: - there is
no "right" or "better" indent style also)

Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Dos: Venerable. Windows: Vulnerable. OS/2: Viable.

Site Timeline