1

I have a page where appear a list of alumns registered to a class, above a textbox for write a name of an alumn and right side a button submit for execute the search, these textobox is for search alumns in bd that still aren't registered to that class.

When I search a alumn and I registered to class, update the page, but when I make a new search still appear the alumn that I registered before.

I thought use this query (in php)

 $q = "select * from studentsubject where studid=$studid and classid=$classid";
 $r = mysql_query($q);

These query show the alumns are registered to the class, then I want do adverse, show the list of alumns that still aren't registered to the class and hide the alumns that already are registered.

I try with stored procedure:

DELIMITER $$

CREATE PROCEDURE getStudents(in classid_val int(11), in studid_val int(11))
BEGIN

SELECT * from studentsubject WHERE classid=classid_val AND studid=studid_val
SELECT FOUND_ROWS()
IF FOUND_ROWS()>0 THEN
select * from student where id=studid_val
ELSEIF FOUND_ROWS()<0 THEN
select * from student
ENDIF;


END$$

These stored procedure do 1/2 of I want do, but it don't work when I make a search by name of alumns with the textbox that befored told.

Gedward Romo
  • 311
  • 3
  • 8
  • how about an exciting `union` – Drew Aug 20 '16 at 03:55
  • By the way, the `mysql_*` functions are [no longer supported or maintained](http://stackoverflow.com/questions/12859942). They were [deprecated in PHP 5.5.0](https://wiki.php.net/rfc/mysql_deprecation) and [removed in PHP 7.0.0](http://php.net/manual/en/function.mysql-connect.php#function.mysql-connect-refsynopsisdiv). You are strongly encouraged to migrate to either [MySQLi](http://php.net/manual/en/book.mysqli.php) or [PDO_MySQL](http://php.net/manual/en/ref.pdo-mysql.php). – Pang Sep 17 '16 at 05:20

1 Answers1

0
SELECT x.*
  FROM x
  LEFT
  JOIN y
    ON y.some_criterion = x.some_criterion
 WHERE y.some_non_nullable_column = NULL
Strawberry
  • 33,750
  • 13
  • 40
  • 57