Jump to content

Cant manipulate my last database column within php!...pliiiiiz help


joaca

Recommended Posts

Hello fellow coders.

I have a problem that has haunted me for so long. I am using php $ mysql to come up with a student selection system. I have managed to retrieve my data from the database using php. However, when I try to include data from my last column into an IF statement, it doesnt work. Here is a sample of my code. please help.

 

<code>

if($_POST['sub'])

{

require("../scripts/opendb.php");

 

$result = mysql_query("select * from schools");

$num_result = mysql_num_rows($result);

 

for($i=0; $i<$num_result; $i++)

{

$row = mysql_fetch_array($result);

require("../scripts/create_table.php");

 

$resultThree = mysql_query("select * from students where firstchoice='".$row["regno"]."' or secondchoice='".$row["regno"]."' or thirdchoice='".$row["regno"]."' or fourthchoice='".$row["regno"]."'");

$num_resultThree = mysql_num_rows($resultThree);

 

for($j=0; $j<$num_resultThree; $j++)

{

  $rowThree = mysql_fetch_array($resultThree);

if($row["regno"] == $row["firstchoice"])

{

  $weight = 1;

  }

  if($row["regno"] == $row["secondchoice"])

  {

$weight = 2;

}

elseif($row["regno"] == $row["thirdchoice"])

{

$weight = 3;  

  }

elseif($row["regno"] == $row["fourthchoice"])

{  

  $weight = 4;

  }

 

$resultFour = mysql_query("insert into '".$row["regno"]."' values '".$rowThree["name"]."','".$rowThree["points"]."','".$weight."'");

 

 

}

}

exit();

}

</code>

 

My problem is in the if..else statements. My code does not consider the last if...else statement

So what does happen if $row["regno"] doesn't equal $row["firstchoice"], and $row["regno"] doesn't equal $row["secondchoice"], and $row["regno"] doesn't equal $row["thirdchoice"] ?

 

Syntactically, if the conditions said above are met there's no reason why the last 'if' statement wouldn't be run. The problem must lye within your own logic - or data.

 

Try adding some debug like (just after: $rowThree = mysql_fetch_array($resultThree);):

 

print $row['regno'] . '<br />'; print_r($rowThree);

 

To see what values are being passed through the 'if' statements..

 

Adam

Sorry MrAdam, I must have made a mistake while copying the code to the forum. The if statements compare columns from two different tables. $row["regno"] is a column from a table that has schools and their registration numbers. $rowThree["firstchoice"] is a column from another table that has students and the choices of schools they wish to attend. My attempts to debug are not yielding anything positive.

Archived

This topic is now archived and is closed to further replies.

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