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
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
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
Share on other sites

hi guys

 

sorry for taking so long....

craygo: the line you gave me does work but there is still a problem;  there is more then one value for the answer of the first search but at the minute it only elmintates 1 of the detentiondates.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.