addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1light-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Re: [houston-php] Mix html with php vs php string.

From: user 1.
Sent on: Wednesday, October 13, 2010 8:21 PM
This is just a quick example 

<?php
/*
Brandon Bissoon
October 13, 2010
Example for PHP Group
*/

// <Insert Querying Script Here>  //

// Assuming $item = mysql_fetch_assoc($result)
// therefore $itemType = $item['Type'];
$Source = //<Declare Variable>//

// Declare Your Variables
$itemType = $item['type'];
$itemName = 'dyn'.$item['name'];
$itemValue = $item['value'];
$itemSource = $item['source'];
$sourceText = $source['text'];


switch($itemType)
{
case 'comboBox': 
echo '<select name="'. $itemName .'">'; 
// Default Option Label is 'Select A Value'
echo '<option value=''>{ Select A Value }</option>';
foreach($itemSource as $Source){
// For Every Item Source Add Option
echo '<option '; 
echo 'value="'.$sourceText.'" ';
// If Item Value Exist and Source Text is Equal to Item Value
// Make it the Selected Option
if (isset($itemValue) && $sourceText == $itemValue){
echo 'selected';
}
// Close Option and Add Label Equal to Source Text
echo '>'. $sourceText .'</option>';
endforeach;
}
echo '</select>';
echo '<br>';
break;
}
?>


Brandon R. Bissoon
Multi-Platform Developer / UX Architect

"A simple man believes anything, but a prudent man gives thought to his steps." (Proverbs 14:15)

--- On Wed, 10/13/10, Jonny Nguyen <[address removed]> wrote:

From: Jonny Nguyen <[address removed]>
Subject: Re: [houston-php] Mix html with php vs php string.
To: [address removed]
Date: Wednesday, October 13, 2010, 7:13 PM

The example I gave you was to simple to address the complexity. Here is my real concern.

<?php switch($item['type']):
    case 1: /* ComboBox */ ?>
    <select name='dyn<?php echo $item['name']; ?>'>
    <option value=''>{select a value}</option>
    <?php foreach($item['source'] as $source): ?>
    <option value='<?php echo $source['text']; ?>'<?php if(isset($item['value']) && ($source['text'] == $item['value'])) { echo ' selected'; }?>><?php echo $source['text']; ?></option>
    <?php endforeach; ?>
    </select><br/>   
    <?php break; ?>
   
    <?php case 2: /* Listbox */ ?>
    <select name='dyn<?php echo $item['name']; ?>[]' size='5' Multiple>   
    <?php foreach($item['source'] as $source): ?>
    <option value='<?php echo $source['text']; ?>'<?php if(isset($item['value']) && (in_array($source['text'], $item['value']))) { echo ' selected'; }?>><?php echo $source['text']; ?></option>   
    <?php endforeach; ?>   
    </select><br/>
    <?php break; ?>
   
    <?php case 3: /* Text Field */ ?>
    <input type='text' name='dyn<?php echo $item['name']; ?>' value='<?php if(isset($item['value'])) { echo $item['value']; }?>'/><br/>
    <?php break; ?>
   
    <?php case 4: /* Text Area */ ?>
    <textarea rows='5' name='dyn<?php echo $item['name']; ?>' cols='20'><?php if(isset($item['value'])) { echo $item['value']; }?></textarea><br/>
    <?php break; ?>

    <?php case 5: /* Radio Button */ ?>
    <?php foreach($item['source'] as $source): ?>
    <input type='radio' name='dyn<?php echo $item['name']; ?>' value='<?php echo $source['text']; ?>'<?php if(isset($item['value']) && ($source['text'] == $item['value'])) { echo ' checked';  }?>><?php echo $source['text']; ?><br/>
    <?php endforeach; ?>
    <?php break; ?>
   
    <?php case 6: /* Check Box */ ?>
    <?php foreach($item['source'] as $source): ?>
    <input type='checkbox' name='dyn<?php echo $item['name']; ?>[]' value='<?php echo $source['text']; ?>'<?php if(isset($item['value']) && (in_array($source['text'], $item['value']))) { echo ' checked';  }?>><?php echo $source['text']; ?><br/>
    <?php endforeach; ?>
    <?php break; ?>
       
    <?php case 8: /* Image */ ?>
    <img src="angry.gif" alt="Angry face" /><br/>
    <?php break; ?>
   
    <?php case 9: /* Category ComboBox */ ?>
    <h4><?php echo $item['title']; ?></h4>
    <select name='category' onchange="location = options[selectedIndex].value;">
    <option value='<?php echo $real_url . $routes['control']; ?>'>{select a value}</option>
    <?php foreach($item['source'] as $source): ?>
    <option value='<?php echo $real_url . $routes['control'] . DS . $source['option'] ?>'<?php if(isset($item['value']) && $source['option'] == $item['value']) { echo ' Selected'; } ?>><?php echo $source['text']; ?></option>
    <?php endforeach; ?>
    </select>
    <?php break; ?>
   
    <?php default: ?>
    <?php break; ?>
<?php endswitch; ?>

Please provide input on how to make this code more readable or better. My ears are yours


On Wed, Oct 13, 2010 at 3:06 PM, Sean Dundon <[address removed]> wrote:
Oh, absolutely mix the two of them.  Even better, declare all of your
variables and do your calculations at the top:

<?php
 $heading = 'Hello World';
?>
<html>
<head />
<body>
<h3><?=$heading?></h3>
</body>
</html>

Some people don't like the <?= tag, as it doesn't play nice with xml,
but in my experience it works great.  Now you have your logic
separated from your output, which is a much more peaceful way to live.

On Tue, Oct 12, 2010 at 5:50 PM, Jonny Nguyen <[address removed]> wrote:
> I need your input regarding mix html with php or just create a php string.
> See example below.
>
> 1. Html mix with php
> <html>
> <head></head>
> <body>
> <h3><?php echo 'Hello World'; ?></h3>
> </body>
> </html>
>
> 2. php string
> <?php
> strhtml = '<html>';
> strhtml .= '<head></head>';
> strhtml .= '<body>';
> strhtml .= '<h3>Hello World</h3>';
> strhtml .= '</body>';
> strhtml .= '</html>';
> echo strhtml;
> ?>
>
> thanks
>
> Jonny


--
Sean T. Dundon
[address removed]




--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
http://www.meetup.com/houston-php-users-group/
This message was sent by Sean Dundon ([address removed]) from Houston PHP Users Group.
To learn more about Sean Dundon, visit his/her member profile: http://www.meetup.com/houston-php-users-group/members/4591778/
To unsubscribe or to update your mailing list settings, click here: http://www.meetup.com/houston-php-users-group/settings/
Meetup, PO Box 4668 #37895 New York, New York[masked] | [address removed]






--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Jonny Nguyen ([address removed]) from Houston PHP Users Group.
To learn more about Jonny Nguyen, visit his/her member profile
To unsubscribe or to update your mailing list settings, click here

Meetup, PO Box 4668 #37895 New York, New York[masked] | [address removed]

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy