buothz Posted January 17, 2013 Share Posted January 17, 2013 $dati_auto = array("auto_marca", "auto_tipo", "auto_prezzo"); $maxi = count($dati_auto); echo 'max n vale' . $maxn; for ($i = 0; $i < $maxi; $i++) { //echo '<p>dati auto vale ' . $dati_auto[$i].'</p>'; $field = $fields->get('$dati_auto[$i]'); $label = $field->get("label$language"); echo "<li><strong>$label:</strong> $page->$dati_auto[$i]</li>"; } why this code don't work? There's a method to take an array with my vars and put in a cycle? Thank u Link to comment Share on other sites More sharing options...
Pete Posted January 17, 2013 Share Posted January 17, 2013 This: $field = $fields->get('$dati_auto[$i]'); Should be without single quotes, like this: $field = $fields->get($dati_auto[$i]); Otherwise you are treating it as a string. 1 Link to comment Share on other sites More sharing options...
nik Posted January 17, 2013 Share Posted January 17, 2013 (edited) I'm not sure I understand what you're trying to achieve, but let's try and fix a couple of little mistakes from the code . echo 'max n vake' . $maxn; There's no variable named $maxn, there should probably read $maxi. $field = $fields->get('$dati_auto[$i]'); You're using single quotes so PHP treats what's between them as a literal string and does not interpolate the variable. As there's nothing more than a variable there, you can leave the single quotes off. To make PHP interpolate the variable, use double quotes as you've done at the very next line. The $language variable shown there is initialized to some meaningful value somewhere as well, right? And yet another variable interpolation thing here: echo "<li><strong>$label:</strong> $page->$dati_auto[$i]</li>"; Should be: echo "<li><strong>$label:</strong> {$page->$dati_auto[$i]}</li>"; (Ah, Pete was faster, so no hurry anymore for me. I'll go on a little more then.) And of course you'd need fields called auto_marca, auto_tipo and auto_prezzo to exists in the template of this page for this to work in the first place. But I think you've covered that already. One more thing, and this is just a preference, not a mistake at all. I like to iterate over that kind of array like this: foreach($dati_auto as $field_name) { $field = $fields->get($field_name); // ... echo "... {$page->$field_name} ...";} But as I said, there's nothing wrong with the way you've done it . (Edit: Ngh.. The editor messed the code totally - had to fix them afterwards. I wanted to see if the post looks alright before posting it and used full editor for that (more options or whatever the button says there). Then submitted the post and code was all over the place...) Edited January 17, 2013 by nik 1 Link to comment Share on other sites More sharing options...
buothz Posted January 17, 2013 Author Share Posted January 17, 2013 I'm not sure I understand what you're trying to achieve, but let's try and fix a couple of little mistakes from the code . echo 'max n vake' . $maxn; There's no variable named $maxn, there should probably read $maxi. $field = $fields->get('$dati_auto[$i]'); You're using single quotes so PHP treats what's between them as a literal string and does not interpolate the variable. As there's nothing more than a variable there, you can leave the single quotes off. To make PHP interpolate the variable, use double quotes as you've done at the very next line. The $language variable shown there is initialized to some meaningful value somewhere as well, right? And yet another variable interpolation thing here: echo "<li><strong>$label:</strong> $page->$dati_auto[$i]</li>"; Should be: echo "<li><strong>$label:</strong> {$page->$dati_auto[$i]}</li>"; (Ah, Pete was faster, so no hurry anymore for me. I'll go on a little more then.) And of course you'd need fields called auto_marca, auto_tipo and auto_prezzo to exists in the template of this page for this to work in the first place. But I think you've covered that already. One more thing, and this is just a preference, not a mistake at all. I like to iterate over that kind of array like this: foreach($dati_auto as $field_name) { $field = $fields->get($field_name); // ... echo "... {$page->$field_name} ..."; } But as I said, there's nothing wrong with the way you've done it . (Edit: Ngh.. The editor messed the code totally - had to fix them afterwards. I wanted to see if the post looks alright before posting it and used full editor for that (more options or whatever the button says there). Then submitted the post and code was all over the place...) thank u to all! Problem resolved! Another little question: why i can't see name of field but only id??? Link to comment Share on other sites More sharing options...
Pete Posted January 17, 2013 Share Posted January 17, 2013 If it's a page field (I think it is) then you need to edit that field, click on the Input tab and set "Label Field" to "title". Link to comment Share on other sites More sharing options...
Soma Posted January 17, 2013 Share Posted January 17, 2013 These look like its a user select. Ids are in the range of admin etc. You should not choor title but name as the label as users dont have a title field. Link to comment Share on other sites More sharing options...
buothz Posted January 17, 2013 Author Share Posted January 17, 2013 These look like its a user select. Ids are in the range of admin etc. You should not choor title but name as the label as users dont have a title field. If i've understand well what do u tell -> ids are of the template name for example 29 is basic-page.php template etc... I've the same problem for the fields, I can't see field's name but only id... how can I resolve this problem? Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 17, 2013 Share Posted January 17, 2013 There is a 'label' select where you should pick title (or another, good property) - see here: http://o7.no/VarKm9 Link to comment Share on other sites More sharing options...
Soma Posted January 17, 2013 Share Posted January 17, 2013 Then what is the field you use to make that select? Too little questions you ask to be able to help from guessing. Link to comment Share on other sites More sharing options...
Nico Knoll Posted January 18, 2013 Share Posted January 18, 2013 There is a 'label' select where you should pick title (or another, good property) - see here: http://o7.no/VarKm9 Lovely theme you are using Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now