0

I want to display the result from the file directory. It did display the result, however, it was all in one line which I didn't intend that to happen. I want it to display the result on the specific part.

I got this error for example

Position ID: P0007 IT CEO Hello 01/10/13 full time fixed term Post ---


Notice: Undefined offset: 1 in /home/students/accounts//hit3323/www/htdocs/jobassign1b/searchjobprocess.php on line 56
Title:



Notice: Undefined offset: 2 in /home/students/accounts//hit3323/www/htdocs/jobassign1b/searchjobprocess.php on line 59
Description:


Notice: Undefined offset: 3 in /home/students/accounts//hit3323/www/htdocs/jobassign1b/searchjobprocess.php on line 62

I wanted for example

Position ID: P0007 Title: IT CEO Description: Hello

this is the php code, any suggestions? Thank you in advance

<?php

if(!empty($_GET["jobtitle"]))
{
umask(0007);                                    
$directory = "../../data/jobposts";             // path to directory
if(!is_dir($directory))
{
    mkdir($directory, 02770);
}

$data = $directory. "/jobs.txt";                // checking file in the directory
$opening = fopen($data, "r");                   // opening the file in reading mode

$dirFile = file_get_contents($data);
if(strpos($dirFile, $_GET['jobtitle']) === false)  // checking the user file exist or not
    {

    echo "<p>Job Title does not exist in the file</p>";
    echo '<a href="searchstatusform.php">Search another Job Title</a><br />';
    echo '<a href="index.php">Return to homepage</a>';

    }

    else

    {

    $array = file($data);
    $jobString = $_GET['jobtitle'];
        foreach($array as $key => $value) 
        {
        $get = strpos($value, $jobString);    // getting the key value of the array containing status record            
        if ($get !== false)
            {
                $file2 = $key; 
                $array2 = $array[$file2];
                $newArray = explode("\t", $array2);   //using explode and \t to create a new line
                $i = 0;
                echo "<h1> Job Vacancy Information</h1>";
                echo "<p>Position ID: $newArray[$i]</p>";     //displaying the results
                $i++;

                echo "<p>Title: $newArray[$i]</p><br />";
                $i++;

                echo "<p>Description: $newArray[$i]</p>";
                $i++;

                echo "<p>Closing Date: $newArray[$i]</p>";
                $i++;

                echo "<p>Position: $newArray[$i]</p>";
                $i++;

                echo "<p>Application by: $newArray[$i]</p>";
                $i++;

                echo "<p>Location: $newArray[$i]</p>";
                $i++;

                for($i;$i<(count($newArray)-1);$i++)
                {
                echo"<p id=p>$newArray[$i]</p>";
                }
                echo "</ul>";
                echo '<a href="searchjobform.php">Search again a new status</a>';
                echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                echo '<a href="index.php">Return to homepage</a></p>';
                }
            }
        }
    }
    else 
    {
        echo "<p>Enter a valid job to search</p>";
    }
?>
mleko
  • 11,650
  • 6
  • 50
  • 71
Tyler Matema
  • 65
  • 1
  • 3
  • 9
  • Notices are usually a sign that your code is doing something you didn't consider. It's usually a good idea to start looking at the line generating the notice, and if that looks correct - look at the code where the variable used is set (the most recent assignment is usually what you're looking for). If that looks okay too, print_r/var_dump the variable like Greg suggests below. – illuzive Oct 01 '13 at 07:02
  • possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – mleko Jun 29 '14 at 06:57

1 Answers1

1

its saying that the elements that $i is pointing to don't exist.

one thing you learn pretty quickly with php is to write code in baby steps so the first thing you need to make sure of is that $newArray contains what you think it does.

try outputting $newArray to the screen to see whats actually in the array, sounds like its empty. Right after you assign $newArray, put this line:

print_r($newArray);

Also, not sure why you are bothering with $i++ when you can just replace $i with the number of the element you want to appear, for instance...

echo "<p>Position ID: $newArray[0]</p>";     //displaying the results
echo "<p>Title: $newArray[1]</p><br />";
echo "<p>Description: $newArray[2]</p>";
echo "<p>Closing Date: $newArray[3]</p>";

Post the output of $newArray then we can work out what code goes next.

cheers

Greg J

Greg J
  • 189
  • 2
  • 9