Witam. Mam sobie taki kod:
<?php$mc = mysql_connect("","ROOT","PASS");mysql_query("SET NAMES UTF8");if(!$mc){echo mysql_error();}mysql_select_db('DATABASE');$exercise_id = 7;$exercise_sets_query = "SELECT * FROM drupal_exercise_sets WHERE id = 7"; $exercise_sets = mysql_query($exercise_sets_query); while ($row = mysql_fetch_array($exercise_sets)) { $exercise_shown = true; echo '<center><fieldset style="background-color: white;"><legend>polecenie</legend><p style="font-size: 17px;">'.$row['description']; echo '</p></fieldset></center>'; echo '<form id="exercise" action="/cwiczenia/wynik-cwiczenia" method="post">'; echo '<input class="input" type="hidden" name="set" value="'.$exercise_id.'" />'; $exercises_list = explode(',', $row['exercises']); array_walk($exercises_list, 'trim'); $addon = ''; foreach ($exercises_list as $exercise_id) { $addon .= "id = '".$exercise_id."' OR "; } $addon = substr($addon, 0, -3); $exercises_query = mysql_query("SELECT * FROM drupal_exercises WHERE ".$addon." ORDER BY RAND() LIMIT ".$row['max_questions']); $count = 0; $rows = mysql_num_rows($exercises_query); while($exercise = mysql_fetch_array($exercises_query)) { $sentence_parts = explode("{:word:}", $exercise['sentence']); echo ' <p>'; echo $sentence_parts[0]; for ($i = 1; $i < count($sentence_parts); $i++) { echo ' <input class="input" type="text" id="ex_'.$exercise['id'].'" name="ex_'.$exercise['id'].'['.($i-1).']" />'; echo $sentence_parts[$i]; } echo " <script> $('#bex_".$count."').click(function() { $('table#tex_".$count."').fadeOut(250, function() { $('table#tex_".($count+1)."').fadeIn(250, function() {}); "; if ($rows == $count+2) { echo "$('form#exercise button').fadeIn(250, function(){});"; } echo " }); "; echo " return false; }); </script> "; if ($exercise['wordtypes'] == '0') { echo "<script>$('#e".$exercise['id']."').keyup(function() { var length = $(this).val().length; if (length > 0) { var character = $(this).val().charAt(0); if (character != character.toUpperCase()) { $('#hint".$exercise['id']."').text('Pamiętaj o wielkiej literze!'); } else { $('#hint".$exercise['id']."').text(''); } } });</script>"; } ++$count; } echo '<div style="margin-top: 22px; text-align: center;"><input type="submit" value="Sprawdź"/></div>'; echo '</form>'; }?>
oraz kontroler:
<?phpdrupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION); global $user;$userid = $user->uid; $mc = mysql_connect("","ROOT","PASS"); mysql_query("SET NAMES UTF8");if(!$mc){echo mysql_error();}mysql_select_db('DATABASE');/** * SKRYPT LOGOWANIA */function starts_with_upper($str) { $chr = mb_substr ($str, 0, 1, "UTF-8"); return mb_strtolower($chr, "UTF-8") != $chr;} if (isset($_POST['set']) && !empty($_POST['set'])) { $set_id = mysql_real_escape_string($_POST['set']); $exercise_sets_query = "SELECT * FROM drupal_exercise_sets WHERE id = '".$set_id."'"; $exercise_sets = mysql_query($exercise_sets_query); while ($row = mysql_fetch_array($exercise_sets)) { // Build the query $exercises_sent = array(); foreach ($_POST as $key => $value) { $prefix = substr($key, 0, 3); $prefix = mysql_real_escape_string($prefix); if ($prefix == 'ex_') { $exercises_sent[substr($key, 3)] = $value; } } if (count($exercises_sent) == 0) { echo '<div class="exercise_result">Nastąpił błąd podczas interpretowania wyników.</div>'; break; } $addon = ''; foreach ($exercises_sent as $key => $value) { $addon .= "id = '".mysql_real_escape_string($key)."' OR "; } $addon = substr($addon, 0, -3); $exercises_query = mysql_query("SELECT * FROM drupal_exercises WHERE ".$addon); // Calculate results $total_exercises = 0; $total_passed = 0; while($exercise = mysql_fetch_array($exercises_query)) { $dbWords = explode(',', $exercise['words']); foreach ($dbWords as $word) { $word = trim($word); ++$total_exercises; if (in_array($word, $exercises_sent[$exercise['id']])) { ++$total_passed; } } } // Show results echo '<h1 class="dash_bottom"><span class="yellow_dash"></span>'.$row['name'].'<span id="cwiczenia"></span></h1>'; $total = 0; if ($total_passed != 0) { $total = ($total_passed / $total_exercises)*100; $total = round($total, 2); } echo '<div class="exercise_result">Wynik: '.$total.'%</div>'; if ($user->uid==0) { echo '<p>Jeżeli chcesz aby Twoje rezultaty były zapisywane - <a href="logowanie" title="Logowanie">zaloguj się</a>.</p>'; } echo '<p><a href="/cwiczenia">Powrót do ćwiczeń</a></p>'; // Save the results mysql_query("DELETE FROM drupal_exercise_sets_completed WHERE userid = '".$userid."' AND exerciseid = '".$set_id."' "); $query = "REPLACE INTO drupal_exercise_sets_completed (`userid`, `percentage`, `exerciseid`) VALUES('".$userid."', '".$total."', '".$set_id."')"; mysql_query($query); } } /* if (!$exercise_shown) { // Zapisz dane użytkownika o podanym ID, do zmiennej $profile //$profile = user::getData($_SESSION['login'], $_SESSION['pass']); $query = "SELECT * FROM drupal_exercise_sets LEFT JOIN (SELECT id AS mid, userid, exerciseid, percentage FROM drupal_exercise_sets_completed WHERE userid='".$userid."') AS esc ON drupal_exercise_sets.id=esc.exerciseid"; $exercises = mysql_query($query); echo '<h1 class="dash_bottom"><span class="yellow_dash"></span>Ćwiczenia niemieckie<span id="cwiczenia"></span></h1>'; $total_percentage = 0; $exercises_count = 0;}*/?>
I nie mogę tego zrobić w jednym pliku, w ajaxie, by po kliknięciu w "Sprawdź" nie przeładowywało strony tylko wyświetliło część z kontrolera. Proszę bardzo o pomoc, męczę się z tym już czwarty dzień i jakoś mi nie wychodzi
Pozdrawiam.