Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i fill up the table with a query? 1

Status
Not open for further replies.

pooraguy

Programmer
Jan 1, 2004
3
NO
Hello all,

i need some help with this i am trying to fill up a query upto a unlimited number this is what it is


INSERT INTO `t_logins_mbs` ( `lm_key` , `fk_logins` , `fk_mbs` , `lm_started` , `lm_ended` , `lm_active` , `lm_method` , `lm_period` )
VALUES (
'', '1', '1', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '1', '', '0'
);




I want the query to go like this

INSERT INTO `t_logins_mbs` ( `lm_key` , `fk_logins` , `fk_mbs` , `lm_started` , `lm_ended` , `lm_active` , `lm_method` , `lm_period` )
VALUES (
'', '2', '2', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '1', '', '0'
);


INSERT INTO `t_logins_mbs` ( `lm_key` , `fk_logins` , `fk_mbs` , `lm_started` , `lm_ended` , `lm_active` , `lm_method` , `lm_period` )
VALUES (
'', '3', '3', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '1', '', '0'
);



What do i do .. as i have to put each one by one if i do it manually.. is there anyway i can put in place of the numbers '2' '3' and so on.. i just want the first and second instance to be going up in numbers

3 3
4 4

hope u understood :)
 
Code:
$i=1;
while($i < 1000)	
{
$query=&quot;INSERT INTO `t_logins_mbs` ( `lm_key` , `fk_logins` , `fk_mbs` , `lm_started` , `lm_ended` , `lm_active` , `lm_method` , `lm_period` ) 
VALUES (
'', '$i', '$i', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '1', '', '0'
)&quot;;
$rs2=mysql_query($query,$conn);
i++;
}
somehting like this
 
hos2 this is what i got


SQL-query :

$i = 1

MySQL said:


You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '$i=1' at line 1
 
pooraguy, create yourself an integers table containing the integers 0 through 9

[tt]create table integers (i integer);
insert into integers values
(0),(1),(2),(3),(4),(5),(6),(7),(8),(9);[/tt]

then you can generate as many numbers as you want, using cross joins

for example, here is how to populate your table with the numbers 1 through 150:

[tt]insert
into t_logins_mbs
( fk_logins
, fk_mbs
)
select hundreds.i*100 + tens.i*10 + units.i
as logins
, hundreds.i*100 + tens.i*10 + units.i
as mbs
from integers hundreds
cross
join integers tens
cross
join integers units
where hundreds.i*100 + tens.i*10 + units.i
between 1 and 150[/tt]

hang on to that integers table, it will come in handy for many other situations


rudy
 
r937 a very hand solution and star for this



[ponder]
----------------
ur feedback is a very welcome desire
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top