Jump to content

Advise on modifying this script please:


roldahayes

Recommended Posts

Hi there, this script has been modified to my needs and works well, but im wondering if anyone can help with getting the "description" coloumn to allien left instead of centered??

 

Also would it be possible to add a new field to the script to allow a small image to be displayed for each line?

 

<html>
<body>

<table border="1" cellspacing="0" cellpadding="5" width="440" style="border-collapse:collapse;">
  <tr style="background-color:gainsboro">
    <th>Product Code</th>
    <th>Description</th>
    <th>Price<br />(exc VAT)</th>
    <th>Price<br />(Inc. VAT)</th>
  </tr>
<?php

$odd  = 'whitesmoke';
$even = 'azure';

$products = file('info.txt');

foreach($products as $i => $product_info)
{
    list($product_code, $description, $price, $priceVAT) = explode('~', $product_info);

    $bg = ($i%2) ? $odd : $even;
    
    echo "  <tr style=\"background-color:$bg\">
    <td>$product_code</td>
    <td>$description</td>
    <td>\$$price</td>
    <td>\$$priceVAT</td>
  </tr>\n";

}

?>
</table>

 

an example of this script running can be seen here http://www.rhinoracks.co.uk/berlingo.php

Link to comment
https://forums.phpfreaks.com/topic/75784-advise-on-modifying-this-script-please/
Share on other sites

Only change that small section:

<html>
<body>

<table border="1" cellspacing="0" cellpadding="5" width="440" style="border-collapse:collapse;">
  <tr style="background-color:gainsboro">
    <th>Product Code</th>
    <th>Description</th>
    <th>Price<br />(exc VAT)</th>
    <th>Price<br />(Inc. VAT)</th>
  </tr>
<?php

$odd  = 'whitesmoke';
$even = 'azure';

$products = file('info.txt');

foreach($products as $i => $product_info)
{
    list($product_code, $description, $price, $priceVAT) = explode('~', $product_info);

    $bg = ($i%2) ? $odd : $even;
    
    echo "  <tr style=\"background-color:$bg\">
    <td>$product_code</td>
    <td aligtn="left">$description</td>
    <td>\$$price</td>
    <td>\$$priceVAT</td>
  </tr>\n";

}

?>
</table>

If you want an image, where would you want it? This is more html than php.

I am changing the small section

 

echo "  <tr style=\"background-color:$bg\">

    <td>$product_code</td>

    <td>$description</td>

    <td>&pound$price</td>

    <td>&pound$priceVAT</td>

  </tr>\n";

 

but it still kills the page...

 

I wanted the image to show in an extra colomn to the left of the table like a thumbnail image, ive already got the images resized and stored in a folder and wondered if the code could "link" to these somehow from my data text file...

oh yeah, sorry. forgot to escape the quotes.

something like this might work for the image:

<html>
<body>

<table border="1" cellspacing="0" cellpadding="5" width="440" style="border-collapse:collapse;">
  <tr style="background-color:gainsboro">
    <th>Product Code</th>
    <th>Description</th>
    <th>Price<br />(exc VAT)</th>
    <th>Price<br />(Inc. VAT)</th>
  </tr>
<?php

$odd  = 'whitesmoke';
$even = 'azure';

$products = file('info.txt');

foreach($products as $i => $product_info)
{
    list($product_code, $description, $price, $priceVAT, $image) = explode('~', $product_info);
        list($w, $h) = getimagesize($image);
        $image = "<a href=\"$image\"><img src=\"$image\" border=\"0\" alt=\"$image\" width=\"$w\" height=\"$h\" /></a>";
    $bg = ($i%2) ? $odd : $even;
    
    echo "  <tr style=\"background-color:$bg\">
    <td>$image</td>
    <td>$product_code</td>
    <td align=\"left\">$description</td>
    <td>\$$price</td>
    <td>\$$priceVAT</td>
  </tr>\n";

}

?>
</table>

 

Just have a part of the file (the last bit of each section) as the relative path to the file.

i.e:

images/myimage.jpg

What does the code look like ?

If you're talking about the text file I'm presuming it's something like this:

product_code1~description1~price1~priceVAT1~image1
product_code2~description2~price2~priceVAT2~image2
product_code3~description3~price3~priceVAT3~image3

as it's going through each line and getting the vars by exploding '~'.

Fantastic! unlimited thanks for this!

 

last question...!

 

the thumb image is now hyperlinked to the origanl thum stored on the server...

could this be changed to link to a pop up html window to show a larger view?

 

page so far is here

http://www.rhinoracks.co.uk/image.php  (the one section down the bottom of the pipe tube)

yeah. just add another var to the list which contains the full size version.

<html>
<body>

<table border="1" cellspacing="0" cellpadding="5" width="440" style="border-collapse:collapse;">
  <tr style="background-color:gainsboro">
    <th>Product Code</th>
    <th>Description</th>
    <th>Price<br />(exc VAT)</th>
    <th>Price<br />(Inc. VAT)</th>
  </tr>
<?php

$odd  = 'whitesmoke';
$even = 'azure';

$products = file('info.txt');

