Mark Henry
Mark Henry

Reputation: 2699

The results of 2 queries in one while loop

I want to plot three dataseries in jquery flot the first two series are the snowdepth in the last 10 weeks (upper and lower mountain). The last one is the snowdepth for the upper slopes one year earlier. I use two queries for this exercice and I want to merge the results into one while loop. This is what i have so far but the dataseries stay empty (d1,d2,d5). What am I doing wrong?

$yrwk = $curryear . $currweek;
$rQuery21 = "select wk, yr, snow_valley, snow_mountain from sv_cond_vw where res_id=$res_id AND yrwk<$yrwk order by yrwk desc limit 11";
$rResult21 = mysql_query($rQuery21);

$lyrwk = $lastyear . $currweek;
$lQuery21 = "select snow_mountain from sv_cond_vw where res_id=$res_id AND yrwk<$yrwk order by lyrwk desc limit 11";
$lResult21 = mysql_query($lQuery21);

while ($rows21 = mysql_fetch_array($rResult21) && $lrows21 = mysql_fetch_array($lResult21))
{
$wk = $rows21['wk'];
$yr = $rows21['yr'];

$wk=date('d-m-Y', getDateFromWeek($wk, $yr));
$wk = strtotime($wk);
$wk=$wk*1000;

$snow_mnt = $rows21['snow_mountain'];
$snow_val = $rows21['snow_valley'];
$d1 .= '[' . $wk . ',' . $snow_mnt . '],';
$d2 .= '[' . $wk . ',' . $snow_val . '],';

$lsnow_mnt = $lrows21['snow_mountain'];
$d5 .= '[' . $wk . ',' . $lsnow_mnt . '],';
}

Upvotes: 1

Views: 2678

Answers (2)

Toto
Toto

Reputation: 91448

In your first query, you do SELECT wk, yr and in the WHERE clause, you do WHERE yrwk < $yrwk.

Have you really these 3 fields in your table ? If not, you should do:

WHERE CONCAT(yr, wk) < $yrwk

Upvotes: 1

Marcin
Marcin

Reputation: 238339

Assuming that your queries work, I think that you should change '&&' into 'and' as '&&' has higher precedence than '=' and thus $rows21 is not set properly.

Upvotes: 3

Related Questions