PHP problem need help with
I'm still learning the ropes of PHP but its a fun language.
OK what I am doing is making a picture site without a database (why - i have no idea), i got the linking and displaying of the 2000 pics to work with only two pages for the entire site but what i am stuck with is trying to make a "back" and "forward" link to refer to the previous or following image as i'll have no way of knowing which image they choose to view first.
this is what i have so far, if it helps:
second page:
I tryed adding an id into the name but cant figure out how to get it to look back at the first page from the second, with a database would be easy but there must be a way to do this
for some reason i keep trying to get something like this to work (in laymams terms)
if id is not equal to id, then id++, then reload in self (PHP_SELF)
to go forward one, or id-- to go back one
but all i end up with is a link to the id number .php
any ideas? or solutions?
Peter J. Boettcher posted this at 13:08 — 29th August 2001.
They have: 812 posts
Joined: Feb 2000
Another approach might be just to use the JavaScript back() and forward() methods.
I know it's not a PHP solution but it might be simpler.
Mark Hensler posted this at 23:34 — 29th August 2001.
He has: 4,048 posts
Joined: Aug 2000
If you make all your image names numeric, it would be easy.
You could make an array with all the filenames, but 2,000 images makes this very undesirable.
Mark Hensler
If there is no answer on Google, then there is no question.
Busy posted this at 01:23 — 30th August 2001.
He has: 6,151 posts
Joined: May 2001
you mean history-1 etc? but if they clicked say number 5 from the list they wouldnt have a forward and back would be the index.
could I break an array into, say 50 or 100 arrays and call it from one field?
I might try naming the images by numbers like you mentioned and calling the next and previous by that, other than that I guess I have to use a database
Thanks
Busy posted this at 06:12 — 1st September 2001.
He has: 6,151 posts
Joined: May 2001
I'm sturbon and am determined to solve this
I've added another page with the list of links with an id=1001 (increasing in number down the list) I can get the second page to see this id number and then add one displaying the next one, I cant however get this id number to show as the item it is.
for the next link on the second page, i have:
<?php
include("addtodisplaylist.php");
if ($id == $id)
{
$id = $id + 1;
//echo("<a href=\"");
echo ("h$id") ;
//echo("\">Next</a>");
}else{
echo("<a href=\"listpic.php\">list pictures</a><br>");
}
?>
for the third page (addtodisplaylist.php), i have:
<?php
$h1001 = ('<br><a href="displaypic.php?name=water-texture&width=160&height=140&id=1001">pic 1</a>');
$h1002 = ('<br><a href="displaypic.php?name=graph&width=160&height=140&id=1002">pic 2</a>');
$h1003 =
......
?>
the links on the first page are the same as the third, but have assigned them to $h1001, $h1002 etc
instead of it displaying h1002, how can I associate it to the link needed?
I think I need to add "h" into the $id, making it $h1002 etc as all i'm doing so far is just printing the h1002, not the var itself, $h$id doesnt work, $h + $id doesnt work
**I just know i'll be bald before I figure this out :)**
Mark Hensler posted this at 07:45 — 1st September 2001.
He has: 4,048 posts
Joined: Aug 2000
What your looking for is this:
<?php
echo ${\"h\".$id};
?>
I would do this:
<?php
//second page
include(\"addtodisplaylist.php\");
if (ereg(\"^[0-9]*$\",$id)) {
//the ereg() makes sure that $id is numeric
$id++;
echo ${\"h\".$id};
}
else {
echo(\"<a href=\\"listpic.php\\">list pictures</a><br>\");
}
//third page (addtodisplaylist.php)
$i=1000;
$image[++$i] = ('<br><a href=\"displaypic.php?name=water-texture&width=160&height=140&id=$i\">pic 1</a>');
$image[++$i] = ('<br><a href=\"displaypic.php?name=graph&width=160&height=140&id=$i\">pic 2</a>');
$image[++$i] =
....
?>
You can read more about variable variables here.
Good Luck,
Mark Hensler
If there is no answer on Google, then there is no question.
Busy posted this at 00:24 — 2nd September 2001.
He has: 6,151 posts
Joined: May 2001
Mark, Thanks, I tried what you suggested but it didnt work
I don't understand all that ereg stuff yet but shouldnt somewhere in there point to $i ?
on the first page do I asign the id to 1001 or h1001 ? (tryed both, neither worked) also wouldnt the id on the first page have to be the same as the third page?
I realise this is going to end up as one massive array which you have mentioned becoming very undesirable.
should I carry on pursueing this, or just learn databases, I am learning a lot of what not to do doing this lol
Mark Hensler posted this at 01:01 — 2nd September 2001.
He has: 4,048 posts
Joined: Aug 2000
I'm sorry, I forgot about the 'h' on page 3. Do you need the 'h'? I would work better without it.
with 'h'
<?php
//second page
include(\"addtodisplaylist.php\");
if (ereg(\"^[0-9]*$\",$id)) {
//the ereg() makes sure that $id is numeric
$id++;
echo ${\"h\".$id};
}
else {
echo(\"<a href=\\"listpic.php\\">list pictures</a><br>\");
}
//third page (addtodisplaylist.php)
$i=1000;
$image[\"h\".++$i] = ('<br><a href=\"displaypic.php?name=water-texture&width=160&height=140&id=h$i\">pic 1</a>');
$image[\"h\".++$i] = ('<br><a href=\"displaypic.php?name=graph&width=160&height=140&id=h$i\">pic 2</a>');
$image[\"h\".++$i] =
....
?>
without 'h'
<?php
//second page
include(\"addtodisplaylist.php\");
if (ereg(\"^[0-9]*$\",$id)) {
//the ereg() makes sure that $id is numeric
$id++;
echo $id;
}
else {
echo(\"<a href=\\"listpic.php\\">list pictures</a><br>\");
}
//third page (addtodisplaylist.php)
$i=1000;
$image[++$i] = ('<br><a href=\"displaypic.php?name=water-texture&width=160&height=140&id=$i\">pic 1</a>');
$image[++$i] = ('<br><a href=\"displaypic.php?name=graph&width=160&height=140&id=$i\">pic 2</a>');
$image[++$i] =
....
?>
For both examples above, $id should be numeric (only numbers, no letters). The ereg() function searches $id for the pattern I specified, and returns true if the pattern is found to be true, and false if not. The pattern I specified requires that the value contains only the numbers 0 through 9, and no other characters (letters, punctuation, spaces, etc.).
I would highly recommend learning to use a database. It would make this a whole lot easier to maintain, and you can apply that DB knowledge elsewhere.
Mark Hensler
If there is no answer on Google, then there is no question.
Busy posted this at 03:02 — 2nd September 2001.
He has: 6,151 posts
Joined: May 2001
Thanks,
that works the same way as what i had, displaying the increased id number by one, what I was aftr was it displaying the link connected to that id number.
I do need to learn databases, I was just hoping I could get a good grasp of PHP before learning another language.
<?
if(Mark == big help){
echo("Thanks");
}else{
blow a raspberry
}
?>
Thanks
**I'm sure the more I learn, the more I forget**
Mark Hensler posted this at 03:06 — 2nd September 2001.
He has: 4,048 posts
Joined: Aug 2000
sorry....
<?php
// with 'h'
//change:
echo ${\"h\".$id};
//into
echo $image[\"h\".$i];
// without 'h'
//change:
echo $id;
//into
echo $image[$i];
?>
Mark Hensler
If there is no answer on Google, then there is no question.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.