Page 1 of 2
Newbie help
Posted: Mon Oct 27, 2003 4:57 pm
by johnperkins21
I am quite new to php and am in the process of designing a fairly simplistic image gallery. However, I am having some problems from the outset. My code just does not seem to work. Can someone please offer some advice.
Here is the code:
<?php
$images[] = "openhouse01.gif";
$images[] = "openhouse02.gof";
?>
<img src = "<?php echo $images[1]; ?>" width = "150" height = "100">
The images exist in the same folder as the php page, however I get the box without an image in it for some reason. Taking out the php and just using:
<img src ="openhouse01.gif" width = "150" width = "100">
works fine.
Any help would be greatly appreciated,
John Perkins
Posted: Mon Oct 27, 2003 5:03 pm
by m3rajk
becasue you can't add to a non-pre existing array like that.
http://php.net
look up
echo and the heredoc syntax and
arrays.
and one last thing (stolen from volka, i shoul d give him credit), youmight wanna read:
http://www.catb.org/~esr/faqs/smart-questions.html
Posted: Mon Oct 27, 2003 5:33 pm
by johnperkins21
Okay, took out array:
<?php
$images = "openhouse01.gif";
?>
<img src = "<?php echo $images; ?>" width = "150" height = "100">
Still no image. Thanks again for the help.
John Perkins
Posted: Mon Oct 27, 2003 5:38 pm
by Gen-ik
m3rajk wrote:becasue you can't add to a non-pre existing array like that.
....erm...... you can you know. I code like that all the time and it works fine.
Code: Select all
<?
$test[] = "Apple";
$test[] = "Banana";
$test[] = "Coconut";
foreach($test as $key => $food)
{
echo "{$key} is a {$food}<br>";
}
?>
Posted: Mon Oct 27, 2003 5:40 pm
by Gen-ik
johnperkins21 wrote:Okay, took out array:
<?php
$images = "openhouse01.gif";
?>
<img src = "<?php echo $images; ?>" width = "150" height = "100">
Still no image. Thanks again for the help.
John Perkins
It's not a PHP problem. That code looks fine.
Make sure the image names are correct, make sure the page has a .php extension, and make sure the page is running on a server.
Posted: Mon Oct 27, 2003 5:43 pm
by m3rajk
Gen-ik wrote:m3rajk wrote:becasue you can't add to a non-pre existing array like that.
....erm...... you can you know. I code like that all the time and it works fine.
Code: Select all
<?
$test[] = "Apple";
$test[] = "Banana";
$test[] = "Coconut";
foreach($test as $key => $food)
{
echo "{$key} is a {$food}<br>";
}
?>
i thought you had to create an empty array first or it would overwrite.
johnperkins21 -- i love how you actually read what i wrote. now try actually doing as i advised, infact, try the links i put in there so you wouldn't have to search. i left the choice of seeing the link up to you, not taking it looks like you want us to do YOUR work of scripting this.
if pages are linked with suggested reading, either state why you feel it's irrelevant in your response or read it. without that you basically slight whoever gives it, which is rude, and if you're a newb and someone who's been here a while wants to give you their time to do that they shouldn't see themselves slighted. it's irksome
Posted: Mon Oct 27, 2003 5:44 pm
by johnperkins21
That's what I thought. I'm pretty sure the array was right too. I changed that from $images = array ("openhouse01.gif","openhouse02.gif") just to try something new. The server is ok, and I'm saving as .php, just no image shows up. It is very strange and difficult to troubleshoot.
Thanks for helping me believe that I am not super lame and completely misunderstanding how to code.
Posted: Mon Oct 27, 2003 5:50 pm
by johnperkins21
m3rajk,
I'm sorry if you felt slighted. I did read the links, before I posted I went through the PHP manual. The reason I posted is because from what I understand from the links you provided is that my code is correct. I do not want anybody to write the script for me, if I did there are many places I can go to download what I want and alter it to suit my needs. I'm trying to learn but am having problems with my scripting. It seems to be an issue with my computer/server rather than my code. But since I am quite new to PHP, I thought someone here would be nice enough to help me out. And I was right. I do greatly appreciate your help, and apologize if I seemed rude.
Posted: Mon Oct 27, 2003 5:55 pm
by m3rajk
well double check that the second image isn't a blank image.
because you ask for... accroding to your first post "openhouse02.gof" and according to your last "openhouse02.gif"
which one is it? or did you want the first? in which case you still need to read up on arrays, because you're not thinking of them as a computer does.....the world does not start at 1, but rather 0
try
Code: Select all
<?php
$images=array();
$images[] = 'openhouse01.gif';
$images[] = 'openhouse02.gif';
echo <<END
<img src = "{$images[1]}" width = "150" height = "100">
END;
?>
Posted: Mon Oct 27, 2003 5:59 pm
by m3rajk
johnperkins21 wrote:m3rajk,
I'm sorry if you felt slighted. I did read the links, before I posted I went through the PHP manual. The reason I posted is because from what I understand from the links you provided is that my code is correct. I do not want anybody to write the script for me, if I did there are many places I can go to download what I want and alter it to suit my needs. I'm trying to learn but am having problems with my scripting. It seems to be an issue with my computer/server rather than my code. But since I am quite new to PHP, I thought someone here would be nice enough to help me out. And I was right. I do greatly appreciate your help, and apologize if I seemed rude.
apology accepted.
next time mention reading it.
heredocs are actually easier in the long run with long stretches, trust me i learned the hard way.
do you get any warnings on the page? have you double chacked that it's in a directory that the server software feels is a web directory?
Posted: Mon Oct 27, 2003 6:01 pm
by JAM
Also tried the code in the original post, and it works. If you do not have the images in the same directory as the file running the script, it will not work. Perhaps obvious, but...
Using a browser that do not support spaces between src = "... etc?
httpd.conf rules that rewrites image filenames, treating them as something else?
Wierd ideas, but the only things I can think of that messes this up. Odd issue but good luck.
Posted: Mon Oct 27, 2003 6:14 pm
by johnperkins21
You're absolutely right, it was misspelt, and I was looking for the second image [1]. But I know that it was right most of the times I did it (I've rewritten the code about 10 times in at least 3 different ways). I do have quite a bit more to learn about arrays and php in general. I thought I had learned enough to write this simple script, but it just doesn't seem to work for me.
I tried your suggest code and received the following output:
END; ?>
Apparently it is a server issue. PHP was working fine on there Friday, but now it seems wanked. If PHP isn't working then HTML would receive "" for an image source and I would get no photo. It's got to have something to do with Dreamweaver screwing up my file or something. Thanks for the help all. I do greatly appreciate the help and look forward to learning PHP.
Posted: Mon Oct 27, 2003 6:17 pm
by m3rajk
there was a missing < so it looked for img as the end instead of END
Code: Select all
<?php
$images=array();
$images[] = 'openhouse01.gif';
$images[] = 'openhouse02.gif';
echo <<<END
<img src = "{$images[1]}" width = "150" height = "100">
END;
?>
Posted: Mon Oct 27, 2003 6:33 pm
by johnperkins21
Apparently I should just give up. Now I just get a blank page. I tried another php page in the same directory and it works fine (another image gallery that I d/l to get ideas). It is very strange.
For the record:
Server is Red Hat 8 running Apache 1.3.22 with PHP 4.3.2.
Using IE 6.0.2 locally to view and Dreamweaver to edit the files directly on the server (just switched to Wordpad though 10 minutes ago). Local machine running WinXP completely updated. If you guys have any ideas, I'd be happy to hear 'em.
Posted: Mon Oct 27, 2003 6:38 pm
by d3ad1ysp0rk
whats the URL?