Jump to content

Simple PHP Searching... plz take a look


Nazirul

Recommended Posts

;D

 

Hello

 

this is my code.. i can't use the if-else statement.. any idea?

 

$query = "SELECT * FROM $table WHERE student_number LIKE '".$_POST['txtSearch']."'";  
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result))
{
$Student_Number = $row['Student_Number'];
$Student_Name = $row['Student_Name'];
$Qualification = $row['Qualification'];
$Status = $row['Status'];

$kirim = $_POST['txtSearch'];

if ($kirim == $Student_Number)
{
	echo "You are success";
}
else 
       {
	echo("You are failed!!!");
}
}

 

i want to display a msg if the student success or not... is it the correct way for it?

 

thanks

Link to comment
Share on other sites

2 things:

 

1) Why can't you use if-else?

2) If you're going to use LIKE in your SQL statement, surround the value with %:

$query = "SELECT * FROM $table WHERE student_number LIKE '%".$_POST['txtSearch']."%'";  

 

If this is a school assignment and you can't use if-else, you're probably looking for the ternary operator: http://us.php.net/operators.comparison

 

Link to comment
Share on other sites

the code is actually working ...  ;D

 

it is just try-n-error code...

 

but the problem is... i want to display an error when the student number did not match in the table...

 

how thats gonna be... i've spend a few hours for that... (im newbie anyway, :) )

Link to comment
Share on other sites

   if ($kirim == $Student_Number)
   {
      echo "You are success";
   }
[b]   else
       {
      echo("You are failed!!!");
   }[/b]

 

i have a problem with the 'else' statement... when the student did not match like in the table, it display nothing... that is "      echo("You are failed!!!"); " did not works...  ???

 

 

Link to comment
Share on other sites

Well, it's got to display one of the two lol.

 

lol... its confusing me... it is either one must work...

 

i've tried ...

 

   if ($kirim != $Student_Number)
  {
     echo "You are failed!!!";
  }
  else
      {
     echo("You are success");
  }

 

it just does not output the correct echo when the student number was wrong... no luck... :(

 

Link to comment
Share on other sites

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.