Jump to content

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


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.

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.