Jump to content

morocco-iceberg

Members
  • Posts

    100
  • Joined

Everything posted by morocco-iceberg

  1. Sorry if this is in the wrong section, it was the most relevant I could find. I have an assignment where I am required to create both a Relational Schema and ER Diagram, but I always thought an ER Diagram was a form of Relational Schema, and I wasn't taught about Relational Schema in class, only ER Diagrams. Basically my question is are they different, and if so how would I draw a Relational Schema?
  2. I found that I hadn't included the variable $identifier where it was required which meant it wasn't calling the correct values, so its all sweet now. Thanks for the help
  3. I changed that line of code to what you recommended again, but this time it didn't cause any errors. I've just woken up so I'm guessing it was a typo that caused them. I've taken out the double quotes around the $row["$letters"], didn't realise I hadn't before so cheers for picking that up. The $$letters are variable variables, so those should be fine as they are. The score still isn't adding up though. And I'm not exactly sure how to change that specific while loop into a foreach loop...
  4. I've been able to fix everything that causes errors from the code... anything that reports an error anyway, but my code still won't work. The first section is a function to mark the user input and see if they have selected the correct words in the correct order. This code is located on the page following the page on which the function sent() outputs the questions the user is required to answer. I don't receive any error messages, but it does not add up the score, which is what I need it to do. I'm really lost with this. Function that marks the user input: function mark($table){ $counter = 0; while ($counter<2){ $id = $_POST[$table."_q".$counter]; $names = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t"); foreach($names as $identifier => $letter){ $sql = mysql_query("SELECT * FROM $table WHERE id = '{$id}'") or die($error); while($row = mysql_fetch_array($sql)){ $$letter = $row["$letter"]; } if (isset($_POST[$table.'_a'.$counter.'_0'])){ ${'a'.$letter} = mysql_real_escape_string($_POST[$table.'_a'.$counter.'_0']); }else{ ${'a'.$letter} = "Undefined"; } ${'c'.$letter} = strcmp(${'a'.$letter}, $$letter); } if($ca == 0 && $cb == 0 && $cc == 0 && $cd == 0 && $ce == 0 && $cf == 0 && $cg == 0 && $ch == 0 && $ci == 0 && $cj == 0 && $ck == 0 && $cl == 0 && $cm == 0 && $cn == 0 && $co == 0 && $cp == 0 && $cq == 0 && $cr == 0 && $cs == 0 && $ct == 0){ global $score; $score++; }else{ global $score; $score = $score; } $counter++; } } Function that outputs the dropdown boxes for the user input: function sent($table){ $sql = mysql_query("SELECT * FROM $table ORDER BY RAND()") or die($error); $counter = 0; while($row = mysql_fetch_array($sql)){ $id[$counter] = $row["id"]; $a[$counter] = $row["a"]; $b[$counter] = $row["b"]; $c[$counter] = $row["c"]; $d[$counter] = $row["d"]; $e[$counter] = $row["e"]; $f[$counter] = $row["f"]; $g[$counter] = $row["g"]; $h[$counter] = $row["h"]; $i[$counter] = $row["i"]; $j[$counter] = $row["j"]; $k[$counter] = $row["k"]; $l[$counter] = $row["l"]; $m[$counter] = $row["m"]; $n[$counter] = $row["n"]; $o[$counter] = $row["o"]; $p[$counter] = $row["p"]; $q[$counter] = $row["q"]; $r[$counter] = $row["r"]; $s[$counter] = $row["s"]; $t[$counter] = $row["t"]; $counter++; } $counter = 0; while($counter<2){ echo "<input type=\"hidden\" name=\"".$table."_q".$counter."\" value=\"".$id[$counter]."\">"; ${$table.'_a'.$counter} = array("$a[$counter]", "$b[$counter]", "$c[$counter]", "$d[$counter]", "$e[$counter]", "$f[$counter]", "$g[$counter]", "$h[$counter]", "$i[$counter]", "$j[$counter]", "$k[$counter]", "$l[$counter]", "$m[$counter]", "$n[$counter]", "$o[$counter]", "$p[$counter]", "$q[$counter]", "$r[$counter]", "$s[$counter]", "$t[$counter]"); ${$table.'_c'.$counter} = ${$table.'_a'.$counter}; shuffle(${$table.'_a'.$counter}); echo "<table border=\"1\" bordercolor=\"#000000\" rules=\"none\" frame=\"box\" cellpadding=\"5\"><tr>"; $number = 0; while($number<20){ if(!${$table.'_a'.$counter}[$number]){ echo ""; }else{ echo "<td>".${$table.'_a'.$counter}[$number]."</td>"; } $number++; } echo "</tr></table><br/><table><tr>"; foreach(${$table.'_c'.$counter} as $identifier => $column){ if(empty($column)){ break; }else{ echo "<td><select name=\"".$table."_a".$counter."_".$identifier."\"><option value=\"0\"></option>"; $number = 0; while($number<20){ if(!${$table.'_a'.$counter}[$number]){ echo ""; }else{ echo "<option value=\"".${$table.'_a'.$counter}[$number]."\">".${$table.'_a'.$counter}[$number]."</option>"; } $number++; } echo "</select></td>"; } } echo "</tr></table><br/>"; $counter++; } }
  5. Notice: Undefined variable: b on line 48 (minus the 36 lines not included means line 12 in the code I've provided). Notice: Undefined index: sente_a2 on line 44 (line 10) Notice: Undefined variable: c on line 48 Notice: Undefined index: sente_a3 on line 44 And it just goes on and on like that for each letter and number.
  6. I'm only new to this and am getting a bit stuck. Basically function sent() outputs a set of questions within a form, the user answers the questions and function mark() is supposed to check whether the user got the answers correct. The output of sent() is a group of dropdown boxes that thes user has to construct a sentence from. The dropboxes contain preset words. My attempt at mark() is below, with the relevant code from sent() below that. The specific error that I am receiving says "Notice: Undefined variable:" and then lists all of the letters. How can I fix it/make it better/do it another way? function mark($table){ $counter = 0; while($counter<2){ $id = $_POST[$table."_q".$counter]; $sql = mysql_query("SELECT * FROM $table WHERE id = '{$id}'") or die($error); $letters = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t"); foreach($letters as $number => $letter){ ${'a'.$letter} = $_POST[$table."_a".$number]; while($row = mysql_fetch_array($sql)){ ${$letter} = $row[$letter]; } ${'c'.$letter} = strcmp(${'a'.$letter}, ${$letter}); } if ($ca == 0 && $cb == 0 && $cc == 0 && $cd == 0 && $ce == 0 && $cf == 0 && $cg == 0 && $ch == 0 && $ci == 0 && $cj == 0 && $ck == 0 && $cl == 0 && $cm == 0 && $cn == 0 && $co == 0 && $cp == 0 && $cq == 0 && $cr == 0 && $cs == 0 && $ct == 0){ global $score; $score++; }else{ global $score; $score = $score; } $counter++; } } function sent($table){ $sql = mysql_query("SELECT * FROM $table ORDER BY RAND()") or die($error); $counter = 0; while($row = mysql_fetch_array($sql)){ $id[$counter] = $row["id"]; $a[$counter] = $row["a"]; $b[$counter] = $row["b"]; $c[$counter] = $row["c"]; $d[$counter] = $row["d"]; $e[$counter] = $row["e"]; $f[$counter] = $row["f"]; $g[$counter] = $row["g"]; $h[$counter] = $row["h"]; $i[$counter] = $row["i"]; $j[$counter] = $row["j"]; $k[$counter] = $row["k"]; $l[$counter] = $row["l"]; $m[$counter] = $row["m"]; $n[$counter] = $row["n"]; $o[$counter] = $row["o"]; $p[$counter] = $row["p"]; $q[$counter] = $row["q"]; $r[$counter] = $row["r"]; $s[$counter] = $row["s"]; $t[$counter] = $row["t"]; $counter++; } $counter = 0; while($counter<2){ echo "<input type=\"hidden\" name=\"".$table."_q".$counter."\" value=\"".$id[$counter]."\">"; ${$table.'_a'.$counter} = array("$a[$counter]", "$b[$counter]", "$c[$counter]", "$d[$counter]", "$e[$counter]", "$f[$counter]", "$g[$counter]", "$h[$counter]", "$i[$counter]", "$j[$counter]", "$k[$counter]", "$l[$counter]", "$m[$counter]", "$n[$counter]", "$o[$counter]", "$p[$counter]", "$q[$counter]", "$r[$counter]", "$s[$counter]", "$t[$counter]"); ${$table.'_c'.$counter} = ${$table.'_a'.$counter}; shuffle(${$table.'_a'.$counter}); $number = 0; echo "<table border=\"1\" bordercolor=\"#000000\" rules=\"none\" frame=\"box\" cellpadding=\"5\"><tr>"; while($number<20){ if(!${$table.'_a'.$counter}[$number]){ echo ""; }else{ echo "<td>".${$table.'_a'.$counter}[$number]."</td>"; } $number++; } echo "</tr></table><br/><table><tr>"; foreach(${$table.'_c'.$counter} as $column){ if(empty($column)){ break; }else{ echo "<td><select name=\"".$table."_a".$counter."\"><option value=\"0\"></option>"; $number = 0; while($number<20){ if(!${$table.'_a'.$counter}[$number]){ echo ""; }else{ echo "<option value=\"".${$table.'_a'.$counter}[$number]."_".$number."\">".${$table.'_a'.$counter}[$number]."</option>"; } $number++; } echo "</select></td>"; } } echo "</tr></table><br/>"; $counter++; } }
  7. I can't find a reason for why I'm getting this error: Parse error: syntax error, unexpected '{' on line 4 And I was wondering if I should use a switch case in my code instead of what I have at the moment, or leave it as is? <?php session_start(); $error = "An error occurred, please press f5 to refresh the page and try again."; if(!isset($_SESSION["list_score"]){ die("You cannot access this page because you have not completed a previous section of the test, or have already completed this section."); } $deta = $_SESSION["deta"]; $gram_score = $_SESSION["gram_score"]; $gram_time = $_SESSION["gram_time"]; $read_score = $_SESSION["read_score"]; $read_time = $_SESSION["read_time"]; $writ_score = $_SESSION["writ_score"]; $writ_time = $_SESSION["writ_time"]; $list_score = $_SESSION["list_score"]; $list_time = $_SESSION["list_time"]; $score = $gram_score + $read_score + $list_score; if($score<12){ $v = "Beginner"; $w = 24; $x = 36; $y = 48; $z = 60; }else if($score>11 && $score<24){ $v = "Elementary"; $w = 12; $x = 24; $y = 36; $z = 48; }else if($score>23 && $score<36){ $v = "Pre-Intermediate"; $w = 0; $x = 12; $y = 24; $z = 36; }else if($score>35 && $score<48){ $v = "Intermediate"; $w = 0; $x = 0; $y = 12; $z = 24; }else if($score>47 && $score<60){ $v = "Upper-Intermediate"; $w = 0; $x = 0; $y = 0; $z = 12; }else{ $v = "Advanced"; $w = 0; $x = 0; $y = 0; $z = 0; } echo "You are at ".$v." level."."\r\n" . $w." weeks to enter D class."."\r\n" . $x." weeks to enter C class"."\r\n" . $y." weeks to enter B class"."\r\n" . $z." weeks to enter A class"; ?>
  8. Oh, well that seems much more sensible (its 5:30am and I haven't slept). Thanks!
  9. I just need to know the correct syntax for using a variable variable within a mysql query. At the current time I have this: $sql = mysql_query("SELECT * FROM $table WHERE start = '{$'q'.$counter}' AND answer = '{$'q'.$counter}'") or die($error);
  10. Ok, well I'll go through and try to rewrite the code in a better way, thanks for all of the help. And, yes I'm stupid, but what does 'hard code' mean? I googled it and can't find any definitions...
  11. Lol, yeah, like I said I'm still learning so I've probably done it all the worst way. And the names are descriptive to me, i.e oppop calls to the table that contains the opposites pre-intermediate questions. And any tips how could I make it less repetitive? I did it this way because that's all I thought I could do... I fixed something and now the parse error is apparently on line 136... which I can't find, it seriously just skips from 134 to 139, without a tab to expand it or anything.
  12. Yeah, I haven't really developed the whole organizational skills thing yet, I've just started my database design course at uni, and am obviously still learning. I've only been coding php and mysql for about a month now. Most of the lines of code are part of a function that I couldn't figure out how to do any other way. The oppo("oppop"); lines call to a previous function, and the text within the "" is the name of the table contained in the database that the function uses.
  13. Here's the lines near the end of the file that I suspect the error is located, but I suppose it could be anywhere. <h1>Opposites</h1>" .$oppo."<br/><br/>"; oppo("oppoe"); oppo("oppop"); oppo("oppoi"); oppo("oppou"); oppo("oppoa"); $oppoAnswers = array($oppoe_a0, $oppoe_a1, $oppop_a0, $oppop_a1, $oppoi_a0, $oppoi_a1, $oppou_a0, $oppou_a1, $oppoa_a0, $oppoa_a1); shuffle($oppoAnswers); echo "<table border=\"1\" bordercolor=\"#000000\" rules=\"none\" frame=\"box\" cellpadding=\"5\"> <tr> <td>".$oppoAnswers[0]."</td> <td>".$oppoAnswers[1]."</td> <td>".$oppoAnswers[2]."</td> <td>".$oppoAnswers[3]."</td> <td>".$oppoAnswers[4]."</td> </tr> <tr> <td>".$oppoAnswers[5]."</td> <td>".$oppoAnswers[6]."</td> <td>".$oppoAnswers[7]."</td> <td>".$oppoAnswers[8]."</td> <td>".$oppoAnswers[9]."</td> </tr> </table> <table>"; $oppoOptions = array($oppoe_0, $oppoe_1, $oppop_0, $oppop_1, $oppoi_0, $oppoi_1, $oppou_0, $oppou_1, $oppoa_0, $oppoa_1); shuffle($oppoOptions); $oppoSelect = $oppoOptions[0].$oppoOptions[1].$oppoOptions[2].$oppoOptions[3].$oppoOptions[4].$oppoOptions[5].$oppoOptions[6].$oppoOptions[7].$oppoOptions[8].$oppoOptions[9]; echo $oppoe_s; echo $oppoSelect; echo $oppoe_m; echo $oppoSelect; echo $oppoe_e; echo $oppop_s; echo $oppoSelect; echo $oppop_m; echo $oppoSelect; echo $oppop_e; echo $oppoi_s; echo $oppoSelect; echo $oppoi_m; echo $oppoSelect; echo $oppoi_e; echo $oppou_s; echo $oppoSelect; echo $oppou_m; echo $oppoSelect; echo $oppou_e; echo $oppoa_s; echo $oppoSelect; echo $oppoa_m; echo $oppoSelect; echo $oppoa_e; echo "</table> <div id=\"center\"><input type=\"submit\" value=\"Move to next section...\" onClick=\"return confirm('Are you sure you want to move to the next section?');\" /></div> </form> </body> </html>"; ?>
  14. I keep getting this error: Parse error: parse error in * on line 4712 (which is the last line in the file and only contains ?>). I can't find anything wrong, and as the error doesn't specify anything I don't know what kind of error to look for. Does anyone know what this would typically be reffering to?
  15. I can't figure out what is going on here. When I use this in my code: $result = mysql_query("SELECT * FROM read")or die(mysql_error()); $number = mysql_numrows($result); I get this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read' at line 1 Because I couldn't find anything wrong I thought I'd check if there is actually a problem, so I changed the name of the table to 'list', like this: $result = mysql_query("SELECT * FROM list")or die(mysql_error()); $number = mysql_numrows($result); And it worked fine, I recieved no error message and the rest of the code output what I expected it to. Any ideas what could be going wrong? I've checked the tables and they're fine (the list table is just a copy of the read table, so I don't see why it would be affecting the code.)
  16. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19) VALUES ('d' at line 1 if(isset($_POST["add"])){ $section = "sent"; $level = $_POST["level"]; $table = $section . $level; $section_0 = $_POST["0"]; $section_1 = $_POST["1"]; $section_2 = $_POST["2"]; $section_3 = $_POST["3"]; $section_4 = $_POST["4"]; $section_5 = $_POST["5"]; $section_6 = $_POST["6"]; $section_7 = $_POST["7"]; $section_8 = $_POST["8"]; $section_9 = $_POST["9"]; $section_10 = $_POST["10"]; $section_11 = $_POST["11"]; $section_12 = $_POST["12"]; $section_13 = $_POST["13"]; $section_14 = $_POST["14"]; $section_15 = $_POST["15"]; $section_16 = $_POST["16"]; $section_17 = $_POST["17"]; $section_18 = $_POST["18"]; $section_19 = $_POST["19"]; $query = "INSERT INTO $table (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19) VALUES ('$section_0', '$section_1', '$section_2', '$section_3', '$section_4', '$section_5', '$section_6', '$section_7', '$section_8', '$section_9', '$section_10', '$section_11', '$section_12', '$section_13', '$section_14', '$section_15', '$section_16', '$section_17', '$section_18', '$section_19')"; mysql_query($query) or die(mysql_error()); $success_message = "Question was added."; } I can't find anything wrong, but no matter what it won't work. Help!
  17. Haha, will do, still only learning these things.
  18. Just having a bit of trouble with my logic. I'm not too sure how to go about doing this kind of thing. I have a form that first asks the user how many sections of data they want to enter. Then once that form is submitted depending on the number they input the relevant number of input boxes are shown for them to enter their data. This is where this code comes into play. When they submit the second form it activates this code, so for each field it inserts the data into the relevant slots. I have two problems: a) I need all the information inserted into the same row. b) If the correct number of fields do not yet exist in the table i need to create them and submit the relevant data. Here's what I've got so far, but I'm a little bit stuck... if(isset($_POST["add"])){ $section = "sent"; $level = $_POST["level"]; $table = $section . $level; $number = $_POST["number"]; $i = 0; while($i<$number){ $i = mysql_real_escape_string($_POST["$i"]); mysql_query("INSERT INTO $table ('$i') VALUES ('$i')") or die($error_message); $i++; } $success_message = "Question was added."; }
  19. I ask because I have tried it and it doesn't work, so I assumed I was doing it wrong.
  20. Is it possible to create a variable name using variable variables and an extension? i.e $$table with _0 after so if $table = apple the new variable name would be $apple_0. If this isn't possible could you tell me a way around it?
  21. Oooh, that makes sense, I'll try that! Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.