Jump to content

[SOLVED] Creating tables


phatgreenbuds

Recommended Posts

Any idea why this would not work? I expected it to create a table and then populate that table with 24 rows...all I get is the 24th row.

 

<?php
$sql = "CREATE TABLE $tblname
(
content_id INT( NOT NULL AUTO_INCREMENT, 
content_win_path VARCHAR(50) NOT NULL,
tbl_hour INT(3) NOT NULL,
tbl_slot INT(3) NOT NULL,
PRIMARY KEY (content_id)
)";

mysql_query($sql,$dbconn);

$count = 1;
while ($count <= 24) {
	$query="INSERT INTO $tblname (tbl_hour) VALUES ('$count')";
	$count++;
	}
	$addcon = mysql_query($query);
	confirm_query($addcon);
?>

Link to comment
https://forums.phpfreaks.com/topic/126213-solved-creating-tables/
Share on other sites

You need to run your query every time the loop is executed. You should however, look into doing it like this:

$query="INSERT INTO $tblname (tbl_hour) VALUES ";

while ($count <= 24)

  {

  $query.="('$count'),";

  count++;

  }

$query=substr($query, 0, -1);

$addcon = mysql_query($query);

confirm_query($addcom);

 

----

By the way, what does confirm_query do?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.