Array - echo and php

Sorry, I forgot to mention that I’m using an external CSS.

I try to center doors and links below each door . I know that php allows html tags. To do so, we close php ?>, write html tags then re-open php. Am I right ?

So I’ve tried this, but it does not work !

[embed=425,349]<?php
if($nord[$piece] != -1){ ?>

<?php echo 'NORD'; } ?>[/embed]

To open/close PHP as you say, you just do it…

Remember PHP is handled on the server. It’s output is placed into the page where it is and then the combined
HTML is sent to the browser. Something like this in HTML:

Hello, <?PHP echo "some text..."; ?>, thank you…

Would send this HTML to the browser: Hello, some text…, thank you…
This means that your code you posted can be done either with stopping and starting the PHP or just making it
into an echo line. Here is one way it could be done…
[php]

<?PHP if($nord[$piece] != -1){ echo '
'; echo 'NORD'; } ?>

[/php]
NOTE: Please notice the quotes and double-quotes. You must close pairs of them in order. You can not do
it this way: ’ "… ’ " It must be this way: ’ “…” ’ This means it is tricky sometimes to sort that issue out!
Also, to pass a variable such as $nord[$piece] to a webpage using ?numpiece= , you do not need quotes for
the value if it is a number. You only need quotes if the value contains spaces…
Lastly, note the use of a period to “concatenate” parts of the string together with data.

Hope this helps…

[embed=425,349]echo ‘

’;[/embed] you’re right. I must be very tired.

I’ve tried the echo but still doesn’t work. May be I can try

only by closing and reopening ?> and <?php.

I tried something new :
[embed=425,349]<?php
$piece = 0;
if (isset($_GET[“numpiece”])) {
$piece = $_GET[“numpiece”];
}
?>

<?php echo "

{$indice[$piece]}

"; ?>
<?php if ($nord[$piece] != -1) { echo "
NORD"; } ?>[/embed]

No result.
Here’s the full code in attachments as you can see, it’s a simple and basic game.


Corrections.pdf (17.5 KB)

[php]if($nord[$piece] != -1){
echo ‘NORD’;
}[/php]

have you tried

[php]if($nord[$piece] != -1){
echo ‘NORD’;
}[/php]

I know , is supposedly saves space when php interrupts it, but in the past has caused me problems, so I just stick with the period (.). This probably isn’t the problem, but it would hurt to try?

I know , is supposedly saves space when php interrupts it, but in the past has caused me problems, so I just stick with the period (.). This probably isn’t the problem, but it would hurt to try?

I’ve already tried…
Never mind, i will try something help.
thank you anyway !

Well, danae, I changed all of your commas to periods and your code works on my server.
It allows me to move east to west and back again.

I think it works as you want it to. (But, not with those commas!)

Indeed ErnieAlex, it works for me too - both with commas and periods.
My problem is with CSS and php. I try to center doors and directions (below my doors). So here’s my code :

[embed=425,349]f($nord[$piece] != -1){
echo '<div id=“element1” '. $nord[$piece] . ‘">’;
echo ‘NORD’;
}[/embed]
I want my doors and directions aligned horizontally with links under.
To separate the directions from my doors do I need to exclude <img src=“door.png”… from the echo ’ <a href="…"… ?

Well, if you think of the page as a canvas and you place four

's on the page, they can be placed anywhere
on the page. But, normally, they are placed one after the other down the page. To fix this, you need to use the
“position” argument and tell the DIV that it is to be positioned in a fixed location on the page. Once you do that,
it will stay on the page where you want it.

Also, anything that you place in one of the DIV’s will be grouped together. So, the link will stay with the image if
you group them together in one DIV. I explained this earlier in the thread… If you want to just place them under
the rest of your display, you can place them into a table. The table would be 3x3 cells where you would use the
four in the middle of each side. Or, you can place on them on the page at the edges of all of the page like this:
[php]
if($nord[$piece] != -1){
echo ‘

’;
echo ‘NORD’;
echo ‘
’;
}
[/php]
You will need to do this for each direction. Test this by trying just this one room and moving south (sud) to
see it displayed. I used three echo’s to make it easier for you to read, but, could be just one…

Hope that helps…

I tried yesterday : doors and links were positioned on top.

Now everything is fine, it’s almost done. I use an external css file, it’s much better, I think.
My problem is the position of my doors and links. As you know, I want my links placed under the doors. But as they are all grouped together in one DIV, I need to place my png out of the div : your notes are so helpful, really. Table ? I do not how to manage this [embed=425,349]echo ’

'; [/embed] ? tr, td ?

Links :[embed=425,349]if($nord[$piece] != -1){
echo “<div id = 'echo2’NORD”;
}[/embed]. They are vertically centered not horizontally !
I tried the same thing with my image echo ’ <img src=“door.png” … it doesn’t work, I have a white page.

A table will be the best way, I think but it means I have to redo my the work !

I try to create a table :

[embed=425,349][embed=425,349]if($nord[$piece] != -1){
// Open the table
echo “

”;
echo “”;
echo “”;
echo ‘’;
echo “”;
// Close the table
echo “
NORD<img src=“door.png”’ . $nord[$piece] . ‘" alt=“door”>
”;
}[/embed]
[/embed]
I did this for each direction. Doors and links still not horizontally aligned. Links now are centered but above each door…
May be I need to create a [embed=425,349]
[/embed] ?

Change this section to the following… Note that you do not want to use

as it is a separate cell in a table.
You normally use the (table header) for long cols of data. For your use, just make it normal text and if you
want special formatting for it (such as colored backgrounds or bold text), then use CSS to make it pretty…

[php]
echo “

”;
echo “”;
echo “<img src='door.png alt=“door”>
”;
echo “NORD”;
echo “”;
echo “”;
[/php]
With this code, you have a table row. In that row, you have one cell square. In that cell, you have both the
image and the text for that one door. This example places the door at the top, uses
to move below the
picture and places the text under the door. You would reverse this to make the text above the door. For the
left-right door’s you would remove the
and place the text next to the image. I feel it is easier using the
DIV version I gave you before, but, the table is good, too. Either will work for you…

Why in the world are you echo’ing HTML?

[php]<?php if($nord[$piece] != -1): ?>

NORD door
<?php endif; ?>[/php]

I’ve tried this code : I’m getting a 500 server error message or a white page with safari !!

Is this actually supposed to be minus one?

!= [size=14pt]-[/size]1

yes != -1

I’ve also tried your code, it works but no image, no links !

What do you see in the “View Page Source” where it should be? Do you have error reporting turned on?

Now it works, I don’t know why !
The only problem is that my doors and links are still in a row (vertically). Links are not under. I use an external CSS but they are all placed on the left margin.

Well, Danae, I would just use the code that I gave you in an earlier post. Place the four doors inside of DIV tags
and set them where you want on the page…

Here is an example of how it could work for you…
[php]


NORTH
EAST
SOUTH
WEST
[/php] This will place the four doors at all four sides of the page. You need to alter the names as I used ENGLISH ones. You also need to add the check to display or not display them if the door does not exist. These are HTML lines, you would need to make them into echo's to display, but you will get the idea once you place them on your page and test...

Thank you so much ErnieAlex for your help, greatly appreciated.
Now it works fine !

Glad to hear that you solved it. See you in your next post…

Sponsor our Newsletter | Privacy Policy | Terms of Service