Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1815 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Quick PHP Question

Thread title: Quick PHP Question
Reply    
    Thread tools Search this thread Display Modes  
12-31-2009, 11:20 PM
#1
astereo is offline astereo
astereo's Avatar
Status: Member
Join date: Jun 2005
Location: east coast, usa
Expertise: design,development, & WP
Software: Photoshop, Illustrator, WP
 
Posts: 421
iTrader: 6 / 100%
 

astereo is on a distinguished road

Send a message via AIM to astereo Send a message via Skype™ to astereo

  Old  Quick PHP Question

I'm trying to finish up a backend panel for one of my themes because my php is not the best but I'm having a little trouble getting past this last issue.

Question:

I have a "question" database [see attachment] that is being managed through an additional page within the Wordpress backend. basically, there are two groups of questions and three sets of five questions within each group.

For each group a default set must be selected.

So for example:

The group one field is called "showcaseset", with the first set in that group labeled "sq1", set two is "sq2" and set 3 is "sq3". The questions for each set then are labeled in the same way: "sq11", "sq12", "sq13", etc.

Right now if I do something like:

PHP Code:
<?php echo get_option('sq11'); ?>
It will grab the first question from set 1 of the showcase question group. But, to limit code and make things a little more dynamic what I want to do is combine whatever the default set is (ie: sq1, sq2, or sq3) with the number of the question.

To make things a little more clearer:

php echo get_option [sq#] + [static # 1 through 5]

In other words, I would be repeating whatever this line and just changing the static number at the end to a number 1 through five.

Ultimately what I want to happen is the saved option for the current set will be grabbed along with a static number of that question so that the end result echo will be "sq11", "sq12", or etc depending on where it is placed in the template.

Thanks in advance and happy new year!

Reply With Quote
01-03-2010, 02:59 AM
#2
Gaz is offline Gaz
Gaz's Avatar
Status: Request a custom title
Join date: Apr 2007
Location: UK
Expertise: Code & Programming
Software: Coda, TextMate, Sublime 2
 
Posts: 2,097
iTrader: 26 / 100%
 

Gaz will become famous soon enough Gaz will become famous soon enough

Send a message via Skype™ to Gaz

  Old

Firstly I assume this is Wordpress?

Also, you didn't attach anything..

As for the dynamic choosing of the sq# is it in a loop? Can we see some more of the code?

Reply With Quote
01-03-2010, 04:37 PM
#3
astereo is offline astereo
astereo's Avatar
Status: Member
Join date: Jun 2005
Location: east coast, usa
Expertise: design,development, & WP
Software: Photoshop, Illustrator, WP
 
Posts: 421
iTrader: 6 / 100%
 

astereo is on a distinguished road

Send a message via AIM to astereo Send a message via Skype™ to astereo

  Old

Opps, thanks for pointing that out. Here we go for real this time:

The questions are all stored as global custom fields (essentially wordpress options) so they can be used in or out of the loop. Right now I'm planning on using them in both the single.php page (so within the loop) and also in the individual submission form (outside of the loop on another page) so that questions can be easily rotated without needing to manually edit the template or submission form each time.

Here's some code related to the attached question bank:

HTML Code:
<h2>Set One</h2>
<p>Question 1:
<input type="text" name="sq11" size="45" value="<?php echo get_option('sq11'); ?>" /></p>
<p>Question 2:
<input type="text" name="sq12" size="45" value="<?php echo get_option('sq12'); ?>" /></p>
<p>Question 3:
<input type="text" name="sq13" size="45" value="<?php echo get_option('sq13'); ?>" /></p>
<p>Question 4:
<input type="text" name="sq14" size="45" value="<?php echo get_option('sq14'); ?>" /></p>
<p>Question 5:
<input type="text" name="sq15" size="45" value="<?php echo get_option('sq15'); ?>" /></p>
So if set one for example was selected as the active set bank for the profile questions, then I would need a way to echo the value of "sq1" + the # of the question.

Attached Images
File Type: jpg Question Bank ‹ built — WordPress_1262461946216.jpg (119.8 KB, 12 views)

Reply With Quote
Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed