HomeLập trìnhPhpLàm cách nào...

Làm cách nào để hiển thị dữ liệu vòng lặp PHP bằng Jquery hoặc PHP? – JavaScript


tôi có tệp php này. Tôi muốn hiển thị cùng một trường nhập liệu ở cả hai nơi, thực ra tôi muốn gì, tôi muốn có một hộp nhập liệu sau câu hỏi, trường mẫu $clue.="<input type="text" id='field_2'>"; tôi muốn đến đây cùng một trường vòng lặp những gì đã được tạo ra trong <input id="field_1" class="active_textfeild <?php echo $cell_class;?>" type="text" name="cell_<?php echo $i; ?>" value="" maxlength="1" />

tôi muốn viết cùng một trường, tôi biết jQuery có thể làm điều đó, nhưng còn trường đầu vào thì sao, cách tạo vòng lặp php cùng một trường ở đây

nhập mô tả hình ảnh ở đây

<?php
function dkcpg_ajaxurl() {
	?>
	<script type="text/javascript">
		var ajaxurl="<?php echo admin_url("admin-ajax.php'); ?>';
	</script>
	<?php
}
add_action('wp_head','dkcpg_ajaxurl');
// register jquery and style on initialization
function dkcpg_register_front_script_style(){
	wp_register_script( 'dkcpg_front_script1', plugins_url('/js/script.js', __FILE__));
	wp_register_script( 'dkcpg_front_script2', plugins_url('/js/autocopy.js', __FILE__));
	wp_register_style( 'dkcpg_front_style', plugins_url('/template/front/css/style.css', __FILE__));
}
add_action('init', 'dkcpg_register_front_script_style');
// use the registered jquery and style above
function dkcpg_enqueue_front_script_style(){
	wp_enqueue_script('jquery');
	wp_enqueue_script('dkcpg_front_script1');
	wp_enqueue_script('dkcpg_front_script2');
	wp_enqueue_style( 'dkcpg_front_style' );
}
if ( !is_admin() )
	add_action('wp_enqueue_scripts', 'dkcpg_enqueue_front_script_style');
