Jump to content

Recommended Posts

$sql = "SELECT * FROM studproj WHERE Enrolement_Number = students.'$username'";
$results = mysql_query($sql);

//echo $results;

//echo $sql;

if(mysql_num_rows($result) == 0) 
{ 
echo "You already have a project chosen you cannot choose another but you can see your selection on the main page!"; 
exit;
} 
else 
{ 
echo " Please continue and choose your Project";
} 

?>

 

this is the code however i dont know what to put where ==0 is so that it says if there is a row that matches then choose an error message any help ?

Link to comment
https://forums.phpfreaks.com/topic/259770-difficluty-with-a-if-statement/
Share on other sites

ive changed it a little bit

 

$sql = "SELECT * FROM studproj WHERE Enrolement_Number ='$username'";
$result = mysql_query($sql);

//echo $result;

//echo $sql;

if(!$result) {
  // problem with query
echo "query is wrong";
}
elseif (mysql_num_rows($result)) {
echo " Please continue and choose your Project";
}
else 
{
  echo "You already have a project chosen you cannot choose another but you can see your selection on the main page!";

}
?>

 

but it always still just returns as if the query  is true

ive done these however it always shows the result as if the user has a entry in the databse when ive emptied the database so it should be telling them to choose a project

 

 

?php 

$username = $_SESSION['valid_user'];

ECHO $username;



$sql = "SELECT * FROM studproj WHERE Enrolement_Number ='$username'";
$result = mysql_query($sql);

//echo $result;

//echo $sql;

if(!$result) {
  // problem with query
echo "query is wrong";
}
elseif (mysql_num_rows($result)>= 1) {
echo " Please continue and choose your Project";
}
else 
{
  echo "You already have a project chosen you cannot choose another but you can see your selection on the main page!";

}
?>

When you change your condition, you also changed your echo's so they no longer match up with what you checking.  You need to make sure what you put inside your if statement's code body matches what you want to do under that condition.

 

if (mysql_num_rows($results) >= 1){
  echo 'You already have a project';
}
else {
  echo 'You must choose a project.';
}

 

Aww ive found the problem im asking it to match the enrolement number with the users username when it needs to

 

look into the s6tudents table and match the username with the enrolement number that has that username

 

would that be a join statement ? ive never had to do this before so im really not sure

im getting rrally confused by the joining document

woudl i be able to take a shortcut and do something like :

 

$sql1 = "Select Enrolement_Number FROM students WHERE First_Name ='$username'"; 
$result1 = mysql_query($sql1) or die(mysql_error());
echo $result1;
$sql = ("SELECT * FROM studproj WHERE Enrolement_Number  = '$result1'") or die (mysql_error());
$result = mysql_query($sql) or die(mysql_error());

echo mysql_num_rows($result); 

ive had one try of it

 

so what im tryign to say is select all from the studprojc table if the enrolement number matches a field with the username init  from the students table

$sql1 = ("Select * FROM studproj INNER JOIN students ON students.First_Name = Students.'$username'"); 

i finally got the join statment to work wether its the best way to do it im not sure but it works not im havign difficulties taking the filed names and storing them into attributes to disply information from them:

 

$sql = ("Select project.Module_Code,project.Title,project.First_Supervisor,project.Level,project.Description,studproj.Module_Code FROM studproj INNER JOIN project ON  studproj.Module_Code=project.Module_Code "); 
$result = mysql_query($sql) or die(mysql_error());

 

f (mysql_num_rows($result1)==1)
{
echo 'You already have a project';

while ($row = mysql_fetch_row($result)) 
{
$enrolementnumber = $row['Enrolement_Number'];
$Modulecode = $row['Module_Code'];
$Title = $row['Title'];               
$First_Supervisor = $row['First_Supervisor'];                
$Level = $row['Level'];
$Description = $row['Description'];
echo '<table border = "2">

<tr>
<td>Module Code </td><td><input readonly type= "text" name="Module_Code1"></td>
<td>Title </td><td><input readonly type= "text" name="Title1" ></td>
<td>First Supervisor </td><td><input readonly type= "text" name="First_Supervisor1" ></td>
<td>Level </td><td><input readonly type= "text" name="Level1" ></td></tr>
</table>
<table>
<tr>
<td>Description </td><td><input readonly type= "text" size = 200 name="Description1"></td>
</tr>



</table>';

}
}
else {
  echo 'You must choose a project.';


}
?>

 

it wont display the table and i cannot see why it is late so that may be the reason but anyhelp is appricated

 

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.