[SOLVED] empty variables
Posted: Mon Jul 12, 2004 6:53 am
ok ive ran into a slight problem, my table writes variables to a txt file, which are then read from in another page, the code for reading te variables is as follows.
$car is the variable passed to the page, from another.
I am now at the stage where if the variable ( all txt strings) are empty ( the field on the form was not filled in) then it will replace the txt with something else eg "not available", so i added this code, for instance with $country.
The trouble is, to do this for every variable will make a huge messy script, is there any much shorter way i can do this, maybe using a while loop? or something like that?.
Thanx
Tom
$car is the variable passed to the page, from another.
Code: Select all
<?php
$filename = $car;
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
$variable = explode(',',$contents);
$name = $variable[0];
$country = $variable[1];
$email = $variable[2];
$manufacturer = $variable[3];
$model = $variable[4];
$powertrain = $variable[5];
$baseprice = $variable[6];
$engine = $variable[7];
$transmission = $variable[8];
$suspension = $variable[9];
$brakes = $variable[10];
$wheels = $variable[11];
$tyres = $variable[12];
$exterior = $variable[13];
$interior = $variable[14];
$security = $variable[15];
$figures = $variable[16];
$otherinfo = $variable[17];
$image1 = $variable[18];
$image2 = $variable[19];
$image3 = $variable[20];
$image4 = $variable[21];
fclose ($fd);
?>Code: Select all
<?php
if ($country == "")
{
$country = "<font face="Verdana, Arial, Helvetica, sans-serif" color="#cccccc" size="2">Not Available</font>";
}
?>Thanx
Tom