Current location: Hot Scripts Forums » Programming Languages » PHP » Display Filtered Data with Dynamic Titles


Display Filtered Data with Dynamic Titles

Reply
  #1 (permalink)  
Old 03-21-09, 09:02 PM
software4 software4 is offline
Newbie Coder
 
Join Date: Feb 2009
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Display Filtered Data with Dynamic Titles

Here is what i am trying to accomplish. I have written a program for voting. The table that i am pulling the data from is called join and it has (ID, event_name, position, and candidate_name)

example
id = auto#
event_name = Elections
position = President, Vice, etc...
candidate_name = john, jill, tom, etc...

I want to give the user the option to create different positions so that filed is dynamic (done)

I have created the entire program, but now am stuck on the actual page that people would vote on. I need to create a page that will show each position (president, vice, etc..) and all the candidates that are running for that position in a drop down menu.

example
president
drop down menu - tom, bill, sally

vice president
drop down menu - jill, bob, mike

$any_value_the_user_enters
drop dwon menu - todd, colin, cheryl

i would post the current code that i have already created, but i think i am going in the wrong direction with it. This is only my second php program that i have written so i am still kind of new at this.

Thanks,
Ben
Reply With Quote
  #2 (permalink)  
Old 03-21-09, 09:24 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
Step 1: Assuming your using MySQL, you will need to rename your table, as "join" is a keyword.

Step 2: I'm a little confused as to what you want. You want self populating drop down (<select>) boxes? And, you want those boxes grouped under Positions?
Reply With Quote
  #3 (permalink)  
Old 03-21-09, 09:34 PM
software4 software4 is offline
Newbie Coder
 
Join Date: Feb 2009
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
I am using MySQL ??? confused as to rename table as keyword

I am trying to make it so the code will look at the column 'position' and find all of the different types of positions. (President, Vice President, Treasurer, what ever is in that column.)

Then i want to make a page that will say the position, and every one who has the position listed in that table.

data example
id elections position candidate
1 officer president ben
2 officer president cheryl
3 officer vice mike
4 officer vice tom

now i want them to see
president
drop down box displaying ben and cheryl

vice
drop down box displaying mike and tom

I dont know all of the positions ahead of time as i dont all of the posionts for the end user so i need to have the script find the all of the different positions that are listed in the field.

Last edited by software4; 03-21-09 at 09:37 PM.
Reply With Quote
  #4 (permalink)  
Old 03-21-09, 09:41 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
I am stating that MySQL see's the word "JOIN" as an operator, and will reject all queries and throw an error.

So you will need to rename your table to something different.

Give me a minute, I'll see what I can work up for you...
Reply With Quote
  #5 (permalink)  
Old 03-21-09, 09:42 PM
software4 software4 is offline
Newbie Coder
 
Join Date: Feb 2009
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Here is what i have come up with, but it does not give me the flexibility for variables that i dont know in the position field

PHP Code:

// president

$query_Recordset_join_president "SELECT * FROM join2 WHERE join_position = 'President'";
$Recordset_join_president mysql_query($query_Recordset_join_president$Vote) or die(mysql_error());
$row_Recordset_join_president mysql_fetch_assoc($Recordset_join_president);
$totalRows_Recordset_join_president mysql_num_rows($Recordset_join_president);

//Vice
$query_Recordset_join_vice "SELECT * FROM join2 WHERE join_position = 'Vice President'";
$Recordset_join_vice mysql_query($query_Recordset_join_vice$Vote) or die(mysql_error());
$row_Recordset_join_vice mysql_fetch_assoc($Recordset_join_vice);
$totalRows_Recordset_join_vice mysql_num_rows($Recordset_join_vice);
mysql_select_db($database_Vote$Vote); 

and here is what I have in my form

PHP Code:

 <option value="<?php echo $row_Recordset_join_president['join_candidate']?>"><?php echo $row_Recordset_join_president['join_candidate']?></option>

                            <?php
} while ($row_Recordset_join_president mysql_fetch_assoc($Recordset_join_president));
  
$rows mysql_num_rows($Recordset_join_president);
  if(
$rows 0) {
      
mysql_data_seek($Recordset_join_president0);
      
$row_Recordset_join_president mysql_fetch_assoc($Recordset_join_president);
  }
?>
                          </select>
                      </p>
                      <p align="left"> Vice President:
                          <select name="join_candidate2" id="join_candidate2">
                            <?php