foreach($products as $i => $product_info)
{
    list($product_code, $description, $price, $priceVAT, $thumb, $image) = explode('~', $product_info);
        list($w, $h) = getimagesize($thumb);
        $url= "window.open('pop_up.php?img=$image','image',
'left=20,top=20,width=500,height=500,toolbar=0,resizable=1');";
        $thumb = "<a href=\"javascript:void(0);\" onclick="$url"><img src=\"$thumb\" border=\"0\" alt=\"$thumb\" width=\"$w\" height=\"$h\" /></a>";
    $bg = ($i%2) ? $odd : $even;
    
    echo "  <tr style=\"background-color:$bg\">
    <td>$image</td>
    <td>$product_code</td>
    <td align=\"left\">$description</td>
    <td>\$$price</td>
    <td>\$$priceVAT</td>
  </tr>\n";

}

?>
</table>

 

EDIT: in pop_up.php get the img var and use that as the <img src="$_GET['img']" />

sorry. I don't usualy use double quotes. change this:

        $thumb = "<a href=\"javascript:void(0);\" onclick="$url"><img src=\"$thumb\" border=\"0\" alt=\"$thumb\" width=\"$w\" height=\"$h\" /></a>";

to this:

        $thumb = "<a href=\"javascript:void(0);\" onclick=\"$url\"><img src=\"$thumb\" border=\"0\" alt=\"$thumb\" width=\"$w\" height=\"$h\" /></a>";

yeah. create a basic blank page call it pop_up.php.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>image</title>
</head>

<body>
</body>
</html>

 

Then in the body section, you need to get the variable $_GET['img'] and output it as an image. Something like this:

<?php
if(file_exists($_GET['img'])){
list($w, $h) = getimagesize($_GET['img']);
echo "<img src=\"$_GET['img']\" border=\"0\" alt=\"$_GET['img']\" width=\"$w\" height=\"$h\" />";
}else{
echo 'image not found';
}
?>

Right, that makes sense but Im having problems with the data file now with the extra var added

 

Ive made a test page here for where i am so far http://www.rhinoracks.co.uk/test.php

 

</div>
<link href="style.css" rel="stylesheet" type="text/css">


      <table width="98%" border="0" align="center" cellpadding="3" cellspacing="3" style="border-collapse:collapse; font-family:arial; font-size:11px; color:#000000;">
        <tr bgcolor="#282B2D" style="background-color:#282B2D">
          <th colspan="5"><div align="left"><img src="images/modre.jpg" width="405" height="35" /></div></th>
        </tr>
        <tr bgcolor="#132028" style="background-color:#132028">
          <th width="14%" bgcolor="#006699" class="style17">image</th>
          <th width="12%" bgcolor="#006699" class="style17">Order Code</th>
          <th width="58%" bgcolor="#006699" class="style17">Description</th>
          <th width="8%" bgcolor="#006699" class="style17">Price<br />
            (exc VAT)</th>
          <th width="8%" bgcolor="#006699" class="style17">Price<br />
            (Inc. VAT)</th>
        </tr>
        <?php



$odd  = '#cccccc';

$even = '#999999';



$products = file('./csv/berlingo_mod.csv');



foreach($products as $i => $product_info)
{
    list($product_code, $description, $price, $priceVAT, $thumb, $image) = explode(',', $product_info);
        list($w, $h) = getimagesize($thumb);
        $url= "window.open('pop_up.php?img=$image','image',
'left=20,top=20,width=500,height=500,toolbar=0,resizable=1');";
        $thumb = "<a href=\"javascript:void(0);\" onclick=\"$url\"><img src=\"$thumb\" border=\"0\" alt=\"$thumb\" width=\"$w\" height=\"$h\" /></a>";

    $bg = ($i%2) ? $odd : $even;

    

    echo "  <tr style=\"background-color:$bg\">

    <td>$image</td>

    <td>$product_code</td>

    <td align=\"left\">$description</td>

    <td>&pound$price</td>

    <td>&pound$priceVAT</td>

  </tr>\n";



}



?>
      </table>
      <div align="center"><br />

 

data file is here

 

csvimages/mr.jpg,R549,Modular Roof Rack (2 Modulals) 2.0m L x 1.3m W (Not For Tailgate Vans),203.4,239,vans/pipe.jpg

The text needs to be in the order that you're collecting it.

list($product_code, $description, $price, $priceVAT, $thumb, $image)

means that you need it in that order.

R549,Modular Roof Rack (2 Modulals) 2.0m L x 1.3m W (Not For Tailgate Vans),203.4,239,vans/pipe.jpg,csvimages/mr.jpg

 

I'm not sure which is the thumb link and which is the full size, but it needs to be thumb, then full.

Hope that helps!

I've sorted out how to input the data file correctly and the pop up opens the right page by adjusting the code slightly, (although the image wont appear??)

 

Can the code be changed to open a pop up of a URL instead so i can have more information in the pops?

are you getting the "image not found" message?

 

in pop file change this:

<?php
if(file_exists($_GET['img'])){
//list($w, $h) = getimagesize($_GET['img']);
//echo "<img src=\"$_GET['img']\" border=\"0\" alt=\"$_GET['img']\" width=\"$w\" height=\"$h\" />";
echo 'img: ' . $_GET['img'];
}else{
echo 'image not found';
}
?>

to this:

<?php
if(file_exists($_GET['img'])){
list($w, $h) = getimagesize($_GET['img']);
echo "<img src=\"$_GET['img']\" border=\"0\" alt=\"$_GET['img']\" width=\"$w\" height=\"$h\" />";
}else{
echo 'image not found';
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.