WillPower TJ
Active Member
Hello everyone.
I am new to PHP and i came across this really strange problem which i tried everything in my power to fix it but could not.
So basically i have this text file("content.txt") and the PHP script is supposed to generate a html page (i.e. images, text,headings...etc) from the data provided in the text file. The text file reads as follows;
On the PHP code,i read each individual line in ("content.txt") file and store it as an array element (on $ArrayFile[] ) and as you notice, i separated each important item with a tilde symbol(~) in the text file ,so now i just store any data before the ~ symbol into a new array ($itemData[] ), where each element in $itemData[] will contain links,source directory of images,headings ....etc.
But now what is "strange" and "weird" is that the first two images do not show. OK let me show you guys the PHP first,
i call the PHP using GET like http://pacdroids.tk/game/index.php?pg=1&load=0
The path to the images is correct by the way. I even tried moving the first line of data in content.txt to be the last line and moved the last line to the top, now the last line would print the image( which let me to thinking the problem can't be part the image source location).
I need help guys, i spent hours trying to spot the error but i found nothing ! any suggestion will do.
BTW i dont have any knowledge on databases, that's why i use text files. I was planning on learning as i go.
Thank you
I am new to PHP and i came across this really strange problem which i tried everything in my power to fix it but could not.
So basically i have this text file("content.txt") and the PHP script is supposed to generate a html page (i.e. images, text,headings...etc) from the data provided in the text file. The text file reads as follows;
city Racing 3D~'../reviews/cityRacing3D.html'~'images/cityRacing3D.jpg'~<a href='racing.php?pg=1&load=0'>Racing</a>~<a href='publishers/3DGames.html'>3DGames</a>~42Mb~Free
Final Fantasy~'../reviews/ff3.html'~'images/ff3.jpg'~<a href='rpg.php?pg=1&load=0'>Role playing Game (RPG)</a>~<a href='publishers/square.html'>Square</a>~178.84mb~R132.00
WipeOut~'../reviews/wipeout.html'~'images/wipeout.jpg'~<a href='adventure.php?pg=1&load=0'>Adventure</a>~<a href='publishers/activision.html'>Activision Publishing, Inc</a>~35Mb~Free
.
.
.
.
repeats like this
On the PHP code,i read each individual line in ("content.txt") file and store it as an array element (on $ArrayFile[] ) and as you notice, i separated each important item with a tilde symbol(~) in the text file ,so now i just store any data before the ~ symbol into a new array ($itemData[] ), where each element in $itemData[] will contain links,source directory of images,headings ....etc.
But now what is "strange" and "weird" is that the first two images do not show. OK let me show you guys the PHP first,
i call the PHP using GET like http://pacdroids.tk/game/index.php?pg=1&load=0
Code:
<?php
$loaded =$_GET['load'];
$arrayFile = file("indexData.txt");
if ( isset($loaded) && is_numeric( $loaded )) {
$printed = 0; // i use this to keep track of how many <li>'s were printed , should not exceed 4
for ($loaded; $loaded < count( $arrayFile); $loaded++) {
$ItemData = explode("~", $arrayFile[$loaded]);
echo ("<li><a href =".$ItemData[1]."> <h3>".$ItemData[0]."</h3></a>");
echo ("<a href =".$ItemData[1]."> <img src =".$ItemData[2]." width='220' height='134' align='left' alt=".$itemData[0]."> </a>");
echo ("<p class='format'>"."Genre(s) :".$ItemData[3]."<br>".
"Publisher(s) : ".$ItemData[4]."
<br>"."Price on Google Play :".$ItemData[6].
"<br>"."Game file size = ".$ItemData[5]."<br></p></li>");
$printed++;
if ($printed==4) {break;};
}; //end of for loop
//The above code is where the stated problem ends, You can pause here is you want.
// the following code was to let you move around previous and next page
// and remember what you printed on the previous page and not show it again.
// But it is incorrect and does not work properly.
$page =(int)$_GET['pg'];
$lastPage= ceil( count($arrayFile)/4 );
$prevPage = $page -1;
$nextPage = $page + 1;
if ($page ===1) {
$prevPage=null;
};
if ($page ===$lastPage) {
$nextPage=null;};
if ($prevPage!==null) {
$loaded-=3;
echo "<a href='index.php?page=$prevPage&load=$loaded' style='font-size:1.3em;font-weight:800;'>Prev </a>";
};
if ($nextPage!==null) {
echo "<a href='index.php?page=$nextPage&load=$loaded' style='margin-left:100px;font-size:1.3em;font-weight:800;'>Next </a>";
};
} //end of isset if statement
else{
echo "Error";}
?>
The path to the images is correct by the way. I even tried moving the first line of data in content.txt to be the last line and moved the last line to the top, now the last line would print the image( which let me to thinking the problem can't be part the image source location).
I need help guys, i spent hours trying to spot the error but i found nothing ! any suggestion will do.
BTW i dont have any knowledge on databases, that's why i use text files. I was planning on learning as i go.
Thank you
Last edited: