php variable displayed in DIV tag

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shawn1979
Forum Newbie
Posts: 1
Joined: Sat Aug 07, 2010 3:13 pm

php variable displayed in DIV tag

Post by shawn1979 »

Hello, this is my first post here. I am new to php. I am trying to open a .csv file and load parts of it into div tags in html code, which are set in a table. The code below will open the file and print it to the screen, but I can't seem to get values to my div tags. I've been stuck on this for days now please point me in the right direction.
<html>
<head>
<title>Freon Log Test 1</title>

<?PHP
$custname = array();
$hscinvoice = array();
$date = array();
$in = array();
$out = array();
$total = array();

$file_handle = fopen("FreonLogs/R22/8A52.csv", "r");

while (!feof($file_handle) ) {

$line_of_text = fgetcsv($file_handle, 1024);


$custname[1]=$line_of_text[0];
$hscinvoice[1]=$line_of_text[1];
$date[1]=$line_of_text[2];
$in[1]=$line_of_text[3];
$out[1]=$line_of_text[4];
$total[1]=$line_of_text[5];
print $line_of_text[0] . $line_of_text[1]. $line_of_text[2] . "<BR>";
}

fclose($file_handle);
?>

</head>
<body>
<table border="1" width="60%">
<tr>
<td><div><?php echo $custname[1];?></div></td>
<td><div><?php echo $hscinvoice[1];?></div></td>
<td><div><?php echo $date[1];?></div></td>
<td><div><?php echo $in[1];?></div></td>
<td><div><?php echo $out[1];?></div></td>
<td><div><?php echo $total[1];?></div></td>
</tr>
</table>

</body>
</html>

Thanks again for the help
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: php variable displayed in DIV tag

Post by JakeJ »

You're new so it's understandable. In the future, when posting code, please place it between the PHP Code tags so it's more readable. You'll find the button on the tool bar above the message compose box.

The first thing you should do is to make sure your variables actually contain data. Since there doesn't appear to be anything wrong with your code in terms of sticking it in the div tags, I suspect your variables are simply empty which means the real problem is whether or not your array is populated and that might come down to whether or not you're opening your file properly and what's it in it.

I'm not sure why you think you need <div> tags between you <td> tags. You can eliminate those but they're not hurting anything.
Post Reply