Jump to content


Not displaying function after searching MySql


  • You cannot reply to this topic
No replies to this topic

#1 Korndawg

    Young Padawan

  • Members
  • Pip
  • 111 posts
  • Gender:Male
  • Location:Texas, USA

Posted 20 December 2007 - 07:28 PM

Hi P2L! Of course I am having another problem. First of all this is horrible coding, I took one of my friends script and am currently trying to make it smaller (get rid of repeated code). So please if you can help me with the code also that would be great.

Ok now to the main problem I am having. I call the class twice, once for when the search isn't called, and once when the search isn't called. It displays great when the search isn't called, however when the search is called it doesn't display anything. By the way, there are not any mysql errors. (I have nothing in the database right now, but it should display the error corresponding to that)

Here is the code that calls the function:
$option = $_POST["option"];
$search = $_POST["search"];

if(isset($_POST['submit'])){ 
  if ($search == ""){
	echo "
	  <tr>
		<td colspan=\"7\" align=\"center\">
		  You did not enter anything to search for.
		</td>
	  </tr>";
  }else
	showAdmins($search, $option);
}else
  $blank = '';
  showAdmins($blank, $blank);

And here is the code for the function:
function showAdmins($search, $option)
{
	//Search for an admin
?>
		<form method="Post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
		<tr>
			<td colspan="7" align="right">
				<select name="option">
					<option value="user">Username</option>
					<option value="lname">Last Name</option>
					<option value="fname">First Name</option>
				</select>
				<input type="text" name="search" value="<?php echo $search; ?>">
				<input type="submit" value="Search">
			</td>
		</tr>
		</form>
		<tr>
			<td align="center" width="5%">
				Id
			</td>
			<td align="center" width="15%">
				Name
			</td>
			<td align="center" width="15%">
				Username
			</td>
			<td align="center" width="20%">
				E-mail
			</td>
			<td align="center" width="15%">
				Date Registered
			</td>
			<td align="center" width="15%">
				Last Login
			</td>
			<td align="center" width="7%">
				Admin Level
			</td>
		</tr>

<?php
	if ($search != NULL){
		$query = mysql_query("SELECT * FROM `pc_admin` WHERE $option LIKE '%{$_POST['search']}%'") or die(mysql_error());
		$adminnum = mysql_num_rows($query);
	
		if($adminnum <= 0)
			echo "
			<tr>
				<td colspan=\"7\" align=\"center\" class=\"redText\">
					Sorry - No admins were found matching your search criteria. Please try some different search terms.
				</td>
			</tr>
		";
		$show = 0;
	}else{
		$query = mysql_query("SELECT * FROM `pc_admin`") or die(mysql_error());
		$adminnum = mysql_num_rows($query);
		$adminnum = number_format($adminnum);
	
		if($adminnum == '0' || empty($adminnum))
			echo "
			<tr>
				<td colspan=\"7\" align=\"center\" class=\"redText\">
					There are currently no admins
				</td>
			</tr>
		";
		$show = 0;
	}
	
	if($show != 0){
		while($r=mysql_fetch_array($query)){
			echo "
			<tr>
				<td align=\"center\">
					$r[id]
				</td>
				<td align=\"center\">
					$r[user]
				</td>
				<td align=\"center\">
					$r[email]
				</td>
				<td align=\"center\">
					$r[date]
				</td>
				<td align=\"center\">";
				if ($r[last_login] == NULL || $r[last_login] == 0)
					echo "Never";
				else
					echo "$r[last_login]";
			echo "
				</td>
				<td align=\"center\">
					$r[fname] $r[lname]
				</td>
				<td align=\"center\">
					$r[admin]
				</td>
			</tr>";
		}
	}

Bump

Edited by rc69, 21 December 2007 - 09:10 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users