//  ajax 
add_action( 'wp_ajax_crossword_score', 'crossword_score' );
add_action( 'wp_ajax_nopriv_crossword_score', 'crossword_score' );
function crossword_score()
{
	global $wpdb;
	if(isset($_POST['crossword_id']))
	{ 
		$crossword_id = $_POST['crossword_id'];
		$query = "SELECT * FROM `".$wpdb->prefix."crossword` WHERE `crossword_status` = 'Y' AND `crossword_id` = '$crossword_id' LIMIT 0,1";
		$res = $wpdb->get_results($query,ARRAY_A);
		$accross_clues="";
		$down_clues="";
		if(count($res)>0)
		{
			$query = "SELECT * FROM `".$wpdb->prefix."crossword_word` WHERE `crossword_id` = '".$res[0]['crossword_id']."'";
			$cell_letter = $wpdb->get_results($query,ARRAY_A);
			$correct_ans =0;
			$questions_no = 0;
			for($i=0;$i<count($cell_letter);$i++)
			{
				$questions_no++;
				$cell=unserialize($cell_letter[$i]['word_letter_cell']);
				$answer_flag = 'yes';
				foreach($cell as $key=>$value) 
				{ 
					if(isset($_POST['cell_'.$key]))
					{
						if(strtoupper($_POST['cell_'.$key]) != strtoupper($value))
						{
							$answer_flag = 'no';
						}
					}
					else
					{
						$answer_flag = 'no';
					}
				} 
				if($answer_flag == 'yes')
				{
					$correct_ans++;
				}
				unset($cell);
				$clue="<p>".$cell_letter[$i]['word_order'].') '.$cell_letter[$i]['word_text'].'</p>';
				if($cell_letter[$i]['word_direction'] == 'A')
				{
					$accross_clues.=$clue;
				}
				else
				{
					$down_clues.=$clue;
				}
			}
			$score = 0;
			if($correct_ans > 0 && $questions_no>0)
			{
				$score = ($correct_ans/$questions_no)*100;
			}
			?>

			<h4>Score : <?php echo round($score,2);?>%</h4>
			<h4>Correct : <?php echo $correct_ans;?></h4>
			<h4>Wrong : <?php echo $questions_no-$correct_ans;?></h4>
			<?php
		}
	}
	die();
}
function crossword_load()
{	
	global $wpdb;
	$category_id = 0;
	if(isset($_REQUEST['category_id']))
	{
		$category_id = $_REQUEST['category_id'];
	}
	$crossword_id = 0;
	if(isset($_REQUEST['crossword_id']))
	{
		$crossword_id = $_REQUEST['crossword_id'];
	}
	$new_crossword_id = 0;
	if(isset($_REQUEST['new_crossword_id']))
	{
		$new_crossword_id = $_REQUEST['new_crossword_id'];
	}
	?>
	<div class="dk_outer_wrapper">
		<div class="crossword_outer_wrapper">
			<ul class="menu_wrapper">
				<li>
					<select id="crossword_category_switch" class="common_btn" >
						<option value="0" selected="selected" > Select Category</option>
						<?php
						$query = "SELECT * FROM `".$wpdb->prefix."crossword_category` WHERE `category_status` = 'Y' ";
						$res = $wpdb->get_results($query,ARRAY_A);
						for($i=0;$i<count($res);$i++)
						{
							?>
							<option value="<?php echo $res[$i]['category_id']; ?>" <?php if($res[$i]['category_id'] == $category_id) { ?> selected="selected" <?php } ?> ><?php echo stripslashes($res[$i]['category_title']); ?></option>
							<?php
						}
						unset($res);
						?>
					</select>
				</li>
				<li>
					<select id="crossword_game_switch" class="common_btn" >
						<option value="0" selected="selected" > Select Game</option>
						<?php
						$query = "SELECT * FROM `".$wpdb->prefix."crossword` WHERE `crossword_status` = 'Y' ";
						if(intval($category_id))
						{
							$query.= " AND `category_id` = '$category_id'";
						}
						$res = $wpdb->get_results($query,ARRAY_A);
						for($i=0;$i<count($res);$i++)
						{
							?>
							<option value="<?php echo $res[$i]['crossword_id']; ?>" <?php if($res[$i]['crossword_id'] == $new_crossword_id) { ?> selected="selected" <?php } ?> ><?php echo stripslashes($res[$i]['crossword_title']); ?></option>
							<?php
						}
						unset($res);
						?>
					</select>
				</li>
			</ul>
			<div class="crossword_outer_main">
				<?php
				if(intval($new_crossword_id))
				{
					$query = "SELECT * FROM `".$wpdb->prefix."crossword` WHERE `crossword_status` = 'Y' AND `crossword_id` = '$new_crossword_id' ";
					$res = $wpdb->get_results($query,ARRAY_A);
				}
				else
				{
					$query = "SELECT * FROM `".$wpdb->prefix."crossword` WHERE `crossword_status` = 'Y' AND `crossword_id` != '$crossword_id' ORDER BY RAND() LIMIT 0,1";
					$res = $wpdb->get_results($query,ARRAY_A);
				}
				if(count($res)==0)
				{
					$query = "SELECT * FROM `".$wpdb->prefix."crossword` WHERE `crossword_status` = 'Y' ORDER BY RAND() LIMIT 0,1";
					$res =  $wpdb->get_results($query,ARRAY_A);
				}
				if(count($res)==0)
				{
					?>
					<p>No crossword game.</p>
					<?php
				}
				else
				{
					?>
					<form method="post" action="<?php echo $_SERVER['REQUEST_URI'];?>" id="crossword_reload" >
						<input type="hidden" name="crossword_id" id="reoload_crossword_id" value="<?php echo $res[0]['crossword_id']; ?>" />
						<input type="hidden" name="category_id" id="reoload_category_id" value="<?php echo $category_id; ?>" />
						<input type="hidden" name="new_crossword_id" id="reoload_new_crossword_id" value="0" />
					</form>
					<h2><?php echo stripslashes($res[0]['crossword_title']); ?></h2>
					<div class="crossword_box_section">
						<div class="crossword_game_box">
							<form id="crossword_frm">
								<input type="hidden" name="action" value="crossword_score"  />
								<input type="hidden" name="crossword_id" value="<?php echo $res[0]['crossword_id']; ?>" />
								<div class="crossword-table">
									<?php 
									$query = "SELECT * FROM `".$wpdb->prefix."crossword_word` WHERE `crossword_id` = '".$res[0]['crossword_id']."'";
									$cell_letter = $wpdb->get_results($query,ARRAY_A);
									$cell  = array();
									$cell_start  = array();
									$cell_start_cell_no_a  = array();
									$cell_start_cell_no_d  = array();
									$accross_clues="";
									$down_clues="";
									for($i=0;$i<count($cell_letter);$i++)
									{
										$cell_letter_temp = unserialize($cell_letter[$i]['word_letter_cell']);
										$cell_letter_implode = implode(",", array_keys($cell_letter_temp));
										$clue="<p><strong>Start Cell : <a class="start_cell_marker" href="".$cell_letter_implode.'"> <b>'.$cell_letter[$i]['word_start_cell'].'<b></a></strong><br /> <strong>Clue : </strong>';
										if(!empty($cell_letter[$i]['word_clue_text']))
											$clue.= stripslashes($cell_letter[$i]['word_clue_text']).' <br />rfdfd';
										$clue.="<input type="text" id='field_2'>";
										if(!empty($cell_letter[$i]['word_clue_img']))
											$clue.= ' <br /><img src="'.DKCPG_SITE_URL.'wp-content/uploads'.$cell_letter[$i]['word_clue_img'].'"  /><br />';
										if(!empty($cell_letter[$i]['word_clue_audio']))
											$clue.= '<object type="application/x-shockwave-flash" data="'.DKCPG_PLUGIN_URL.'player/audio/player.swf" id="word_clue_audio_'.$i.'" height="24" width="80" >
										<param name="movie" value="'.DKCPG_PLUGIN_URL.'player/audio/player.swf">
										<param name="FlashVars" value="playerID=word_clue_audio_'.$i.'&soundFile=".DKCPG_SITE_URL."wp-content/uploads'.$cell_letter[$i]['word_clue_audio'].'">
										<param name="quality" value="high">
										<param name="menu" value="false">
										<param name="wmode" value="transparent">
										</object> <br />';
										$clue.='<strong class="answer_word"> Ans : '.$cell_letter[$i]['word_text'].'</strong></p>';
										if($cell_letter[$i]['word_direction'] == 'A')
										{
											$accross_clues.=$clue;
											$cell_start_cell_no_a[$cell_letter[$i]['word_start_cell']] = $cell_letter_implode;
										}
										else
										{
											$down_clues.=$clue;
											$cell_start_cell_no_d[$cell_letter[$i]['word_start_cell']] = $cell_letter_implode;
										}
										$cell+=$cell_letter_temp;
										$cell_start[]=$cell_letter[$i]['word_start_cell'];
									}
									for($i=1;$i<121;$i++)
									{
										if(array_key_exists($i, $cell)) 
										{
											$cell_class="activecell";
										}
										else
										{
											$cell_class="blankcell";
										}
										?>
										<div class="cell <?php echo $cell_class;?>" >
											<span >
												<?php if(in_array($i, $cell_start)) { 
													$cell_start_cell_nos="";
													if(array_key_exists($i, $cell_start_cell_no_a)) { 
														$cell_start_cell_nos.= $cell_start_cell_no_a[$i];
													}
													if(array_key_exists($i, $cell_start_cell_no_d)) { 
														if($cell_start_cell_nos != '')
															$cell_start_cell_nos.=',';
														$cell_start_cell_nos.= $cell_start_cell_no_d[$i];
													}
													if($cell_start_cell_nos == '')
													{
														$cell_start_cell_nos = $i;
													}
													?>
													<a href="<?php echo $cell_start_cell_nos; ?>" class="in_cell_start_marker"> <?php echo $i; ?> </a> <?php } else {?>&nbsp;<?php } ?>
												</span>
												<input id="field_1" class="active_textfeild <?php echo $cell_class;?>" type="text" name="cell_<?php echo $i; ?>" value="" maxlength="1" />
											</div>
											<?php
										}
										?>
									</div>
								</form>          
							</div>
							<div class="btn_outer">
								<div class="common_btn"><a href="#" id="crossword_check_score">Check Score</a></div>
								<div class="common_btn"><a href="#" id="crossword_new_game">New Game</a></div>
							</div>
						</div>
						<div class="crossword_right_section">
							<div class="crossword_score">
							</div>
							<div class="question_wrapper">
								<div class="leftcontainer">
									<h2>Across</h2>
									<?php echo $accross_clues;?>
									<??>
								</div>
								<div class="rightcontainer">
									<h2>Down</h2>
									<?php echo $down_clues;?>
								</div>
							</div>
						</div>
						<?php	}?>
				</div>
			</div>
		</div>
		<?php
	}
	add_shortcode( 'crossword', 'crossword_load' );



Zik.vn – Biên dịch & Biên soạn Lại

Đọc thêm  Làm cách nào để lấy địa chỉ ip của tôi trong php?
spot_img

Create a website from scratch

Just drag and drop elements in a page to get started with Newspaper Theme.

Buy Now ⟶

Bài viết liên quang

DMCA.com Protection Status