do {  
?>
                            <option value="<?php echo $row_Recordset_join_vice['join_candidate']?>"><?php echo $row_Recordset_join_vice['join_candidate']?></option>
                            <?php
} while ($row_Recordset_join_vice mysql_fetch_assoc($Recordset_join_vice));
  
$rows mysql_num_rows($Recordset_join_vice);
  if(
$rows 0) {
      
mysql_data_seek($Recordset_join_vice0);
      
$row_Recordset_join_vice mysql_fetch_assoc($Recordset_join_vice);
  }
?>
Reply With Quote
  #6 (permalink)  
Old 03-21-09, 10:35 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
See if this helps you out any. I set up a temp table on my local DB named "test"

So append that section in the Query to your table name, I used the column's you specified.


PHP Code:



<?php

//Set the query
$query "SELECT * FROM `test`";

//call the query
$result mysql_query($query);

//start table build
echo '<table cellspacing="0" cellpadding="0" border="1">';

//loop through DB for table rows
while($row mysql_fetch_array($result))
    {
     
$id $row[0];
     
$election $row[1];
     
$position $row[2];
     
$candidate $row[3];
     
     echo 
'<tr>'
         
.'<td>'.$id.'</td>'
         
.'<td>'.$election.'</td>'
         
.'<td>'.$position.'</td>'
         
.'<td>'.$candidate.'</td>'
         
.'</tr>';
         
        
//create a storage array
        
$storage["$election"]["$position"]["$candidate"] = $id;
    }
echo 
'</table>';


//cycle through our array to build our forms.    
        
foreach($storage as $key => $value)
            {
                echo 
'<form action="whatever.php" method="post">';
                echo 
'Vote in Election: '$key .'<br/>';
                
                
                        foreach(
$value as $key2 => $value2)
                            {
                                    echo 
'<div>'.$key2.'<br/>'
                                        
.'<select name="'.$key2.'">';
                                        
                                
                                    if(
is_array($value2))
                                        {
                                        foreach(
$value2 as $key3 => $value3)
                                            {
                                                echo 
'<option value="'.$value3.'">'.$key3.'</option>';
                                            }
                                        }
                                    else
                                        {
                                            echo 
'<option value="NULL">Not Set</option>';
                                        }                                
                                    
                                    echo 
'</select>'
                                        
.'</div>';
                            }
                    
                echo 
'<br/><input type="submit" name="submit" value="  SUBMIT  "/>'
                    
.'</form>';
                    
            }
            
//print_r($storage);


?>
Reply With Quote
  #7 (permalink)  
Old 03-21-09, 11:06 PM
software4 software4 is offline
Newbie Coder
 
Join Date: Feb 2009
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
First off, i must say, you ROCK... That worked perfect. I need to remove the table, but other then that, it is exactly what I was looking for. That was way above my php level and would have taken me ages to figure out. I am now realizing that I will have some more hurdles to overcome such as now how to store that in a database. I don’t think what I have setup will work.

I appreciate your help and was wondering if I could pay you a little for some more consulting as I would not want to take advantage of your kindness. Of course if you just get a high from helping struggling php writers that is great as well.
Reply With Quote
  #8 (permalink)  
Old 03-21-09, 11:11 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
I really don't mind helping at all, and I could never accept money for it.


That being said,

I'll be right back with a db script for you... (since your so nice )
Reply With Quote
  #9 (permalink)  
Old 03-21-09, 11:13 PM
software4 software4 is offline
Newbie Coder
 
Join Date: Feb 2009
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
here is a view on what i am doing

http://software4schools.com/vote/admin_login.php
you can log in with admin / admin

its all test data, so mess around...
Reply With Quote
  #10 (permalink)  
Old 03-21-09, 11:20 PM
software4 software4 is offline
Newbie Coder
 
Join Date: Feb 2009
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Here is what I still need to accomplish…

I have it setup so their can be multiple events running at the same time. Each event has a start and stop date so end users can only vote during that time per each event

I also need to validate that an end user can only vote once for each event.

I still need to post this data to the database table ‘votes’ What I am perplexed about is how to post this in a database where it will show that a single user voted for multiple officers(positions) in one single post.
Reply With Quote
Reply

Bookmarks


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to put dynamic data display in a scrolling watermark? Whipsmack JavaScript 1 03-29-04 08:22 AM


All times are GMT -5. The time now is 08:31 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.