|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
mikeken Smarty Regular
Joined: 13 Aug 2003 Posts: 57 Location: MN
|
Posted: Tue Aug 19, 2003 1:30 pm Post subject: sections, on a menu form[OK, look again at this thread] |
|
|
First of all...my delimiters are "<{ and }>"
Hi, I have a section in a template that gets looped through and displays values from a database. It works but I also have a smarty variable inside the template that I would like to check from every loop from a varaible in php, and it will get replaced with "selected" if the value of the variable is the same.
Here is some clips of my code:
PHP Code:
[php:1:fc904dee4f]<?php
$query = "SELECT * FROM `styles`";
$result = mysql_query($query);
$code = arraypush($result);
$smarty->assign('mstylecode', $code);
$smarty->assign('ostylecode', $code);
?>[/php:1:fc904dee4f]
HTML Template code:
Code: |
<select name="mstyle" tabindex="2"><{section name=mstyle loop=$mstylecode}>
<option value="<{$mstylecode[mstyle].codename}>" <{$selected}>><{$mstylecode[mstyle].name}></option><{/section}>
</select> |
If you can see that <{$selected}> smarty variable, In the template code, I want that replaced with "selected" based on a condition.
Preferably depending on a variable inside of the php script.
Thanks
Last edited by mikeken on Tue Aug 19, 2003 10:56 pm; edited 1 time in total |
|
Back to top |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Tue Aug 19, 2003 1:56 pm Post subject: |
|
|
something like Code: | <select name="mstyle" tabindex="2"><{section name=mstyle loop=$mstylecode}>
<option value="<{$mstylecode[mstyle].codename}>"<{$selected}> {if $somevar}selected="selected"{/if}><{$mstylecode[mstyle].name}></option>
<{/section}></select> | that will make the code show it selected when $somevar is true _________________ "Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane |
|
Back to top |
|
mikeken Smarty Regular
Joined: 13 Aug 2003 Posts: 57 Location: MN
|
Posted: Tue Aug 19, 2003 2:28 pm Post subject: |
|
|
Is there way to do it in the php code? My goal is to keep virtualy all the code from the template, even smartys functions. |
|
Back to top |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Tue Aug 19, 2003 3:26 pm Post subject: |
|
|
Just tack on an aditional string to the object and have it contain the text if its selected and nothing if its not and then display it regardless _________________ "Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane |
|
Back to top |
|
mikeken Smarty Regular
Joined: 13 Aug 2003 Posts: 57 Location: MN
|
Posted: Tue Aug 19, 2003 5:45 pm Post subject: |
|
|
Still not getting it, this is my php code
[php:1:bad4ae1220]<?
//$smarty->assign('name','Mike');
if($id == ""){
$smarty->assign('content','v3/artists/profile/editprofile/content_error.tpl');
}
else{
$sql = "SELECT * FROM artist_list WHERE artistid=".$id." LIMIT 1";
$result = mysql_query($sql);
$numrows = mysql_num_rows($result);
$row = mysql_fetch_assoc($result);
}
// Verify that the artist exists
if($numrows == 1){
$smarty->assign('content','v3/artists/profile/editprofile/content.tpl');
if($userdata['user_id'] == $row['user_id'] || $userdata['user_level'] == ADMIN){
$good = true;
}
else{
$smarty->assign('content','v3/artists/profile/editprofile/content_error.tpl');
}
}
else{
$smarty->assign('content','v3/artists/profile/editprofile/content_error.tpl');
}
// End of Verification
if($good == true){
//$mstyle = array( 'trance' => 'Trance', 'house' => 'House', 'techno' => 'Techno', 'drumnbass' => 'Drum-N-Bass', 'eurodance' => 'EuroDance', 'hardcore' => 'Hardcore', 'hardhouse' => 'Hardcore', 'hardtrance' => 'Hard Trance', 'vocaltrance' => 'Vocal Trance', 'other' => 'Other');
$smarty->assign('artistname', $row['artistname']);
$smarty->assign('email', $row['email']);
$smarty->assign('website', $row['website']);
$smarty->assign('biography', $row['biography']);
if( $row['emaillisted'] == 1 )
$smarty->assign('emaillisted', 'checked');
if( $row['websitelisted'] == 1 )
$smarty->assign('websitelisted', 'checked');
$query = "SELECT * FROM `styles`";
$result = mysql_query($query);
$code = arraypush($result);
$smarty->assign('mstylecode', $code);
$smarty->assign('ostylecode', $code);
}
$smarty->display('v3/templates/header.tpl');
$smarty->display('v3/templates/main.tpl');
$smarty->display('v3/templates/footer.tpl');
?>[/php:1:bad4ae1220]
Now isnt there a way to do something like, if $row['mstyle'] == (some toher condition){
//then display text selected
}
????????
here is an example of something I would do in phptemplate
[php:1:bad4ae1220]<?
while($columnname = mysql_fetch_assoc($resultsrow)) {
if($columnname["field"] == $field)
$columnname["selected"] = "selected=\"selected\"";
tmpl_iterate($listbox, 'fieldlist');
tmpl_set($listbox, 'fieldlist', $columnname);
}
?>[/php:1:bad4ae1220] |
|
Back to top |
|
mikeken Smarty Regular
Joined: 13 Aug 2003 Posts: 57 Location: MN
|
Posted: Tue Aug 19, 2003 10:59 pm Post subject: |
|
|
I have different style that a user can select from in a html menu in a signup form. I.E trance, house, techno, etc
When they modify there profile I would like to display a menu with all the same options(doesnt matter where I get it from) and depending on which one is currently in the database, I would like that one to be selected...any Ideas? |
|
Back to top |
|
mikeken Smarty Regular
Joined: 13 Aug 2003 Posts: 57 Location: MN
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|