MLUG: RE: [MLUG] mysql problem
RE: [MLUG] mysql problem
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
There is another problem with your code.

Let me first state again what you are trying to do.

You are selecting all the values of a table where one value = something
then you want to only take the top ten records and write those to the
new table.

The problem is that you are telling the program to select everything you
are then putting in a loop which looks correct, but the code after the
loop is just going write everything into the database the very first
time. In reality the loop should write every record you selected 10
times into the table. 

You are going to need to loop through the records, it is not enough to
just tell the program to loop in this case. Unfortunately I do not have
the answer for you, I think one of the previous answers would work
better, but that is the fundamental flaw with your code.

> -----Original Message-----
> From: EMAIL:PROTECTED [mailto:members-
> EMAIL:PROTECTED] On Behalf Of mehmood hasan
> Sent: Tuesday, September 16, 2003 3:43 AM
> To: EMAIL:PROTECTED
> Subject: [MLUG] mysql problem
> 
> hi
> i am inserting values from table "marksquery" to table "chemistry"
> in descendig order by the query m_marks and select only values of
subjects
> =
> "CHM" by the query
> 
> mysql_query("INSERT INTO chemistry
> (f_name,l_name,m_marks,province,subjects,id) select
> markstable.f_name,l_name,m_marks,
> province,subjects,id from markstable where subjects = 'CHM' order by
> m_marks
> ASC");
> 
> this query is working well but i want to insert only 10 rows from
table
> "marksquery" to table "chemistry" i defined check for this and also
> defined
> loop as
> for($i=1; $i<=10; $i++)
> {
> mysql_query("INSERT INTO
> chemistry(f_name,l_name,m_marks,province,subjects,id) select
> markstable.f_name,l_name,m_marks,
> province,subjects,id from markstable where subjects = 'CHM' order by
> m_marks
> ASC");
> 
> but this not works and it insert all the rows of subjects ="CHM" from
> table
> "marksquery" to table "chemistry"
> I want to insert only First 10 rows.Any one can help me
> regards
> 
> _________________________________________________________________
> MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
> http://join.msn.com/?page=features/virus
> 
> _______________________________________________
> members mailing list
> EMAIL:PROTECTED
> http://mlug.missouri.edu/mailman/listinfo/members


_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members