Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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