fer0an Posted November 13, 2010 Share Posted November 13, 2010 hello I'm using some code for add data into one table. I need add on tid number from 1 to 26200 also I need for each 5 number on cid one number for example tid---------------cid 1-----------------1 2-----------------1 3-----------------1 4-----------------1 5-----------------1 6-----------------2 7-----------------2 8-----------------2 9-----------------2 10---------------2 11---------------3 12---------------3 13---------------3 14---------------3 15---------------3 . . . . below is my code , can anyone help me? <?php $dbuser = "***"; $dbpass = "***"; $dbhost = "localhost"; $dbname = "***"; // Connecting, selecting database $con = mysql_connect($dbhost, $dbuser, $dbpass) or die('Could not connect: ' . mysql_error()); mysql_select_db($dbname) or die('Could not select database'); $tid=1; while( $tid<=26200){ $query="INSERT INTO `jos_tag_term_content` ( `tid` , `cid` ) VALUES ( '".$tid."', '$cid' ) "; $tid++; if (!mysql_query($query,$con)) { die('Error: text add' . mysql_error()); } } ?> Link to comment https://forums.phpfreaks.com/topic/218586-help-code/ Share on other sites More sharing options...
Andy-H Posted November 13, 2010 Share Posted November 13, 2010 <?php $dbuser = "***"; $dbpass = "***"; $dbhost = "localhost"; $dbname = "***"; // Connecting, selecting database $con = mysql_connect($dbhost, $dbuser, $dbpass) or die('Could not connect: ' . mysql_error()); mysql_select_db($dbname) or die('Could not select database'); $tid = 1; $cid = 1; while( $tid<=26200){ $query="INSERT INTO `jos_tag_term_content` ( `tid` , `cid` ) VALUES ( '".$tid."', '$cid' ) "; $tid++; if ($tid % 5 == 0) { $cid++; } if (!mysql_query($query,$con)) { die('Error: text add' . mysql_error()); } } ?> Link to comment https://forums.phpfreaks.com/topic/218586-help-code/#findComment-1133842 Share on other sites More sharing options...
requinix Posted November 13, 2010 Share Posted November 13, 2010 So what's the point of this table? Trying to use a database table in place of simple math? function tid2cid($tid) { return floor(($tid - 1) / 5) + 1; } Link to comment https://forums.phpfreaks.com/topic/218586-help-code/#findComment-1133851 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.