sql 쿼리, for문~~ 정보
sql 쿼리, for문~~본문
for문을 통해, 테이블 필드 안에, 생성 하려고 그러는데, 데이터가 생성 되지 않네요... ㅠㅠ
지금 테이블 및 필드는 생성되어있습니다.~~
소스는 아래와 같습니다.
<?
include_once("./_common.php");
if($mode=="create")
{
for($i = 100000; $i <= 999999; $i++) {
$sql = "insert into non_mb (bk_num) values ($i)";
}
$result = mysql_query($sql);
if(!$result)
{
echo "<script>
window.alert('생성실패입니다. 재확인바랍니다');
history.go(-1);
</script>";
exit;
}
echo "<script>
window.alert('데이터가 생성되었습니다.');
</script>";
echo "<meta http-equiv='refresh' content='0;url={$g4[path]}/'>";
exit;
}//mode=create의 끝
?>
<html>
<head>
<style>
body,table{font-size:12px;font-family:굴림;}
</style>
</head>
<body>
<center>
<table border=0 cellpadding=0 cellspacing=1 bgcolor=#cccccc width=500>
<form name=form1 method=post action="<?=$PHP_SELF?>">
<tr height=25 bgcolor=#f2f2f2>
<td align=center ><b>popup 테이블 생성하기</b></td>
</tr>
<tr height=50 bgcolor=#ffffff>
<td align=center >생성.</td>
</tr>
<tr height=25 bgcolor=#f2f2f2>
<td align=center >
<input type=hidden name="mode" value="create">
<input type=submit value="테이블 생성"></td>
</tr>
</form>
</table>
</center>
</body>
</html>
지금 테이블 및 필드는 생성되어있습니다.~~
소스는 아래와 같습니다.
<?
include_once("./_common.php");
if($mode=="create")
{
for($i = 100000; $i <= 999999; $i++) {
$sql = "insert into non_mb (bk_num) values ($i)";
}
$result = mysql_query($sql);
if(!$result)
{
echo "<script>
window.alert('생성실패입니다. 재확인바랍니다');
history.go(-1);
</script>";
exit;
}
echo "<script>
window.alert('데이터가 생성되었습니다.');
</script>";
echo "<meta http-equiv='refresh' content='0;url={$g4[path]}/'>";
exit;
}//mode=create의 끝
?>
<html>
<head>
<style>
body,table{font-size:12px;font-family:굴림;}
</style>
</head>
<body>
<center>
<table border=0 cellpadding=0 cellspacing=1 bgcolor=#cccccc width=500>
<form name=form1 method=post action="<?=$PHP_SELF?>">
<tr height=25 bgcolor=#f2f2f2>
<td align=center ><b>popup 테이블 생성하기</b></td>
</tr>
<tr height=50 bgcolor=#ffffff>
<td align=center >생성.</td>
</tr>
<tr height=25 bgcolor=#f2f2f2>
<td align=center >
<input type=hidden name="mode" value="create">
<input type=submit value="테이블 생성"></td>
</tr>
</form>
</table>
</center>
</body>
</html>
댓글 전체
$sql = "insert into non_mb (bk_num) values ($i)";
다음과 같이 수정.
$sql = "insert into non_mb set bk_num = '$i' ";
다음과 같이 수정.
$sql = "insert into non_mb set bk_num = '$i' ";
답변감사드립니다.^^
하지만, 수정후, 역시나 되지 않네요... ㅠㅠ
하지만, 수정후, 역시나 되지 않네요... ㅠㅠ
for($i = 100000; $i <= 999999; $i++) {
$sql = "insert into non_mb (bk_num) values ($i)";
}
$result = mysql_query($sql); <--- for문 내에서 쿼리를 실행해야 디비에 저장 되죠
for문이 끝나고 쿼리문을 한번만 실행하고 있잖아요
} 안으로 옮기세요
그리고 그누보드에서는 mysql_query($sql) 대신 그냥 sql_query($sql) 하면 됩니다
$sql = "insert into non_mb (bk_num) values ($i)";
}
$result = mysql_query($sql); <--- for문 내에서 쿼리를 실행해야 디비에 저장 되죠
for문이 끝나고 쿼리문을 한번만 실행하고 있잖아요
} 안으로 옮기세요
그리고 그누보드에서는 mysql_query($sql) 대신 그냥 sql_query($sql) 하면 됩니다