webguync Posted March 19, 2010 Share Posted March 19, 2010 Anyone know what I am doing wrong here? <?php <?php $Question["1"] = '1-A'; $Question["2"] = '2-A'; $Question["3"] = '1-A'; $Question["4"] = '2-A'; $Question["5"] = '1-B'; echo "1 - $" . $Question["1"] . "<br />"; echo "2 - $" . $Question["2"] . "<br />"; echo "3 - $" . $Question["3"] . "<br />"; echo "4 - $" . $Question["4"] . "<br />"; echo "5 - $" . $Question["5"] . "<br />"; ?> ouput 1 - $1-A 2 - $2-A 3 - $1-A 4 - $2-A 5 - $1-B want it to be 1(I-A), 2(I-A),3(I-A) etc. Quote Link to comment Share on other sites More sharing options...
doa24uk Posted March 19, 2010 Share Posted March 19, 2010 Is this what you need? <?php $Question = 'I-A'; echo "1(" . $Question . ")<br />"; echo "2(" . $Question . ")<br />"; echo "3(" . $Question . ")<br />"; echo "4(" . $Question . ")<br />"; echo "5(" . $Question . ")<br />"; ?> Quote Link to comment Share on other sites More sharing options...
oni-kun Posted March 19, 2010 Share Posted March 19, 2010 Yeah, You're not really clear with your examples of needs of the script. If you tell us what you're trying to do (if we didn't answer your question) then we may be able to find a more useful way of coding for that. Quote Link to comment Share on other sites More sharing options...
Deivas Posted March 19, 2010 Share Posted March 19, 2010 <?php $Question["1"] = '1-A'; $Question["2"] = '2-A'; $Question["3"] = '1-A'; $Question["4"] = '2-A'; $Question["5"] = '1-B'; echo "1 - (" . $Question["1"] . ")<br />"; echo "2 - (" . $Question["2"] . ")<br />"; echo "3 - (" . $Question["3"] . ")<br />"; echo "4 - (" . $Question["4"] . ")<br />"; echo "5 - (" . $Question["5"] . ")<br />"; ?> or <?php $Question["1"] = '1-A'; $Question["2"] = '2-A'; $Question["3"] = '1-A'; $Question["4"] = '2-A'; $Question["5"] = '1-B'; echo "1(" . $Question["1"] . "),"; echo "2(" . $Question["2"] . "),"; echo "3(" . $Question["3"] . "),"; echo "4(" . $Question["4"] . "),"; echo "5(" . $Question["5"] . ")"; ?> Quote Link to comment Share on other sites More sharing options...
doa24uk Posted March 19, 2010 Share Posted March 19, 2010 Just reposting won't help .... I've given you what you asked for ... is this correct or not? Quote Link to comment Share on other sites More sharing options...
oni-kun Posted March 19, 2010 Share Posted March 19, 2010 Just reposting won't help .... I've given you what you asked for ... is this correct or not? He's not the OP, So I don't know what he's doing.. Hehe. Quote Link to comment Share on other sites More sharing options...
webguync Posted March 19, 2010 Author Share Posted March 19, 2010 ultimately what I need is to set up a column in html which corresponds with values from another column being pulled from MySQL db. so it would look like <td class="colA">1,4,6,8,9,11,15</td><td class="colB>1-A,1-A,1-B,1-B,1-C,1-D,II-B</td> keep in mind that the numbers in col A are variable and are being pulled from MySQL records. I thought an associative array would get me where I wanted to go, but I could be wrong... Quote Link to comment Share on other sites More sharing options...
webguync Posted March 19, 2010 Author Share Posted March 19, 2010 BTW, what Deivas posted is what I am looking for as far as association. I just need to figure out how to get that done dynamically. Quote Link to comment Share on other sites More sharing options...
oni-kun Posted March 19, 2010 Share Posted March 19, 2010 BTW, what Deivas posted is what I am looking for as far as association. I just need to figure out how to get that done dynamically. </td>1,4,6,8,9,11,15<td class="colB>1-A,1-A,1-B,1-B,1-C,1-D,II-B $a = Array(1,4,6,8,9,11,15); $b = Array('1-A','1-A','1-B','1-B','1-C','1-D','II-B'); $combined = array_merge($a, $b); //1-A => 1, 1-A => 4 ... $questions = array_flip($combined); Quote Link to comment Share on other sites More sharing options...
webguync Posted March 20, 2010 Author Share Posted March 20, 2010 I have a few questions on this method. Since the results from $a would be coming from a database field and the results are variable how would I handle this? Maybe it would help if I posted the code I have to display. <table id="resultlist"> <tr> <th scope="col">Employee Name</th> <th scope="col">Number Correct</th> <th scope="col">Score</th> <th scope="col">Question Number Answered Incorrectly</th> <th scope="col">Date Completed</th> <th scope="col">Pass/Fail</th> <th scope="col">Material to review (Chapter, Section)</th> </tr> <?php if (!isset($name)) { ?> <tr><td colspan="7">There are no scores to display</td></tr> <?php } else { for ($i=0; $i<count($name); $i++) { ?> <tr class="<?php echo $i%2 ? 'hilite' : 'nohilite'; ?>"> <td ><?php echo $name[$i];?></td> <td><?php echo $numCorr[$i];?></td> <td><?php echo (ROUND(($pcnt[$i]*100),0).'%'); ?></td> <td><?php echo $incorr[$i];?></td> <td><?php echo (date('F j, Y g:i A',($date[$i])));?></td> <td><?php if(($pcnt[$i]*100) > 89) { echo "<div class='passed'>" .Passed."</div>"; } else { echo "<div class='failed'>" .Failed. "</div>"; } ?></td> <td><?php echo $workon[$i];?></td> </tr> <?php } } ?> </table> the field $incorr is the one with the variable responses, and the field $workon is where I want to corresponding array values to appear. Currently I am entering manually in the database, but would prefer to have the association automated. I could also work with in the $incorr[$i] field displaying 1(I-A),2(I-B) or something like that. Quote Link to comment Share on other sites More sharing options...
webguync Posted March 22, 2010 Author Share Posted March 22, 2010 any ideas on this? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.