phatgreenbuds Posted September 29, 2008 Share Posted September 29, 2008 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/126213-solved-creating-tables/ Share on other sites More sharing options...
AndyB Posted September 29, 2008 Share Posted September 29, 2008 The query is executed outside the loop, so it only happens once Quote Link to comment https://forums.phpfreaks.com/topic/126213-solved-creating-tables/#findComment-652679 Share on other sites More sharing options...
teynon Posted September 29, 2008 Share Posted September 29, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/126213-solved-creating-tables/#findComment-652681 Share on other sites More sharing options...
phatgreenbuds Posted September 29, 2008 Author Share Posted September 29, 2008 Got it figured out...shortly after I posted this I noticed the problem... The "confirm_query()" is just a function that checks if the query was ok...I am trying to be good and clean up the script using more functions. Quote Link to comment https://forums.phpfreaks.com/topic/126213-solved-creating-tables/#findComment-653086 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.