저는 php와 svg를 처음 사용하고 있습니다. 여기 내 코드는 다음과 같습니다.PHP 서버를 새로 고치는 방법
<?php
// Print a login-id
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")
or die(mysql_error());
while($info = mysql_fetch_array($check))
{
$targetNo = "1";
if(!empty($_GET)) {
$targetNo = $_GET["newT"];
}
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
$data = mysql_query("SELECT * FROM alphabet where id >= $targetNo;")
or die(mysql_error());
?>
<aside style="font-size:larger;font-style:italic;color:green;float:left;width:100px;">
<div style="background:pink;height:710px">
Username: <?php print $username ?>
<br><br><br><br>
Score: <?php print $targetNo-1 ?>
</aside>
<aside style="float:left;width:1000px;">
<div style="background:lightblue;height:710px">
<svg onload='Init(evt)'>
<title>Fish Game</title>
<SCRIPT LANGUAGE='JavaScript'>
var SVGDocument = null;
var SVGRoot = null;
function Init(evt) {
SVGDocument = evt.target.ownerDocument;
SVGRoot = SVGDocument.documentElement;
}
function ToggleOpacity(evt, targetId, targNo) {
if(targetId == parseInt(targNo)) {
newTarget = SVGDocument.getElementById(targetId);
newTarget.setAttributeNS(null, 'opacity', '0');
targetId++;
document.location="AtoZ.php?newT=" + targetId;
}
}
</script>
<?php
// status
$a= mysql_query("SELECT * FROM alphabet where id = $targetNo;")
or die(mysql_error());
$targetAlphabet = mysql_fetch_array($a);
$target = $targetAlphabet['Alphabet'];
?>
// status
<text x="10"
y="20"
style="font-family:Times,serif;fill:#B40404;font-size:20px"
>Please find the letter: <?php print $target ?></text>
//Fish
<?php
static $info;
while ($info = mysql_fetch_array($data)) {
$id = $info['ID'];
$al = $info['Alphabet'];
?>
//fish body
<g id='<?php print $id; ?>' onclick='ToggleOpacity(evt, id,"<?php print $targetNo ?>")'>
<circle cx="<?php print $info['body_cx']; ?>"cy="<?php print $info['body_cy']; ?>" r="<?php print $info['body_r']; ?>" stroke="black" stroke-width="1" fill="<?php print $info['body_fill']; ?>" />
//tail
<path d="<?php print $info['tail']; ?>" fill="<?php print $info['tail_fill']; ?>" stroke="<?php print $info['tail_stroke']; ?>" stroke-width="1" />
//eye
<circle cx="<?php print $info['eye_cx']; ?>" cy="<?php print $info['eye_cy']; ?>" r="<?php print $info['eye_r']; ?>" stroke="black" stroke-width="1" fill="<?php print $info['eye_fill' ];?>" />
<circle cx="<?php print $info['pupil_cx']; ?>" cy="<?php print $info['pupil_cy']; ?>" r="<?php print $info['pupil_r']; ?>" stroke="black" stroke-width="1 " />
//'Alphabet'
<text x="<?php print $info['al_x']; ?>" y="<?php print $info['al_y']; ?>" style="font-family:Times,serif;fill:#B40404;font-size:<?php print $info['size']; ?>"><?php print $al; ?></text>
<animateMotion
from="<?php print $info['from']; ?>" to="<?php print $info['to']; ?>"
dur=" <?php print $info['duration']; ?>" repeatCount="indefinite" />
</g>
<?php
}
}
?>
</svg>
</aside>
<?php
}
?>
나는 알파벳 순서로 기본 인 물고기를 클릭해야하는이 게임을 만들고 있습니다. 현재 물고기를 클릭하는 동안 페이지를 새로 고침하여 서버를 업데이트합니다. 따라서 페이지를 새로 고치지 않고 서버를 업데이트 할 수있는 방법이 있습니까? 내 코드에는 애니메이션이 있으므로 물고기가 클릭되어 사라질 때마다 페이지가 새로 고쳐져 물고기 애니메이션이 다시 시작됩니다. 물고기가 멈추지 않고 계속 움직이기를 원합니다. 서버를 지속적으로 업데이트 할 수있는 방법이 있습니까? 내 애니메이션이 mysql에 연결되어있다.
나는 혼자 할 수 없기 때문에 진지하게 조언이 필요하다.
'AJAX'에 대한 연구. – mellamokb
AJAX를 보시고 예를 들어이 링크를 사용해보십시오. http://stackoverflow.com/questions/5143191/inserting-into-mysql-from-php-jquery-ajax –
새로 고침 div를 사용할 수 있습니까? – Trifers