0

I have two queries that will be executed simultaneously. What should I do? Thanks for any help :-). Here is my code:

$sql1 = mysql_query("SELECT tregmk.kmk,tmmatakuliah.nmk,ifnull(tmmatakuliah.sks,0) AS sks FROM tregmk JOIN tmmatakuliah 
                                ON (tregmk.kmk=tmmatakuliah.kmk) LEFT JOIN v_all_nilai_kk ON ((tregmk.kmk=v_all_nilai_kk.kmk) AND 
                                (v_all_nilai_kk.stambuk=$_SESSION[stambuk]) AND (v_all_nilai_kk.nilai > 2)) WHERE (tregmk.tahunajarn=$thajaran) 
                                and (tregmk.semester=$smster) AND (tregmk.fakultas=$fakpilihan) AND (tregmk.prodi=$prodi) AND (tregmk.jenjang=$jenjang) AND 
                                (v_all_nilai_kk.kmk is null) AND (tmmatakuliah.nokur=$no_kur)");



$sql2 = mysql_query("SELECT trkrs.nid,trkrs.iplalu,trkrs.sksdicapai,trkrs.sksrencana,trkrs.sksdiambil,
                        trkrs.ipk,trkrs.konsentrasi,trkrs.tanggal,tdkrs.kmk,tdkrs.statskmk,tdkrs.tanggal,tmdos.nid,tmdos.nama,
                        tmmhs.nasert FROM trkrs JOIN tdkrs ON (trkrs.idkrs=tdkrs.idkrs),tmmhs,tmdos where
                        (tmmhs.stambuk=right(trkrs.idkrs,10)) AND (tmdos.nid=trkrs.nid) AND (trkrs.idkrs=$idkrs)");
waterfall
  • 9
  • 4
  • fetch result simultaneously. – devpro Jan 27 '16 at 08:30
  • What exactly is your problem? Do you want to _combine_ both queries into one transaction, or are you asking about a possible race condition? – Tim Biegeleisen Jan 27 '16 at 08:30
  • Why are you still using the [deprecated `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php?rq=1)? Anyway, if you want them to operate on the same dataset using transactions should be enough... – ThiefMaster Jan 27 '16 at 08:35
  • I want to combine both queries into one transaction. – waterfall Jan 27 '16 at 08:50

1 Answers1

0

Why do you need to run them at the same time? It doesn't look like either well affect the result of the other, so why can't you just run them one after the other then use the results?

If you MUST run them at the same time, you'll have to combine them into a single query and use the results from that - but practically that would be no different to running them right after each other anyway.

If there reason is based on time, you could just pull the time when each query is run and use that?

Matthew Lymer
  • 992
  • 6
  • 10