Jump to content

Login using specific ID and then only display certain data


boothyuk123

Recommended Posts

In follow up to my previous post, I have found a way to display my data but now I am wanting to only display certain data (within an 'if' statement). For example, if I login as a particular student and there is three sets of data in there e.g. MATH1023, ENG1003 and ENG1013 but I only want to display the student's MATH1023 data in a section, how do I do this? I know that I need to do some sort of an IF statement where 'crsecode=MATH1023' but for some reason I cannot get this to work without it pulling this along with the two English courses.

 

Here is my code:

 

<?php 
$db_host = "locahost"; 
$db_user = "dbuser"; 
$db_pass = "dbpassword"; 
$db_name = "dbconnection"; 
$dbac = mysql_connect($db_host,$db_user,$db_pass); 
mysql_select_db ($db_name) or die ("Cannot connect to database."); 

if (!$_POST['search']){ 
?> 
<form name="Item Search" method="post" action=""> 
  Item Search:<br> 
  <label> 
  <input name="swords" type="text" size="30" maxlength="30"> 
  </label>  
  <br> 
  <label> 
  <input name="search" type="submit" id="search" value="Search"> 
  </label> 
</form> 
<?php 
}else{ 
$searchwords = addslashes(htmlspecialchars($_POST['swords'])); 
if (strlen($searchwords) < 2){ 
echo "Your search must contain at least 3 characters. Please try again.<br><input type=button value='Back' onClick='history.go(-1)'>"; 
}else{ 
$words = explode(' ',$searchwords); 
$totalwords = count($words); 
$i = 0; 
$searchstring = ""; 
while ($i != $totalwords){ 
if ($i != 0 and $i != $wordcount){ 
$searchstring .= " and ";; 
} 
$searchstring .= "cwid LIKE '%$words[$i]%'"; 
$i = $i + 1; 
} 
$query = mysql_query("SELECT DISTINCT * FROM transferdatafile where $searchstring"); 
if (mysql_num_rows($query) == 0){ 
echo "No results were found.<br><input type=button value='Back' onClick='history.go(-1)'>"; 
}else{ 
echo '<table border=1>'; 
while ($row = mysql_fetch_array($query)){ 
echo '<tr>'; 
  echo '<td>'.$row['firstname'].'</td>'; 
  echo '<td>'.$row['lastname'].'</td>'; 
  echo '<td>'.$row['subj'].'</td>'; 
  echo '<td>'.$row['course'].'</td>'; 
  echo '<td>'.$row['crsecode'].'</td>'; 
  echo '<td>'.$row['crsegrade'].'</td>'; 
  // etc 
  echo '</tr>'; 
   
}  
echo '</table>'; 
} 
} 
} 
?>

 

Here is the output that I currently get with this when all I want is MATH1023 to display for this particular student's ID (see attachment).

 

Anyone help?

 

 

 

[attachment deleted by admin]

The code you posted has some errors and will not exicute on my wamp.

Line 24 : }else{  throws an error. I don't think it belongs here because you have the same thing on line 28.

Next error I get is that the last } line 60 does not belong there.

 

And line 25 : $searchwords = addslashes(htmlspecialchars($_POST['swords']));

 

has the word swords as being passed to this code, but you are defining it in the form just above Line 15.

==============================================================================

 

As for your question you need a column (maybe a couple) in the user table that defines what you want to display for that user.

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.