Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if else in php

Status
Not open for further replies.

999000333

Programmer
Nov 20, 2006
39
Hello again,
is it possible to assign to the images redball.jpg and greenball.jpg a link, the way I did it does not work..can anyone tell me how to write the code so I can output the image and allow the user to click on it and go to another page?

<?php
if (!( $row_Elenco['DocNum'])){
echo "<a href="../admin/articoli.php">
<IMG SRC='../redball.jpg' ALT='Aperto'>";

} else {
echo"<a href="../admin/user.php">
<IMG SRC='../greenball.jpg' ALT='Chiuso'>";
}
?>

Thanks
Paola
 
Change all inner double quotes to single quotes:
Code:
<?php
if  (!( $row_Elenco['DocNum'])){
echo "<a href=[red]'[/red]../admin/articoli.php[red]'[/red]>
<IMG SRC='../redball.jpg' ALT='Aperto'>";

} else {
echo"<a href=[red]'[/red]../admin/user.php[red]'[/red]>
<IMG SRC='../greenball.jpg'  ALT='Chiuso'>";
}
?>



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
To vacunita

Again you have been of GREAT HELP....

You saved me lots of time and grief...
as you can tell I' m kind of new to php. But eh!! I learned to precious things today!!

Thanks
Paola
 
Actually, I would have recommended exactly the opposite, changing the OUTER quotes to singlequotes:

Code:
if  (!( $row_Elenco['DocNum']))
{
	echo '<a href="../admin/articoli.php"><IMG SRC="../redball.jpg" ALT="Aperto">";

}
else
{
	echo '<a href="../admin/user.php"><IMG SRC="../greenball.jpg"  ALT="Chiuso">';
}
?>

Keeping in mind the differences between single and double quotes in general, particularly variable interpolation:
Canonically, HTML uses doublequotes. While I know of no browser that will barf on singlequotes around attrtibute values in HTML, there are some more pedantic interpretations of the XHTML spec.


Want the best answers? Ask the best questions! TANSTAAFL!
 
sleipnir214 said:
Canonically, HTML uses doublequotes. While I know of no browser that will barf on singlequotes around attrtibute values in HTML, there are some more pedantic interpretations of the XHTML spec.
Actually, AFAIK the need to use double quotes in even the most pedantic XHTML spec is just a myth. There is no official documentation that supports that -- all it says is that all attributes need to be quoted.
 
Even so, HTML does still canonically uses doublequotes around all its attribute values. Recommending conversion of all interior quotes to singlequotes, thus passing the singlequotes to the HTML stream, seems a suboptimal solution to give to a new programmer.


Want the best answers? Ask the best questions! TANSTAAFL!
 
It might seem so, but As you mentioned. PHP variables will not get interpreted inside single quotes normally. This will cause more confusion than passing single quotes to HTML.

Its the slightly wrong approach for the easier use.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
The code posted had no variables to interpolate and PHP programmers need to be aware of the differences in behavior between singlequotes and doublequotes.

Also, I am not at all a fan of expediency when providing code to new programmers. In the long run, the new programmer is better off being given the best possible example, even if it means bundling some additional topics in the answer.


Want the best answers? Ask the best questions! TANSTAAFL!
 
So right. but alas its done and corrected.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top