p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: If Then and html


Message #1 by Jefferis Peterson <jefferis@p...> on Mon, 21 Oct 2002 16:00:07 -0400
Hi folks, 
I always get confused about this simple thing. When you are using PHP and
html/javascript, when do you turn single quotes to double and vice versa?

Bums me out that I can't keep this straight. Anyone have a mnemonic for it?

Anyway, here's what I want to do:
If an image has 3 views I want to print out extra cells in a table and show
the views. If not, I only want one cell .

So a query to my database  will return $views = 1 or $views = 3

I want to make the following conditional on 3 views.

If $views = 3 then print:

<td valign="middle">
<div align="center">
          <p><a href="#"  onclick="MM_openBrWindow('<?php echo
"show_image.php?img={$row_viewall['pictures']}"; $img 
$row_viewall['pictures'];?>','','toolbar=yes,scrollbars=yes,resizable=yes,wi
dth=550,height=500');return false"> <img src='<?php $t1 = ereg_replace ("A",
"B", $row_viewall['thumbnail']); echo $t1; ?>' alt="<?php echo
$row_viewall['item_name']; ?>" border="0"></a><br>
            Side View</div></td>
      <td valign="middle"><p align="center"> <a href="#"
onclick="MM_openBrWindow('<?php echo
"show_image.php?img={$row_viewall['pictures']}"; $img 
$row_viewall['pictures'];?>','','toolbar=yes,scrollbars=yes,resizable=yes,wi
dth=550,height=500');return false"><img src='<?php $t2 = ereg_replace ("A",
"C", $row_viewall['thumbnail']); echo $t2; ?>' alt="<?php echo
$row_viewall['item_name']; ?>" border="0"></a><br>
          Edge View</td>




So my question is, what's the best way to surround all this html text within
a php if/then function?

Jeff

Message #2 by "Gellings, C.O." <gellingsco@p...> on Wed, 23 Oct 2002 22:37:04 +0200
Jeff,

Sorry, I'll do this on the fly. Didn't take the time to read your code. I
usually let the function return true on succes ... (javascript) and set it
thus in PHP
short example
script bit ....
	function bSetImage(newnr1, newnr2, selected, location, centernr){
		document.images[selected].src = aImages[selected][2].src;
		document.images[newnr1].src = aImages[newnr1][1].src;
		document.images[newnr2].src = aImages[newnr2][1].src;
		document.images["centerimage"].src 
parent.topframe.solidlines[centernr].src;
		return true;
		}

PHP page bit ....
<? echo "<........ onMouseOver=\"return
bSetImage('pension','endurance','logement', 2, 1)\">" ?>

in normal HTML coding the params within the event are in quotes while the
event is set in double quotes
i.e. onMouseOver="....."
functionName('string_param','string_param', num_param,
num_param,'string_param', .......)

mth

Carl

-----Original Message-----
From: Jefferis Peterson [mailto:jefferis@p...]
Sent: 21 October 2002 22:00
To: beginning php
Subject: [beginning_php] If Then and html


Hi folks,
I always get confused about this simple thing. When you are using PHP and
html/javascript, when do you turn single quotes to double and vice versa?

Bums me out that I can't keep this straight. Anyone have a mnemonic for it?

Anyway, here's what I want to do:
If an image has 3 views I want to print out extra cells in a table and show
the views. If not, I only want one cell .

So a query to my database  will return $views = 1 or $views = 3

I want to make the following conditional on 3 views.

If $views = 3 then print:

<td valign="middle">
<div align="center">
          <p><a href="#"  onclick="MM_openBrWindow('<?php echo
"show_image.php?img={$row_viewall['pictures']}"; $img 
$row_viewall['pictures'];?>','','toolbar=yes,scrollbars=yes,resizable=yes,wi
dth=550,height=500');return false"> <img src='<?php $t1 = ereg_replace ("A",
"B", $row_viewall['thumbnail']); echo $t1; ?>' alt="<?php echo
$row_viewall['item_name']; ?>" border="0"></a><br>
            Side View</div></td>
      <td valign="middle"><p align="center"> <a href="#"
onclick="MM_openBrWindow('<?php echo
"show_image.php?img={$row_viewall['pictures']}"; $img 
$row_viewall['pictures'];?>','','toolbar=yes,scrollbars=yes,resizable=yes,wi
dth=550,height=500');return false"><img src='<?php $t2 = ereg_replace ("A",
"C", $row_viewall['thumbnail']); echo $t2; ?>' alt="<?php echo
$row_viewall['item_name']; ?>" border="0"></a><br>
          Edge View</td>




So my question is, what's the best way to surround all this html text within
a php if/then function?

Jeff




  Return to Index