Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 225
0 Users 6 Guests Online
Forum Index » PHP + MySQL » my php problem
Posted on Sunday 15th June 2008 at 07:14 AM
Matt
templates/default/images/noavatar.png's Avatar
Newbie
i'm having a problem right now, and the reason is because i'm not fully understanding how i'm suppossed to do this.

i have a page where an admin can add a poll, the poll system uses 3 mysql tables, poll, questions, responses. i will show a link to an online demo:
http://dev64.frankychan04.com/cms/?page=polls&a=3
you enter the name for the poll, then you enter the amount of options you want, the amount of options can be unlimited.
the query to create the poll is done after the first step, now i want to know is how to load every option into the table, what would my query look like, and what would the for loop look like, thanks.
Posted on Sunday 15th June 2008 at 06:20 PM
Adam981
templates/default/images/noavatar.png's Avatar
Junior Member
it would help if we seen the php codes, use [php*] php code here [/php*] without the stars
Posted on Sunday 15th June 2008 at 06:30 PM
Matt
templates/default/images/noavatar.png's Avatar
Newbie
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
    
//-----------------------------------------------------------------
    //  Create Poll
    //-----------------------------------------------------------------

    
case 3:

    if (
$_POST['question'] && $_POST['options'])
    {
        
//-----------------------------------------------------------------
        //  Insert the poll
        //-----------------------------------------------------------------

        
$db->insertRow("poll",array('name' => ''.$_POST['question'].'','user' => ''.$userinfo['username'].'','date' => ''.time().''));


        if (
$_POST['options'])
        {

        
//-----------------------------------------------------------------
        //  Add in the options
        //-----------------------------------------------------------------

        
startbox("Step Two");
        
$options $_POST[options];
        echo 
"<form action='$PHP_SELF?page=polls&a=3' method='post'><table class='main' cellspacing='1' cellpadding='5'>";
        for (
$a 1$a <= $options$a++) 
        {
                echo 
'<tr class="con1"><td>Option '.$a.': <input type="text" value="'.$a.'" /></td></tr>';
        }

        
?>

        </table><br/>
        <table class="main" cellspacing="1" cellpadding="3">
        <tr class="con1">
            <td width="50%">Actions:</td>
            <td width="50%" align="right"><input type="submit" value="Next &raquo;" /></td>
        </tr>
        </table></form>

    <?php

        
} else {

        
//-----------------------------------------------------------------
        //  This is the part i can't figure out
        //-----------------------------------------------------------------


    
} else {

    
?>

    <div class="box">
    <div class="boxtitle"><?=$language['Poll add title']; ?></div>
    <div class="boxcontent">
    <form action="<?=$PHP_SELF;?>?page=polls&a=3" method="post">
    <table class="main" cellspacing="1" cellpadding="5">
        <tr class="head">
            <td width="70%"><?=$language['Poll add desc']; ?></td>
            <td width="10%" align="center"><?=$language['Poll add desc3']; ?></td>
        </tr>
        <tr class='con1'>
            <td>
               <input type="text" name="question" class="box" style="width:100%;"  size="65" value="" />
            </td>
            <td align="center">
               <input type="text" class="box" name="options" style="width:30px;" />
            </td>
        </tr>
    </table>
    </div></div><br/>
    <table class="main" cellspacing="1" cellpadding="3">
        <tr class="con1">
            <td width="50%">Actions:</td>
            <td width="50%" align="right"><input type="submit" value="Next &raquo;" /></td>
        </tr>
    </table></form>

    <?php

    
}

    break;
?>


for each option there is, i want each option added into my database, that is the query and for loop i can't figure out.
Posted on Sunday 15th June 2008 at 07:09 PM
Adam981
templates/default/images/noavatar.png's Avatar
Junior Member
Hmm you have a different kinda poll then im use too, id say msg MOD-Shadow, he might be able to help. unless u wanted to use the poll we hve here.
Posted on Sunday 15th June 2008 at 07:14 PM
Matt
templates/default/images/noavatar.png's Avatar
Newbie
thats when it comes to adding the poll.
PHP Code
1
2
3
4
for ($a = 1; $a <= $options; $a++) 
        {
                echo '<tr class="con1"><td>Option '.$a.': <input type="text" value="'.$a.'" /></td></tr>';
        }


Say i have 5 options, all 5 options are generated with that code, so for each option i have, i want a row created in the database, how would i do that?