Jump to content

Can't figure this out


Archadian

Recommended Posts


echo "<table class=\"gena\" align=\"center\" valign=\"top\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"480\">";

eh();

$user = mysql_query("SELECT uname FROM users") or die("Users.");
$chk = mysql_fetch_array($user);

while($chkuser = $chk['uname']) {

	roster();

	$roster = mysql_query("SELECT name, note FROM roster_members WHERE name NOT LIKE '$chkuser' AND note NOT LIKE '%alt%'") or die("Roster.");

		while($for = mysql_fetch_array($roster)) {

			$ros = $for['name'];

			echo "<tr>";
			echo "<td align=\"center\" valign=\"top\" width=\"448\" height=\"27\">" . $ros . "</td>";
			echo "</tr>";

	}

}

echo "</table>";

 

I have been playing around with this and can't seem to get this to work at all. I am trying to get a list of names from the "roster DB" and compare it to the "user DB" and make a list of all the names in the Roster DB that aren't listed in the user DB. Confused? I know what im trying to do but i just can't seem to get it to work. If anyone has any ideas please let me know. This is driving me crazy. Thanks in advance :)

Link to comment
Share on other sites

Thx skali, i tried that and it printed everything out from the roster DB twice. I did this:

 


echo "<table class=\"gena\" align=\"center\" valign=\"top\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"480\">";

eh();

$user = mysql_query("SELECT uname FROM users") or die("Users.");
$chk = mysql_fetch_array($user);

$chkuser = $chk['uname'];

	roster();

	$roster = mysql_query("SELECT name, note FROM roster_members WHERE name NOT LIKE '$chkuser' AND note NOT LIKE '%alt%'") or die("Roster.");

		while($for = mysql_fetch_array($roster)) {

			$ros = $for['name'];

			echo "<tr>";
			echo "<td align=\"center\" valign=\"top\" width=\"448\" height=\"27\">" . $ros . "</td>";
			echo "</tr>";

	}

echo "</table>";

 

But now its printing everything out from the roster DB only once but its not comparing the names to the user DB and leaving those names out.

Link to comment
Share on other sites

Tried it and it didn't work. the names of the tables are roster_members (roster DB) and eh_users (ehforums DB). Im trying to compare the names in both DB's and return the names from the roster DB that does not match the names in the ehforums DB. Trying to make a list of who hasn't registered for the forums yet. Hopefully it clears this up. Thanks :)

 

Don't mind the actual names of the tables in my code, im pulling the info from a different table now. what i explained above is what im trying to do.

Link to comment
Share on other sites

pretty inefficient method, but if you're not gonna do it all the time and you NEED it done

you could use a loop for all roster A and inside run query to check against B

 

i.e.

$a_query = mysql_query("SELECT name from roster_a");

while($row = mysql_fetch_object($a_query)){

$a_name = $row->name;

$b_query = mysql_query("SELECT name from roser_b WHERE `name`='$a_name'");
if(mysql_num_rows($b_query) = 1)

etc...

Link to comment
Share on other sites

This sounds like a job for left join!

 

SELECT name
FROM roster_members
LEFT JOIN users
ON (roster_members.name = users.name)
WHERE users.name IS NULL

 

Why does it work?  A left join will keep rows from the left table even when there is no match in the right table.  It will fill the right table with NULL for every column for the rows that don't match.  So to check for "no match", you just check if any column from the right table is null.  This won't work if that column really can be null of course, but I assume users.name is never null.

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.