Page 1 of 1
Simple SELECT * where id IS NOT EQUAL TO....???
Posted: Tue Feb 02, 2010 10:10 am
by simonmlewis
Code: Select all
$rejectoffer = mysql_query ("SELECT * FROM offers WHERE sellerprodid = '$sellerprodid' AND buyerprodid <> '$buyerprodid'");
This is not being liked by my machine.
I thought <> or != would work.
How do you state that you want to find items in the table where something is NOT EQUAL to something.
So if I pass "3" to a database, and I want everything that isn't a 3...........??
Re: Simple SELECT * where id IS NOT EQUAL TO....???
Posted: Tue Feb 02, 2010 11:08 am
by simonmlewis
Here's all the code.
My error (shown further below) is about line 48 and 65.
48 is "while($rowoffer.....)"
65 is "mysql_free_result($result2);".
Code: Select all
$rejectoffer = mysql_query ("SELECT * FROM offers WHERE sellerprodid = '$sellerprodid' AND buyerprodid != $buyerprodid");
while ($rowoffer = mysql_fetch_object($rejectoffer))
{
$result2 = mysql_query ("SELECT email, firstname, lastname FROM users WHERE id == '$rowoffer->buyerid'");
while ($row2 = mysql_fetch_object($result2))
{
$to = "$row2->email";
$subject = "domain Rejected";
$headers = "From: noreply@domain.co.uk";
$body = "** This email account is not monitored - please do not reply. **
Dear $row2->firstname $row2->lastname
We are sorry to inform you that an offer you have made has been rejected. Please login to see which item you are being emailed about.
Best regards
";
mail ($to, $subject, $body, $headers);
}
mysql_free_result($result2);
}
mysql_free_result($rejectoffer);
Re: Simple SELECT * where id IS NOT EQUAL TO....???
Posted: Tue Feb 02, 2010 5:39 pm
by social_experiment
Try :
Code: Select all
<?php $rejectoffer = mysql_query ("SELECT * FROM offers WHERE sellerprodid = '$sellerprodid' AND buyerprodid NOT LIKE '$buyerprodid'"); ?>
Re: Simple SELECT * where id IS NOT EQUAL TO....???
Posted: Wed Feb 03, 2010 3:20 am
by simonmlewis
Sorry same error.
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /usr/local/psa/home/vhosts/domain.co.uk/httpdocs/beta/includes/myoffers.inc on line 48
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /usr/local/psa/home/vhosts/domain.co.uk/httpdocs/beta/includes/myoffers.inc on line 65
In the place.
Re: Simple SELECT * where id IS NOT EQUAL TO....???
Posted: Wed Feb 03, 2010 3:38 am
by Eran
The error has nothing to do with the comparison operator. Your original attempt was correct, you should be using != or <> which both indicate "not matching".
You should be checking the result of a mysql_query() before you pass it on to other functions -
Code: Select all
if($rejectoffer === false) {
echo mysql_error();
}
Also, echo out the query string just before you run mysql_query() on it and put it here (my guess is that one of the variables is not set)
Re: Simple SELECT * where id IS NOT EQUAL TO....???
Posted: Wed Feb 03, 2010 3:50 am
by simonmlewis
I am sorry but I don't understand - mainly about the little but of 'error' code you gave me.
This is the full code that is called upon if a variable has "accept" in it.
It basically tells the one successful person they have got something, and ALL OTHERS in the list that they were rejected.
It's the REJECTED part that's causing the errors.
Code: Select all
$offer = mysql_query ("SELECT * FROM offers WHERE id = '$offerid'");
while ($rowoffer = mysql_fetch_object($offer))
{
$result = mysql_query ("SELECT email, firstname, lastname FROM users WHERE id = '$rowoffer->buyerid'");
while ($row = mysql_fetch_object($result))
{
$to = "$row->email";
$subject = "domain Offer Accepted";
$headers = "From: noreply@domain.co.uk";
$body = "** This email account is not monitored - please do not reply. **
Dear $row->firstname $row->lastname
An offer you have made on domain has been accepted. Please login to see which item you are being emailed about, and take necessary steps to despatch your item for theirs.
Best regards
domain
http://www.domain.co.uk
";
mail ($to, $subject, $body, $headers);
}
mysql_free_result($result);
}
mysql_free_result($offer);
$rejectoffer = mysql_query ("SELECT * FROM offers WHERE sellerprodid = '$sellerprodid' AND buyerprodid <> '$buyerprodid'");
while ($rowoffer = mysql_fetch_object($rejectoffer))
{
$result2 = mysql_query ("SELECT email, firstname, lastname FROM users WHERE id == '$rowoffer->buyerid'");
while ($row2 = mysql_fetch_object($result2))
{
$to = "$row2->email";
$subject = "domain Offer Rejected";
$headers = "From: noreply@domain.co.uk";
$body = "** This email account is not monitored - please do not reply. **
Dear $row2->firstname $row2->lastname
We are sorry to inform you that an offer you have made on domain has been rejected. Please login to see which item you are being emailed about.
Best regards
domain
http://www.domain.co.uk
";
mail ($to, $subject, $body, $headers);
}
mysql_free_result($result2);
}
mysql_free_result($rejectoffer);
Re: Simple SELECT * where id IS NOT EQUAL TO....???
Posted: Wed Feb 03, 2010 4:09 am
by social_experiment
Code: Select all
<?php $result2 = mysql_query ("SELECT email, firstname, lastname FROM users WHERE id = '$rowoffer->buyerid'");
while ($row2 = mysql_fetch_object($result2)) ?>
Remove the '==' and make it only '=' in the $result2 query.
Re: Simple SELECT * where id IS NOT EQUAL TO....???
Posted: Wed Feb 03, 2010 4:23 am
by simonmlewis
Now that has surprised me.
I thought the code at the be "is equal to"...."==", because else you have to do <>, != etc....
Why does = work and == not work?
By the way - WORKS A TREAT.
Re: Simple SELECT * where id IS NOT EQUAL TO....???
Posted: Wed Feb 03, 2010 5:05 am
by social_experiment
Im not sure, maybe the '==' is not part of the SQL syntax.
http://dev.mysql.com/doc/refman/5.0/en/ ... ators.html