|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi guys. Ok I've got this bit of code...
<html> <head> <title>testpage</title> <script language="php"> function csv_entrycount($csvhandle){ $count=0; while(($line=fgetcsv($csvhandle,1000,",")) !==FALSE) { $count++; } return $count; } </script> </head> <body> <table border="0" cellspacing="0" width="100%"> <tr> <td> <?php echo '<p align="center"><table border="2" cellspacing="0" cellpadding="5" bordercolor="#000066">'; $handle=fopen("soy.csv", "r"); //retrieves and opens CSV*/ //THIS IS THE SPOT WHERE I'M ADDING SOMETHING*/ $row = 0; //Creates a counter for row*/ while(($line=fgetcsv($handle,1000,",")) ! ==FALSE) //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=$numsizes>$line[0]</ td>"; //generates a row with label*/ for ($c=1; $c < $num; $c +=2) //Cycles through each size, price pair*/ { $price = $line[$c + 1]; $size = $line[$c]; $name = "$line[0]"; $paypalbutton=<<<EOD <form target="paypal" action="https:// www.paypal.com/cgi-bin/webscr" method="post"> <input type="image" src="https:// www.paypal.com/en_US/i/btn/btn_cart_SM.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> <img alt="" border="0" src="https:// www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> <input type="hidden" name="add" value="1"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="business" value="AceIncorporated@gmail.com"> <input type="hidden" name="item_name" value="{$name } {$size}"> <input type="hidden" name="amount" value="{$price}"> <input type="hidden" name="no_shipping" value="0"> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="lc" value="US"> <input type="hidden" name="bn" value="PP-ShopCartBF"> </form> EOD; echo "<td>$size</td>"; // generates a size cell*/ echo "<td>$$price</ td>"; //generates a price cell*/ echo "<td>$paypalbutton</td>"; echo "</ tr>"; //closes row } } fclose($handle); //Closes csv echo "</table>"; ?> </td> </tr> </table> </body> </html> Works GREAT...Except my aunt wants 2 columns instead of one. I have an idea on how to do it, but I'm having trouble. I'm wanting to insert a line of code that utilizes my function up there in the head. $maxcol=csv_entrycount($handle); in my code towards the top of the script, you'll see where I blatantly advertised that I wanted to place something there... that's what I want to put there. But when I do, it makes the page...disappear. Normally I'd think that the code was just wrong and I needed to fix it. (and that may still be the case), but I tried the SAME bit of code in a much less codey page for testing purposes and it WORKED. I'm so frustrated. I've been at this for the past week now. Can anyone ? AceX |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
AceX wrote:
> Hi guys. Ok I've got this bit of code... > > > <html> > > <head> > <title>testpage</title> > <script language="php"> > function csv_entrycount($csvhandle){ > $count=0; > > while(($line=fgetcsv($csvhandle,1000,",")) !==FALSE) > { > $count++; > } > return $count; > } > </script> > </head> > > <body> > > <table border="0" cellspacing="0" width="100%"> > <tr> > <td> > <?php > echo '<p align="center"><table border="2" > cellspacing="0" cellpadding="5" bordercolor="#000066">'; > $handle=fopen("soy.csv", > "r"); //retrieves and opens CSV*/ > //THIS IS THE SPOT WHERE I'M ADDING > SOMETHING*/ > $row = > 0; //Creates a > counter for row*/ > while(($line=fgetcsv($handle,1000,",")) ! > ==FALSE) //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=$numsizes>$line[0]</ > td>"; //generates a row with label*/ > > for ($c=1; $c < $num; $c > +=2) //Cycles through each size, price > pair*/ > { > $price = $line[$c + 1]; > $size = $line[$c]; > $name = "$line[0]"; > $paypalbutton=<<<EOD > <form target="paypal" action="https:// > www.paypal.com/cgi-bin/webscr" method="post"> > <input type="image" src="https:// > www.paypal.com/en_US/i/btn/btn_cart_SM.gif" border="0" name="submit" > alt="Make payments with PayPal - it's fast, free and secure!"> > <img alt="" border="0" src="https:// > www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> > <input type="hidden" name="add" > value="1"> > <input type="hidden" name="cmd" > value="_cart"> > <input type="hidden" name="business" > value="AceIncorporated@gmail.com"> > <input type="hidden" name="item_name" value="{$name } > {$size}"> > <input type="hidden" name="amount" value="{$price}"> > <input type="hidden" name="no_shipping" value="0"> > <input type="hidden" name="no_note" value="1"> > <input type="hidden" name="currency_code" value="USD"> > <input type="hidden" name="lc" value="US"> > <input type="hidden" name="bn" value="PP-ShopCartBF"> > </form> > EOD; > echo "<td>$size</td>"; // > generates a size cell*/ > echo "<td>$$price</ > td>"; //generates a price cell*/ > echo "<td>$paypalbutton</td>"; > echo "</ > tr>"; //closes row > } > } > > fclose($handle); //Closes > csv > > echo "</table>"; > ?> > </td> > </tr> > </table> > > </body> > > </html> > > Works GREAT...Except my aunt wants 2 columns instead of one. I have an > idea on how to do it, but I'm having trouble. > > I'm wanting to insert a line of code that utilizes my function up > there in the head. > > $maxcol=csv_entrycount($handle); > > in my code towards the top of the script, you'll see where I blatantly > advertised that I wanted to place something there... that's what I > want to put there. But when I do, it makes the page...disappear. > > Normally I'd think that the code was just wrong and I needed to fix > it. (and that may still be the case), but I tried the SAME bit of code > in a much less codey page for testing purposes and it WORKED. I'm so > frustrated. I've been at this for the past week now. Can anyone ? > > AceX > > > > > Enable errors and display them to see why your page is going away: In your php.ini file, ensure you have: error_reporting = E_ALL display_errors = on -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Feb 15, 11:41pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> AceX wrote: > > Hi guys. Ok I've got this bit of code... > > > <html> > > > <head> > > <title>testpage</title> > > <script language="php"> > > function csv_entrycount($csvhandle){ > > $count=0; > > > while(($line=fgetcsv($csvhandle,1000,",")) !==FALSE) > > { > > $count++; > > } > > return $count; > > } > > </script> > > </head> > > > <body> > > > <table border="0" cellspacing="0" width="100%"> > > <tr> > > <td> > > <?php > > echo '<p align="center"><table border="2" > > cellspacing="0" cellpadding="5" bordercolor="#000066">'; > > $handle=fopen("soy.csv", > > "r"); //retrieves and opens CSV*/ > > //THIS IS THE SPOT WHEREI'M ADDING > > SOMETHING*/ > > $row = > > 0; //Creates a > > counter for row*/ > > while(($line=fgetcsv($handle,1000,",")) ! > > ==FALSE) //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=$numsizes>$line[0]</ > > td>"; //generates a row with label*/ > > > for ($c=1; $c < $num; $c > > +=2) //Cycles through each size, price > > pair*/ > > { > > $price = $line[$c + 1]; > > $size = $line[$c]; > > $name = "$line[0]"; > > $paypalbutton=<<<EOD > > <form target="paypal" action="https:// > >www.paypal.com/cgi-bin/webscr" method="post"> > > <input type="image" src="https:// > >www.paypal.com/en_US/i/btn/btn_cart_SM.gif" border="0" name="submit" > > alt="Make payments with PayPal - it's fast, free and secure!"> > > <img alt="" border="0" src="https:// > >www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> > > <input type="hidden" name="add" > > value="1"> > > <input type="hidden" name="cmd" > > value="_cart"> > > <input type="hidden" name="business" > > value="AceIncorpora...@gmail.com"> > > <input type="hidden" name="item_name" value="{$name } > > {$size}"> > > <input type="hidden" name="amount" value="{$price}"> > > <input type="hidden" name="no_shipping" value="0"> > > <input type="hidden" name="no_note" value="1"> > > <input type="hidden" name="currency_code" value="USD"> > > <input type="hidden" name="lc" value="US"> > > <input type="hidden" name="bn" value="PP-ShopCartBF"> > > </form> > > EOD; > > echo "<td>$size</td>"; // > > generates a size cell*/ > > echo "<td>$$price</ > > td>"; //generates a price cell*/ > > echo "<td>$paypalbutton</td>"; > > echo "</ > > tr>"; //closes row > > } > > } > > > fclose($handle); //Closes > > csv > > > echo "</table>"; > > ?> > > </td> > > </tr> > > </table> > > > </body> > > > </html> > > > Works GREAT...Except my aunt wants 2 columns instead of one. I have an > > idea on how to do it, but I'm having trouble. > > > I'm wanting to insert a line of code that utilizes my function up > > there in the head. > > > $maxcol=csv_entrycount($handle); > > > in my code towards the top of the script, you'll see where I blatantly > > advertised that I wanted to place something there... that's what I > > want to put there. But when I do, it makes the page...disappear. > > > Normally I'd think that the code was just wrong and I needed to fix > > it. (and that may still be the case), but I tried the SAME bit of code > > in a much less codey page for testing purposes and it WORKED. I'm so > > frustrated. I've been at this for the past week now. Can anyone ? > > > AceX > > Enable errors and display them to see why your page is going away: > > In your php.ini file, ensure you have: > > error_reporting = E_ALL > display_errors = on > > -- > ================== > Remove the "x" from my email address > Jerry Stuckle > JDS Computer Training Corp. > jstuck...@attglobal.net > ==================- Hide quoted text - > > - Show quoted text - The errors are on. Normally if there's an error with the code, the page won't load at all, and it will display an error message. I've seen a lot of error messages workin on this and been able to work through 'em. But with this one, the page loads. The php-generated table just disappears. Everything else loads fine. Check out www.aceincorporated.com/greatamerican/soy.php to see the working 'single' column version. And then check out www.aceincorporated.com/greatamerican/soy3.php to see what happens when I add that one line of code. AceX |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Fri, 15 Feb 2008 20:26:14 -0800 (PST), AceX
<AceIncorporated@gmail.com> wrote: >I'm wanting to insert a line of code that utilizes my function up >there in the head. > >$maxcol=csv_entrycount($handle); > >in my code towards the top of the script, you'll see where I blatantly >advertised that I wanted to place something there... that's what I >want to put there. But when I do, it makes the page...disappear. AFAIK you can NOT insert snippets of PHP in the same was as you would, say, Javascript - withink <script> tags in the <HEAD>. Put your function at the bottom of the page within <?php .... ?> and see what happens then... -- Locate your Mobile phone: <http://www.bizorg.co.uk/news.html> Great gifts: <http://www.ThisBritain.com/ASOS_popup.html> |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
AceX wrote:
> On Feb 15, 11:41 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote: >> AceX wrote: >>> Hi guys. Ok I've got this bit of code... >>> <html> >>> <head> >>> <title>testpage</title> >>> <script language="php"> >>> function csv_entrycount($csvhandle){ >>> $count=0; >>> while(($line=fgetcsv($csvhandle,1000,",")) !==FALSE) >>> { >>> $count++; >>> } >>> return $count; >>> } >>> </script> >>> </head> >>> <body> >>> <table border="0" cellspacing="0" width="100%"> >>> <tr> >>> <td> >>> <?php >>> echo '<p align="center"><table border="2" >>> cellspacing="0" cellpadding="5" bordercolor="#000066">'; >>> $handle=fopen("soy.csv", >>> "r"); //retrieves and opens CSV*/ >>> //THIS IS THE SPOT WHERE I'M ADDING >>> SOMETHING*/ >>> $row = >>> 0; //Creates a >>> counter for row*/ >>> while(($line=fgetcsv($handle,1000,",")) ! >>> ==FALSE) //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=$numsizes>$line[0]</ >>> td>"; //generates a row with label*/ >>> for ($c=1; $c < $num; $c >>> +=2) //Cycles through each size, price >>> pair*/ >>> { >>> $price = $line[$c + 1]; >>> $size = $line[$c]; >>> $name = "$line[0]"; >>> $paypalbutton=<<<EOD >>> <form target="paypal" action="https:// >>> www.paypal.com/cgi-bin/webscr" method="post"> >>> <input type="image" src="https:// >>> www.paypal.com/en_US/i/btn/btn_cart_SM.gif" border="0" name="submit" >>> alt="Make payments with PayPal - it's fast, free and secure!"> >>> <img alt="" border="0" src="https:// >>> www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> >>> <input type="hidden" name="add" >>> value="1"> >>> <input type="hidden" name="cmd" >>> value="_cart"> >>> <input type="hidden" name="business" >>> value="AceIncorpora...@gmail.com"> >>> <input type="hidden" name="item_name" value="{$name } >>> {$size}"> >>> <input type="hidden" name="amount" value="{$price}"> >>> <input type="hidden" name="no_shipping" value="0"> >>> <input type="hidden" name="no_note" value="1"> >>> <input type="hidden" name="currency_code" value="USD"> >>> <input type="hidden" name="lc" value="US"> >>> <input type="hidden" name="bn" value="PP-ShopCartBF"> >>> </form> >>> EOD; >>> echo "<td>$size</td>"; // >>> generates a size cell*/ >>> echo "<td>$$price</ >>> td>"; //generates a price cell*/ >>> echo "<td>$paypalbutton</td>"; >>> echo "</ >>> tr>"; //closes row >>> } >>> } >>> fclose($handle); //Closes >>> csv >>> echo "</table>"; >>> ?> >>> </td> >>> </tr> >>> </table> >>> </body> >>> </html> >>> Works GREAT...Except my aunt wants 2 columns instead of one. I have an >>> idea on how to do it, but I'm having trouble. >>> I'm wanting to insert a line of code that utilizes my function up >>> there in the head. >>> $maxcol=csv_entrycount($handle); >>> in my code towards the top of the script, you'll see where I blatantly >>> advertised that I wanted to place something there... that's what I >>> want to put there. But when I do, it makes the page...disappear. >>> Normally I'd think that the code was just wrong and I needed to fix >>> it. (and that may still be the case), but I tried the SAME bit of code >>> in a much less codey page for testing purposes and it WORKED. I'm so >>> frustrated. I've been at this for the past week now. Can anyone ? >>> AceX >> Enable errors and display them to see why your page is going away: >> >> In your php.ini file, ensure you have: >> >> error_reporting = E_ALL >> display_errors = on >> >> -- >> ================== >> Remove the "x" from my email address >> Jerry Stuckle >> JDS Computer Training Corp. >> jstuck...@attglobal.net >> ==================- Hide quoted text - >> >> - Show quoted text - > > The errors are on. Normally if there's an error with the code, the > page won't load at all, and it will display an error message. I've > seen a lot of error messages workin on this and been able to work > through 'em. But with this one, the page loads. The php-generated > table just disappears. Everything else loads fine. Check out > www.aceincorporated.com/greatamerican/soy.php to see the working > 'single' column version. And then check out www.aceincorporated.com/greatamerican/soy3.php > to see what happens when I add that one line of code. > AceX > Two things: First of all, you can use <script> tags with PHP code, but support for it isn't always there. Using the standard PHP tags <?php ... ?> is much better. Start there. But your main problem is you're reading the entire file in your function, so when you return you're at end-of-file and there is nothing else to read. You'll have to reset the file pointer to the beginning of the file to read it again. Two other things - first of all, most carts use a database for something like this. It solves a lot of other problems. I really recommend you do so. The other question is why you're even using XML. XML is great for M2M communications, but browser support is problematic. HTML 4.01 Strict is much better to use for new pages. And BTW - you're going to have problems with some browsers, anyway. I can't get either page to validate. For instance, your first page: http://validator.w3.org/check?verbos...ican%2Fsoy.php -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Hi,
Here's how you can print any number of columns. The mod (%) test tells you if the item is either the first or last column. [products.php] <? error_reporting(E_ALL | E_STRICT); function printGrid($columns = 2) { $path = dirname(__FILE__) . '/list.csv'; if (($csv = fopen($path, 'r')) === false) { trigger_error("Failed to open CSV file.", E_USER_ERROR); } else { $sz = 1000; for ($i = 0; ($item = fgetcsv($csv, $sz)) !== false; $i++) { if ($columns && $i % $columns == 0) echo "<tr>\n"; // Print the product echo '<td>' . ($i + 1) . ". {$item[0]}</td>\n"; if ($columns && $i % $columns == $columns - 1) echo "</tr>\n"; } fclose($csv); for (; $columns && $i % $columns != 0; $i++) { echo "<td> </td>\n"; } } } ?> <h1>Products</h1> <table cellpadding=3 cellspacing=0 border=1> <? printGrid() ?> </table> On Feb 15, 11:26 pm, AceX <AceIncorpora...@gmail.com> wrote: > Hi guys. Ok I've got this bit of code... > > <html> > > <head> > <title>testpage</title> > <script language="php"> > function csv_entrycount($csvhandle){ > $count=0; > > while(($line=fgetcsv($csvhandle,1000,",")) !==FALSE) > { > $count++;} > return $count; > } > > </script> > </head> > > <body> > > <table border="0" cellspacing="0" width="100%"> > <tr> > <td> > <?php > echo '<p align="center"><table border="2" > cellspacing="0" cellpadding="5" bordercolor="#000066">'; > $handle=fopen("soy.csv", > "r"); //retrieves and opens CSV*/ > //THIS IS THE SPOT WHERE I'M ADDING > SOMETHING*/ > $row = > 0; //Creates a > counter for row*/ > while(($line=fgetcsv($handle,1000,",")) ! > ==FALSE) //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=$numsizes>$line[0]</ > td>"; //generates a row with label*/ > > for ($c=1; $c < $num; $c > +=2) //Cycles through each size, price > pair*/ > { > $price = $line[$c + 1]; > $size = $line[$c]; > $name = "$line[0]"; > $paypalbutton=<<<EOD > <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> > <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_cart_SM.gif" border="0" name="submit" > alt="Make payments with PayPal - it's fast, free and secure!"> > <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> > <input type="hidden" name="add" > value="1"> > <input type="hidden" name="cmd" > value="_cart"> > <input type="hidden" name="business" > value="AceIncorpora...@gmail.com"> > <input type="hidden" name="item_name" value="{$name } > {$size}"> > <input type="hidden" name="amount" value="{$price}"> > <input type="hidden" name="no_shipping" value="0"> > <input type="hidden" name="no_note" value="1"> > <input type="hidden" name="currency_code" value="USD"> > <input type="hidden" name="lc" value="US"> > <input type="hidden" name="bn" value="PP-ShopCartBF"> > </form> > EOD; > echo "<td>$size</td>"; // > generates a size cell*/ > echo "<td>$$price</ > td>"; //generates a price cell*/ > echo "<td>$paypalbutton</td>"; > echo "</ > tr>"; //closes row > } > } > > fclose($handle); //Closes > csv > > echo "</table>"; > ?> > </td> > </tr> > </table> > > </body> > > </html> > > Works GREAT...Except my aunt wants 2 columns instead of one. I have an > idea on how to do it, but I'm having trouble. > > I'm wanting to insert a line of code that utilizes my function up > there in the head. > > $maxcol=csv_entrycount($handle); > > in my code towards the top of the script, you'll see where I blatantly > advertised that I wanted to place something there... that's what I > want to put there. But when I do, it makes the page...disappear. > > Normally I'd think that the code was just wrong and I needed to fix > it. (and that may still be the case), but I tried the SAME bit of code > in a much less codey page for testing purposes and it WORKED. I'm so > frustrated. I've been at this for the past week now. Can anyone ? > > AceX |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
At line 20 it should be:
if (!$columns || $i % $columns != 0) { for (; $columns && $i % $columns != 0; $i++) { echo "<td> </td>\n"; } echo "</tr>\n"; } On Feb 16, 9:30 pm, petersprc <peters...@gmail.com> wrote: > Hi, > > Here's how you can print any number of columns. > > The mod (%) test tells you if the item is either the first or last > column. > > [products.php] > <? > > error_reporting(E_ALL | E_STRICT); > > function printGrid($columns = 2) > { > $path = dirname(__FILE__) . '/list.csv'; > if (($csv = fopen($path, 'r')) === false) { > trigger_error("Failed to open CSV file.", E_USER_ERROR); > } else { > $sz = 1000; > for ($i = 0; ($item = fgetcsv($csv, $sz)) !== false; $i++) { > if ($columns && $i % $columns == 0) echo "<tr>\n"; > // Print the product > echo '<td>' . ($i + 1) . ". {$item[0]}</td>\n"; > if ($columns && $i % $columns == $columns - 1) echo "</tr>\n"; > } > fclose($csv); > for (; $columns && $i % $columns != 0; $i++) { > echo "<td> </td>\n"; > } > } > > } > > ?> > > <h1>Products</h1> > > <table cellpadding=3 cellspacing=0 border=1> > <? printGrid() ?> > </table> > > On Feb 15, 11:26 pm, AceX <AceIncorpora...@gmail.com> wrote: > > > Hi guys. Ok I've got this bit of code... > > > <html> > > > <head> > > <title>testpage</title> > > <script language="php"> > > function csv_entrycount($csvhandle){ > > $count=0; > > > while(($line=fgetcsv($csvhandle,1000,",")) !==FALSE) > > { > > $count++;} > > return $count; > > } > > > </script> > > </head> > > > <body> > > > <table border="0" cellspacing="0" width="100%"> > > <tr> > > <td> > > <?php > > echo '<p align="center"><table border="2" > > cellspacing="0" cellpadding="5" bordercolor="#000066">'; > > $handle=fopen("soy.csv", > > "r"); //retrieves and opens CSV*/ > > //THIS IS THE SPOT WHERE I'M ADDING > > SOMETHING*/ > > $row = > > 0; //Creates a > > counter for row*/ > > while(($line=fgetcsv($handle,1000,",")) ! > > ==FALSE) //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=$numsizes>$line[0]</ > > td>"; //generates a row with label*/ > > > for ($c=1; $c < $num; $c > > +=2) //Cycles through each size, price > > pair*/ > > { > > $price = $line[$c + 1]; > > $size = $line[$c]; > > $name = "$line[0]"; > > $paypalbutton=<<<EOD > > <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> > > <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_cart_SM.gif" border="0" name="submit" > > alt="Make payments with PayPal - it's fast, free and secure!"> > > <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> > > <input type="hidden" name="add" > > value="1"> > > <input type="hidden" name="cmd" > > value="_cart"> > > <input type="hidden" name="business" > > value="AceIncorpora...@gmail.com"> > > <input type="hidden" name="item_name" value="{$name } > > {$size}"> > > <input type="hidden" name="amount" value="{$price}"> > > <input type="hidden" name="no_shipping" value="0"> > > <input type="hidden" name="no_note" value="1"> > > <input type="hidden" name="currency_code" value="USD"> > > <input type="hidden" name="lc" value="US"> > > <input type="hidden" name="bn" value="PP-ShopCartBF"> > > </form> > > EOD; > > echo "<td>$size</td>"; // > > generates a size cell*/ > > echo "<td>$$price</ > > td>"; //generates a price cell*/ > > echo "<td>$paypalbutton</td>"; > > echo "</ > > tr>"; //closes row > > } > > } > > > fclose($handle); //Closes > > csv > > > echo "</table>"; > > ?> > > </td> > > </tr> > > </table> > > > </body> > > > </html> > > > Works GREAT...Except my aunt wants 2 columns instead of one. I have an > > idea on how to do it, but I'm having trouble. > > > I'm wanting to insert a line of code that utilizes my function up > > there in the head. > > > $maxcol=csv_entrycount($handle); > > > in my code towards the top of the script, you'll see where I blatantly > > advertised that I wanted to place something there... that's what I > > want to put there. But when I do, it makes the page...disappear. > > > Normally I'd think that the code was just wrong and I needed to fix > > it. (and that may still be the case), but I tried the SAME bit of code > > in a much less codey page for testing purposes and it WORKED. I'm so > > frustrated. I've been at this for the past week now. Can anyone ? > > > AceX |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
On Feb 16, 9:36pm, petersprc <peters...@gmail.com> wrote:
> At line 20 it should be: > > if (!$columns || $i % $columns != 0) { > for (; $columns && $i % $columns != 0; $i++) { > echo "<td> </td>\n"; > } > echo "</tr>\n"; > } > > On Feb 16, 9:30 pm, petersprc <peters...@gmail.com> wrote: > > > > > Hi, > > > Here's how you can print any number of columns. > > > The mod (%) test tells you if the item is either the first or last > > column. > > > [products.php] > > <? > > > error_reporting(E_ALL | E_STRICT); > > > function printGrid($columns = 2) > > { > > $path = dirname(__FILE__) . '/list.csv'; > > if (($csv = fopen($path, 'r')) === false) { > > trigger_error("Failed to open CSV file.", E_USER_ERROR); > > } else { > > $sz = 1000; > > for ($i = 0; ($item = fgetcsv($csv, $sz)) !== false; $i++) { > > if ($columns && $i % $columns == 0) echo "<tr>\n"; > > // Print the product > > echo '<td>' . ($i + 1) . ". {$item[0]}</td>\n"; > > if ($columns && $i % $columns == $columns - 1) echo "</tr>\n"; > > } > > fclose($csv); > > for (; $columns && $i % $columns != 0; $i++) { > > echo "<td> </td>\n"; > > } > > } > > > } > > > ?> > > > <h1>Products</h1> > > > <table cellpadding=3 cellspacing=0 border=1> > > <? printGrid() ?> > > </table> > > > On Feb 15, 11:26 pm, AceX <AceIncorpora...@gmail.com> wrote: > > > > Hi guys. Ok I've got this bit of code... > > > > <html> > > > > <head> > > > <title>testpage</title> > > > <script language="php"> > > > function csv_entrycount($csvhandle){ > > > $count=0; > > > > while(($line=fgetcsv($csvhandle,1000,",")) !==FALSE) > > > { > > > $count++;} > > > return $count; > > > } > > > > </script> > > > </head> > > > > <body> > > > > <table border="0" cellspacing="0" width="100%"> > > > <tr> > > > <td> > > > <?php > > > echo '<p align="center"><table border="2" > > > cellspacing="0" cellpadding="5" bordercolor="#000066">'; > > > $handle=fopen("soy.csv", > > > "r"); //retrieves and opens CSV*/ > > > //THIS IS THE SPOT WHERE I'M ADDING > > > SOMETHING*/ > > > $row = > > > 0; //Creates a > > > counter for row*/ > > > while(($line=fgetcsv($handle,1000,",")) ! > > > ==FALSE) //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=$numsizes>$line[0]</ > > > td>"; //generates a row with label*/ > > > > for ($c=1; $c < $num; $c > > > +=2) //Cycles through each size, price > > > pair*/ > > > { > > > $price = $line[$c + 1]; > > > $size = $line[$c]; > > > $name = "$line[0]"; > > > $paypalbutton=<<<EOD > > > <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> > > > <inputtype="image" src="https://www.paypal.com/en_US/i/btn/btn_cart_SM.gif" border="0" name="submit" > > > alt="Make payments with PayPal - it's fast, free and secure!"> > > > <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> > > > <inputtype="hidden" name="add" > > > value="1"> > > > <inputtype="hidden" name="cmd" > > > value="_cart"> > > > <input type="hidden" name="business" > > > value="AceIncorpora...@gmail.com"> > > > <input type="hidden" name="item_name" value="{$name } > > > {$size}"> > > > <input type="hidden" name="amount" value="{$price}"> > > > <input type="hidden" name="no_shipping" value="0"> > > > <input type="hidden" name="no_note" value="1"> > > > <input type="hidden" name="currency_code" value="USD"> > > > <input type="hidden" name="lc" value="US"> > > > <input type="hidden" name="bn" value="PP-ShopCartBF"> > > > </form> > > > EOD; > > > echo "<td>$size</td>"; // > > > generates a size cell*/ > > > echo "<td>$$price</ > > > td>"; //generates a price cell*/ > > > echo "<td>$paypalbutton</td>"; > > > echo "</ > > > tr>"; //closes row > > > } > > > } > > > > fclose($handle); //Closes > > > csv > > > > echo "</table>"; > > > ?> > > > </td> > > > </tr> > > > </table> > > > > </body> > > > > </html> > > > > Works GREAT...Except my aunt wants 2 columns instead of one. I have an > > > idea on how to do it, but I'm having trouble. > > > > I'm wanting to insert a line of code that utilizes my function up > > > there in the head. > > > > $maxcol=csv_entrycount($handle); > > > > in my code towards the top of the script, you'll see where I blatantly > > > advertised that I wanted to place something there... that's what I > > > want to put there. But when I do, it makes the page...disappear. > > > > Normally I'd think that the code was just wrong and I needed to fix > > > it. (and that may still be the case), but I tried the SAME bit of code > > > in a much less codey page for testing purposes and it WORKED. I'm so > > > frustrated. I've been at this for the past week now. Can anyone ? > > > > AceX- Hide quoted text - > > - Show quoted text - I've got the page working fine. As it's my aunt's small out-of-home business and I'm doin it for free, this is the easiest way for me. The validation thing, I'm just not understanding. The only thing that happens is it just doesn't validate.. It's incredibly confusing. I went from 1 error, to about 10,000 (exaggerating). If anyone's willing to that would be great |
|
![]() |
| Outils de la discussion | |
|
|