Jump to content

(Resolved) identifying each record


elexion

Recommended Posts

hello everyone, I've been working on a script that reads records out of database each record is a small array of questions(basically a survey system), per record a total score is assigned(this is the Javascript part)

 //echo the question list from the database$query_questions = mysql_query("SELECT * FROM `vraag`");while($result = mysql_fetch_array($query_questions)){//displaying the questionsecho "<br /><br /><b>";echo $result['header']. "</b><br />";echo $result['beschrijving']. "<br /><br />";echo $result['onderwerp']. "<br />"; //sneaky rogue values!$aantal = $result['aantal_vragen'];//this is a troublesome part of code as well I'll elaborate on this further down the postecho "<input type='hidden' id='number_of_questions' value=".$aantal." mousedown='calculate_score(this.value,0)'/>";$array = unserialize($result['vraag']);//the question list is stored in an array which I'll read out later//retrieve the content from the array foreach($array as $value){//below I created five radio elements because I want people to give each question a score from 1 to 5 I //used the form tag so that each each row of radio boxes would behave properlyecho "<form><table><td>". $value."</td>";echo "<td>1<input type='radio' name='vraag[]' value=1 onclick='calculate_score(".$aantal.",this.value)'/></td><td>2<input type='radio' name='vraag[]' value=2 onclick='calculate_score(".$aantal.",this.value)'/></td><td>3<input type='radio' name='vraag[]' value=3 onclick='calculate_score(".$aantal.",this.value)'/></td><td>4<input type='radio' name='vraag[]' value=4 onclick='calculate_score(".$aantal.",this.value)'/></td><td>5<input type='radio' name='vraag[]' value=5 onclick='calculate_score(".$aantal.",this.value)'/></td></table></form>";}}echo "Uw totaal score is: <span id='total_score' name='span[]'></span>";echo "<br /><form action='submit_survey.php' method='POST'><input type='hidden' name='total' value='total_score.value' />Naam : <input type='text' name='naam_opleider' /><br />bedrijf: <input type='text' name='bedrijf' /><br />Straat: <input type='text' name='straat' /><br />Postcode, Plaats: <input type='text' name='postcode' /><br /><input type='submit' value='versturen' /></form>"; 

what goes wrong is that it uses the last record of the query as the value to calculate with, it ignores the first record and the second and only picks up the last(third) record I want it to assign a score per record so shortly drawn out[record 1]score [record 2]score [record 3]score currently it works like this[record 1] [record 2] [record 3]score So shortly how do I fix this? I don't think the javascript is essential to the problem but if necessary I can include it :)edit note: There are no syntax errors purely functional I removed a for loop that wasn't really doing anythingthanks in advance

Edited by elexion
Link to comment
Share on other sites

what does it exactly prints? can you post that?

Link to comment
Share on other sites

what does it exactly prints? can you post that?
Sure thing I've relocated the span tag so that it is included at every record but the score only appears at the last span Edited by elexion
Link to comment
Share on other sites

for($i = 0; $i < $array; $i++) {
i am not sure about this loop and what is it doing here.
echo "Uw totaal score is: <span id='total_score' name='span[]'></span>";

move this part inside foreach loop

Link to comment
Share on other sites

i am not sure about this loop and what is it doing here.
echo "Uw totaal score is: <span id='total_score' name='span[]'></span>"; 

move this part inside foreach loop

problem is when I try to rate question 2 it fills/overwrites the score of question 1
Link to comment
Share on other sites

I'm thinking for each but...that doesn't work out...I need it to treat each record separately....also I need increment the total_score array of the span element so that the score is displayed underneath each record.... maybe I should do something with ID? or maybe a break.....

Edited by elexion
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...