Re: More php trouble *pulling hair out*
- From: petersprc <petersprc@xxxxxxxxx>
- Date: Sat, 16 Feb 2008 18:36:46 -0800 (PST)
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...@xxxxxxxxx> 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...@xxxxxxxxx> 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...@xxxxxxxxx">
<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 help?
AceX
.
- Follow-Ups:
- Re: More php trouble *pulling hair out*
- From: AceX
- Re: More php trouble *pulling hair out*
- References:
- More php trouble *pulling hair out*
- From: AceX
- Re: More php trouble *pulling hair out*
- From: petersprc
- More php trouble *pulling hair out*
- Prev by Date: Re: Compare each distinct pair of the entires in the 1D associative arrays
- Next by Date: Re: Newbie need help
- Previous by thread: Re: More php trouble *pulling hair out*
- Next by thread: Re: More php trouble *pulling hair out*
- Index(es):