Jump to content

code not working properly


swapnali_s230

Recommended Posts

Hi All

I have been working on one program.. Its giving me output for some echo, not for other echos. I dont know why? Following is the code -

 

 

if (is_array(@$_REQUEST['classes']))

{

foreach($_REQUEST['classes'] as $course1) {

$sql=mysql_query("SELECT Ma_CoName FROM MCourse where Ma_CoNo='$course1'");

@$course=mysql_result($sql, 0) or die('wrong query'.mysql_error());

 

if ($course=='ENGL 1301') echo $course;

elseif ($course=='ABC 33') echo $course;

elseif ($course=="VVV 34") echo $course;

elseif ($course=="CCC 95") echo $course;

elseif ($course=="MMM 12") echo $course;

elseif ($course=="OOO 89") echo $course;

elseif ($course=="CCC 75") echo $course;

}}

Code in bold is not giving me any output, but $course=='ENGL 1301' is giving me output. I dont know why? It is so weird.....

Link to comment
https://forums.phpfreaks.com/topic/259373-code-not-working-properly/
Share on other sites

get rid of the @ symbol at the start of this line:

@$course=mysql_result($sql, 0) or die('wrong query'.mysql_error()); 

you are only pulling a single result into $cource from your mysql_query() result set that is returned from the database.  You need to use a loop to itterate through the resultset array ($sql in this case) and allow you access to each row, not just the first one.

  • 2 weeks later...

Thank you very much for reply.... The problem got solved...I used trim function. :)

I have another problem here. My mysql query is not working ..I don't know why? Here is that line -

$query =mysql_query("SELECT Course_ID FROM Course where Student_ID='$Stud_ID' AND Course_Name='COSC 3312' AND Course_Name='COSC 2430'");

 

 

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.