i have been trying to construct a system that will match people up with each other (for v-day) based on their response on a survey that we will give them. i have an idea on how to do this, but i seem have gotten stuck at one of the early steps.
first my plan -
1. select one row and use the data from as a base of which comparisons will be made.
2. select from the rest of the table where the id!=id and sex!=sex. im ok up to here i think.
3. i will use if ($row->e1=$row2->e1) etc statements and if the statement is true, i want to insert a "1" into a new row of a temp database.
4. take that database and do a count() of all the 1s that i have
5. with the count, i want to insert that along with a name into another temp database where the info will be held until the entire database has been processed using the original row's information to compare it with the other rows.
6. finally i want to "SELECT FROM temp2 ORDER BY score DESC LIMIT 10" (or however this is supposed to be)
right now i just started on my code:
<?
include("conf.php");
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
mysql_select_db($db) or die ("Unable to select database!");
$query = "SELECT * FROM csf WHERE id='$id'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
if (mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_object($result))
{
$query = "SELECT * FROM csf WHERE sex!='$row->sex' AND id!='$row->id'";
$result2 = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
if (mysql_num_rows($result2) > 0)
{
while($row2 = mysql_fetch_object($result2))
{
if ($row->e1=$row2->e1)
{
?>
+1 <? echo $row2->id; ?> <br>
<?
}
else
{
echo '+0';
}
if ($row->e2=$row2->e2)
{
?>
+2<br>
<?
}
else
{
echo '+0';
}
}
}
else
{
?>
<?
}
}
}
else
{
?>
<font size="-1">Nothing</font>
<?
}
mysql_close($connection);
?>
my problem is that although it will select the proper rows to compare from (the "SELECT * FROM csf WHERE sex!='$row->sex' AND id!='$row->id'" query works just fine) my if statements do not seem to work, as i get a +2 even if the two items are not equal.
the results that i get from the above code are
the row that i am first selecting looks like:
id | name | sex | e1 | e2
4 cnbmncvn 2 1 1
and the two rows that the code selects and then processes look like
id | name | sex | e1 | e2
2 sfdgsf 1 2 2
3 sgdrw 1 2 1
does anybody have an idea of what i am doing wrong here?
also how would i go about putting the +1/+2 results into a new table? or is there a better way to go about this?
thanks a lot
GoSharks