0

EDIT: I call the function writecol() further down the page inside <table></table> tags.

Example of data in trxtt.txt:

South East asia,2222,code1

winter break,3333,code2

I am fairly new to php. I am trying to dynamically build table rows based off the variables read from an array. When I call this function I do not receive and error message, but nothing happens. Any ideas what I am doing wrong?

$x = file_get_contents('textt.txt');
$y = explode("\r\n", $x);

function writecol(){
    foreach ($y as $value) {
        $z = explode(",", $value);
        echo "<tr class='visible'><td class='underlinecenter'>" . $z[0] . "</td> <td></td> <td colspan='3' class='underlinecenter'>" . $z[1] . "</td><td></td><td colspan='3' class='underlinecenter'>" . $z[2] . "</td></tr>";
    }   
}
1
  • Please give some sample data of textt.txt Commented Nov 21, 2011 at 16:21

4 Answers 4

2

You don't appear to be calling the function, nor is your function ready to receive the variable with data.

after $y = explode.... insert: writecol($y);

Then replace function writecol(){ with

function writecol($y){

Sign up to request clarification or add additional context in comments.

Comments

0

Well...you never actually call the function. Therefore PHP just doesn't know that you intend it to use the function on the array you created. Additionally, you should add a parameter to your function, because from within writecol() your variable $y will not be visible.

Try it like this:

$y = explode(...);
function writecol($array) {
    foreach ($array as $value) { // your code }
}
writecol($y);

Comments

0

first make sure you have these on (put them at the top under the php tag) for testing so you can see errors

ini_set('display_errors','On'); 
ini_set('error_reporting', -1);

Beyond errors, you aren't calling the function. change your function and add a call:

function writecol($y){ # <-- pass a variable and call it $y
    foreach ($y as $value) {
        $z = explode(",", $value);

        echo "<tr class='visible'><td class='underlinecenter'>" . $z[0] . "</td> <td></td> <td colspan='3' class='underlinecenter'>" . $z[1] . "</td><td></td><td colspan='3' class='underlinecenter'>" . $z[2] . "</td></tr>";
    }   
}
writecol($y); #<-- function call sending the variable $y

Comments

0

You have to call the writecol() function

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.