Translate PHP script to read CSV file and return echo multiple times
P粉127901279
P粉127901279 2023-08-06 19:24:52
0
1
517

I have written a PHP script that reads a CSV file and publishes the resulting radio schedule on a website based on time and date. However, it appears it will be released twice.

The following is the script content:


= $time) { $filteredData[] = $row; } } // Step 5: Display the filtered data with CSS classes for each row if (count($filteredData) > 0) { foreach ($filteredData as $row) { echo "
"; echo "
"; echo ""; echo "
"; echo "
"; echo "

$row[2]
$row[3]

"; echo "
"; echo "
"; } } else { echo 'Not available.'; }

This is the data I tested with in a CSV file:

Friday,12,MMV,until 1pm,top_mmv.png Friday,13,MMV,until 2pm,top_mmv.png Friday,14,MMV,until 3pm,top_mmv.png Friday,15,MMV,until 4pm,top_mmv.png

But when it gets to 2pm on Friday, it posts both the 1pm and 2pm rows. What did I do wrong?

P粉127901279
P粉127901279

reply all (1)
P粉481815897

You need to specify the conditions for collecting data,

if ($day === $currentDay && $Hour >= $time) {

For example, the current time now is 14 o'clock (add 1 hour is your adjustment).

$Hour >= $time

15 >= time from first line of csv is 12 - true 15 >= time from second line of csv is 13 - true 15 >= time from third line of csv is 14 - true 15 >= 15 - true

I think you can see where the problem is.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!