Jump to content

double query


ec

Recommended Posts

Anyone got any idea what is wrong with this?  I am trying to search for a list of detention dates which the pupil are in and compare them to the dates which are available generating a list of dates where the pupil is available.  Any ideas?

 

 

<?php

$query1 = mysql_query("SELECT detentiondate FROM detention WHERE '".$_SESSION['pupilno']."' = pupilno ");
$row1 = mysql_fetch_assoc($query1);


$query2 = mysql_query("SELECT detentiondate FROM detentiondates WHERE detentiondate != $row1.detentiondate ");

echo '<form>';

while ($row = mysql_fetch_assoc($query2)){
   print "$row[detentiondate]";
   echo "<input type='radio' name='choice' value='{$row['detentiondate']}'><br>";

?>

Link to comment
https://forums.phpfreaks.com/topic/101183-double-query/
Share on other sites

this line

$query2 = mysql_query("SELECT detentiondate FROM detentiondates WHERE detentiondate != $row1.detentiondate ");

 

should be

 

$query2 = mysql_query("SELECT detentiondate FROM detentiondates WHERE detentiondate != '".$row1['detentiondate']."'");

 

Ray

Link to comment
https://forums.phpfreaks.com/topic/101183-double-query/#findComment-517600
Share on other sites

<?php
$query1 = mysql_query("SELECT detentiondate FROM detention WHERE '".$_SESSION['pupilno']."' = pupilno ");
$row1 = mysql_fetch_assoc($query1);

$query2 = mysql_query("SELECT detentiondate FROM detentiondates WHERE detentiondate != $row1.detentiondate ");
?>

 

Is it possible to combine those queries?

<?php
$sql = "SELECT detentiondate FROM detentiondates ds
JOIN detention d ON ds.detentiondate!=d.detentiondate
WHERE pupilno='{$_SESSION['pupilno']}'";
?>

Mostly just curious. I'm always trying to better understand JOIN and write less queries.

Link to comment
https://forums.phpfreaks.com/topic/101183-double-query/#findComment-517621
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.