Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dynamic select and input drop downs and dynamic html

Posted on 2007-03-25
6
Medium Priority
?
367 Views
Last Modified: 2013-12-13
I am pretty new to PHP but I'm getting it (if a little slowly). Anyway, I'm working on a project and I need to create a small survey. I know all about using MYSQL and APACHE with PHP but I need to use IIS6 and MS Access. Anyway, The survey is suppose to have a simple username only login for the first page. On the second page will be all of the survey questions along with their rankings. It will be something like this...
Survey 1
 Survey 1 Question 1  <SELECT DROP DOWN RANKING>
 Survey 1 Question 2  <SELECT DROP DOWN RANKING>
 Survey 1 Question 3  <SELECT DROP DOWN RANKING>

The select drop down ranking value will be 1, 2, 3 (the total amount of inputs will be based on the number of survey questions. For example, in the example above, if there were 5 survey questions then there would be 5 inputs in the select drop down. The user is suppose to select only one each. Now, there are 8 surveys and each survey has anywhere from 1 to n survey questions. I've already got the login, logout and session stuff working.I'm currently stuck on 2 things. First, I can't figure out how to get the table, tr and tds set up correctly. The way it's suppose to show up on the page is that there is suppose to be evenly devided based on the number of surveys. If there are 8 surveys there 4 surveys on the left side (first td) and 4 on the right side (second td). My second and I'm sure a more complicated problem is that I can't figure out how to populate the <select tag. Since these are all dynamic, I can't hard-code anything. Here is what I have so far:

<?php
require_once('odbc.php');
$resultcount = 0;
$query = odbc_exec($odbc, "SELECT * FROM ACTIVITY") or die (odbc_errormsg());
print "<table width='400' border='1' cellspacing='0' cellpadding='0' style='margin: 25px 0px 10px 0px;'>\n<tr>\n<td>\n\n<table>";
while($row = odbc_fetch_array($query))
{
$blah1 = $row[ACTIVITY_ID];
    print "\n<tr>\n<td><font size=+1 color=red>";
    echo $row['DESCRIPTION'];
    $active = odbc_exec($odbc, "SELECT * FROM ACTIVITY_TYPE WHERE ACTIVITY_ID = $row[ACTIVITY_ID]") or die (odbc_errormsg());
    while($actrow = odbc_fetch_array($active))
      {
    $blah2 = $actrow[ACTIVITY_ID];
            if ($blah1 = $blah2){
            print "<table>\n<tr>\n<td font size=-1 color=black>\n&nbsp;&nbsp;&nbsp;";
            echo $actrow['DESCRIPTION'];
            echo '&nbsp;&nbsp;&nbsp;<select name='.$rankrow['RANKING_ID'].'>';
                  $ranking = odbc_exec($odbc, "SELECT * FROM ACTIVITY_RANKING WHERE ACTIVITY_ID = $row[ACTIVITY_ID]") or die (odbc_errormsg());
                  while($rankrow = odbc_fetch_array($ranking))
                  {
                  echo '<option value='.$rankrow['RANKING'].'>'.$rankrow['RANKING'].'</option>';
                  }
            print "</td>\n</tr>\n</table>\n";
            }
      }
      if ($resultcount == 3) {
      print "\n</td>\n</tr></table></td>\n<td>\n<table>";
      }else{
      print "\n</td>\n</tr>";
    }
    $resultcount++;
}
print "\n</table>\n</td>\n</tr>\n</table>";
odbc_close($odbc);
?>

This actually works ok (and looks ok in IE) but as I noted above, the html isn't working and I don't know how to populate the <select name so that I can capture it once the user clicks the submit button.

I'm doing this all on my laptop so to show you an example of what I've come up with so far, I've saved the source from my browser and put it up on my friends site. The page is here - http://tests.likeanut.com/

Thanks,
biglarrrr
0
Comment
Question by:biglarrrr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:ClickCentric
ID: 18796901
Hmm...there seems to be a lot wrong here.  You're missing single and double quotes all over the place and the output of the html doesn't look like it would be right at all.  I'd suggest checking out www.w3c.org and looking up the details on how html tables work.  The main reason your select statement is probably failing is because you're never closing it.  Sorry to sound so sharp, but this should really be 4 or 5 separate questions considering all that looks off.  
0
 
LVL 4

Expert Comment

by:Arrivist
ID: 18807095
As a starter, here's one way to create the dynamic two column table:

[BEGIN CODE]

<table>

<?php
colCounter=0;
while $row = odbc_fetch_array($query)) {
      if (colCounter == 0) {
            echo "<tr><td>";
            //output your dropdown, for column one
            echo "</td>";
            colCounter++;
      } else {
            echo "<td>";
            //output your dropdown, for column two
            echo "</td></tr>";
            colCounter=0;
      }
}
if (colCounter == 0) { echo "<td>&nbsp;</td></tr>"; }
?>

</table>

[END CODE]

HTH...
0
 

Author Comment

by:biglarrrr
ID: 18811707
Thanks Arrivist! The advice you posted worked perfectly. As ClickCentric pointed out, there is a lot wrong. :)  Now I've got to figure out how to get the <select to populate correctly. I'm thinking the html will need to look something like this - <select name=blah[1]>, <select name=blah[2]>, etc. so that when the user clicks submit I'll have an array to loop through and populate the db correctly. Any advice? Or should I repost this as another question?

Thanks,
biglarrrr
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Accepted Solution

by:
Arrivist earned 2000 total points
ID: 18815007
Ok, lets keep it simple :)
Try something like this

[BEGIN PSEUDOCODE]

<?php
while($activity_id = #get each activity#) {
    while ($activity_type = #get each activity type for this activity#) {
        echo "<SELECT NAME='" . $activity_id . "-" . $activity_type. "'>";
        while ($ranking = #get each ranking this activity#) {
            echo '<OPTION VALUE='.$ranking.'>'.$ranking.'</OPTION>';
        }
        echo "</SELECT>";
    }
}

?>

[END PSEUDOCODE]

will produce someting like (depending on your key values of course):

<SELECT NAME='1-1'><OPTION VALUE='1'>1</OPTION><OPTION VALUE='2'>2</OPTION></SELECT>
<SELECT NAME='1-2'><OPTION VALUE='1'>1</OPTION><OPTION VALUE='2'>2</OPTION></SELECT>
<SELECT NAME='2-1'><OPTION VALUE='1'>1</OPTION><OPTION VALUE='2'>2</OPTION></SELECT>
etc...

It should be a simple enough task to cope with the form values after that.


 
0
 

Author Comment

by:biglarrrr
ID: 18826330
Thanks for your help Arrivist. I really appreciate it.

Thanks,
biglarrrr
0
 
LVL 4

Expert Comment

by:Arrivist
ID: 18835678
Glad to have been of assistance.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question