TeamPhotoshop
Reviews, updates and in depth guides to your favourite mobile games - AppGamer.com
Forum Home Latest Posts Search Help Subscribe

a tall order... lol

Page: 1 2 Reply
Dec 18th 2003#134084 Report
Member since: Mar 29th 2003
Posts: 1326
OK - thats not exactly at my level. Maybe I'll try to make something similar, but I probably won't worry about inter-page navigation.

But I will need to understand how you create the show.php?comic=2 part. How does that work?

tom
Reply with Quote Reply
Dec 18th 2003#134087 Report
Member since: Nov 6th 2001
Posts: 240
ok, I'll try to explain...

When a new file is uploaded I save the img_name, a description and a datestamp to a text file called data.dat, i separate the data with "||" so it looks like this:

img_1071776917.png||description file 1||1071776917
img_1071777045.png||description file 1||1071777045

that's for saving the info, now the showing.

I use one php file called show.php to display the images. When the page is loaded I load all data in an array:

[PHP]
// create a handle for the file
$fh = fopen($db_file "r");
// read the data
$data = fread($fh, 4096);
// create an array $data, the data in the file
// is split in lines
// each split now looks like this:
// $data[0] = "img_1071776917.png||description file 1||1071776917";
// $data[1] = "img_1071777045.png||description file 1||1071777045";
$data = explode("\n",trim($data));
[/PHP]

reversing the array (so the most recent image is the first image) and counting the number of images.

[PHP]
// count the images
$num_comics = count($data);
// reverse array, so most recent image -> 1
$data = array_reverse($data);
[/PHP]

next I'm going to split the $data array in a new array...
[PHP]
// set image counter
$i=1;
foreach ($data as $line) {
// split each line in 3 parts (image name, description and datestamp)
$line_data = explode("||",$line);

// now fill the img_array
// each element will look like this
// $img_array[1]['img'] = "img_1071776917.png"
// $img_array[1]['desc'] = "description file 1"
// $img_array[1]['date_stamp'] = "1071776917"
// this will be the case for each image...
$img_data[$i] = array (
"img" => $line_data[0],
"desc" => stripslashes($line_data[1]),
"date_stamp" => $line_data[2]
);

$i++;
}
[/PHP]

Now we have all the data we want, on to the navigation:

[PHP]
// if the $comic var is not set, we show comic #1, our first
// image
$comic = isset($_GET['comic']) ? $_GET['comic'] : 1 ;

// the next comic is the current comic + 1, previous comic
// is the current - 1
$next_comic = $comic + 1;
$prev_comic = $comic - 1;

// defining the next and previous links
// if the comic # is bigger than the total number of comics we're
// viewing the last image so our next_link is empty
$next_link = $comic >= $num_comics ? "" : ">>";

// if the comic # is smaller than 2 than we're seeing the first
// comic and the previous link is empty
$prev_link = $comic < 2 ? "" : "<<";
?>
[/PHP]

To display the image:
the $GLOBALS['rel_img_loc'] var (see config.inc.php file) contains the folder where the images are located, $img_data[$comic]['img'] contains the name
of the current image. You can also show a thumb, the image description and the date/time the image was added:

$GLOBALS['rel_img_thumb_loc'] -> thumbs folder

$img_data[$comic]['img'] -> name of image
$img_data[$comic]['desc'] -> image description
$img_data[$comic]['date_stamp'] -> date

[PHP]
print "
[/PHP]

Hope this will clear some things up... (sorry about my English)
Reply with Quote Reply
Dec 19th 2003#134103 Report
Member since: Jun 3rd 2003
Posts: 1867
Wow dude! That's fux0ring perfect!

and btw I don't mind using mysql... lol

just as long as it works... and that seems to work awesome


Only thing is that there have to be 2 updates boxes, not 1 like in yours...

would you mind if i used that code, or some form of it, in my site? If i am able to do it? lol

I'd really appreciate it and you'd totally get credit.


One more thing, should i finish building the site in html before implementing PHP?

Thanks guys a lot especially qtone, you are the man :D
Reply with Quote Reply
Dec 19th 2003#134164 Report
Member since: Nov 6th 2001
Posts: 240
Sure, you can use the code, but since you can make use of a mysql database, I'd use that...
Reply with Quote Reply
Dec 20th 2003#134258 Report
Member since: Jun 3rd 2003
Posts: 1867
k. One more question, can I go ahead and implement the site into html now, and then do the php later on?
Reply with Quote Reply
Dec 20th 2003#134292 Report
Member since: Jul 19th 2003
Posts: 810
I find it easier (in the little php experience i've had) to put all the components into different files, e.g
that picture script into one file
Your HTML site into other pages......

then, when your HTML layout and all the rest of the HTML stuff is done, Put the PHP where you want it

It is less confusing because everything is set out neatly and not in a whole 500 or so lines of code!!
Reply with Quote Reply
Dec 23rd 2003#134608 Report
Member since: Jun 3rd 2003
Posts: 1867
Thanks a lot lazy, as well as everyone else!

Webcomic coming up this january! (If i figure out the php!) I promise! :D
Reply with Quote Reply
Page: 1 2 Back to top
Please login or register above to post in this forum