Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

[HELP] How to fetch list of users with my code

omnistrife42

Novice
Advanced Member
Messages
21
Reaction score
0
Points
26
Hi, hihingi lang po ng tulong...





Originally may
"
$stmt = $db_con->prepare("SELECT * FROM tbl_users ORDER BY userID DESC");
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))

"

working yan pag ganyan sa dating template...

pero since nag bootstrap na ako m


Fatal error: Call to a member function prepare() on a non-object in /home/crosswayprinting/public_html/ztest2/functions/admn/admn_account.php on line 39




Code:
</head>

<body>
    


	<div class="container">
      
        <h2 class="form-signin-heading">Account Management</h2><hr />
        <button class="btn btn-info" type="button" id="btn-add"> <span class="glyphicon glyphicon-pencil"></span>   Add User</button>
        <button class="btn btn-info" type="button" id="btn-view"> <span class="glyphicon glyphicon-eye-open"></span>   View User</button>
        <hr />
        
        <div class="content-loader">
        
        <table cellspacing="0" width="100%" id="example" class="table table-striped table-hover table-responsive">
        <thead>
        <tr>
        <th>User ID</th> 		<!-- 1 -->
        <th>Username</th> 		<!-- 2 -->
		<th>Password</th>		<!-- 3 -->
        <th>First Name</th> 	<!-- 4 -->
		<th>Last Name</th> 	<!-- 4 -->
		<th>Middle Name</th> 	<!-- 4 -->
		<th>Email</th> 	<!-- 4 -->
		<th>Address</th> 	<!-- 4 -->
		<th>Secret Question</th> 	<!-- 4 -->
		<th>Secret Answer</th> 	<!-- 4 -->
		<th>LoA</th> 	<!-- 4 -->
        <th>edit</th>
        <th>delete</th>
        </tr>
        </thead>
        <tbody>
        <?php

        
     
		{
			?>
			<tr>
			<td><?php echo $row['userID']; ?></td> 			<!-- 1 -->
			<td><?php echo $row['userName']; ?></td>		<!-- 2 -->
			<td><?php echo $row['userPass']; ?></td>		<!-- 3 -->	
			<td><?php echo $row['userfirstName']; ?></td>	<!-- 4 -->
			<td><?php echo $row['userlastName']; ?></td>	<!-- 4 -->
			<td><?php echo $row['usermiddleName']; ?></td>	<!-- 4 -->
			<td><?php echo $row['userEmail']; ?></td>		<!-- 5 -->
			<td><?php echo $row['userAddress']; ?></td>		<!-- 5 -->
			<td><?php echo $row['userSecretQuestion']; ?></td>		<!-- 5 -->
			<td><?php echo $row['userSecretAnswer']; ?></td>		<!-- 5 -->
			<td><?php echo $row['userLOA']; ?></td>		<!-- 5 -->
			
			<td align="center">
			<a id="<?php echo $row['userID']; ?>" class="edit-link" href="#" title="Edit">
			<img src="edit.png" width="20px" />
            </a></td>
			<td align="center"><a id="<?php echo $row['userID']; ?>" class="delete-link" href="#" title="Delete">
			<img src="delete.png" width="20px" />
            </a></td>
			</tr>
			<?php
		}
		?>
        </tbody>
        </table>
        
        </div>

    </div>
    
    <br />
    
    <div class="container">
      
        <div class="alert alert-info">
        <a href="http://localhost/tags/home.php" target="_blank">Crossway Printing</a>
        </div>

    </div>
    


</body>
</html>

^^^^^^^^^^
This code above works naman pero... kung anu nakalogin ngaun [ pag ako naka login mismo un lng makikita ko sa list...]
gusto ko sana makita lahat ng users na naka reg sa database ko...
ano pa bang ibang paraan para mafetch ang users ??
 
May error ka. Tama ang SELECT query mo, kaso parang yung PREPARE na ginamit mo ay di pwede para sa SELECT.. Try mo yung QUERY instead of PREPARE..
Try mo to:

Code:
$stmt = $db_con->[b]query[/b]("SELECT * FROM tbl_users ORDER BY userID DESC");
//$stmt->execute(); -- WALA na ito
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
 
try mo to sir

Code:
$stmt = $db_con->prepare("SELECT * FROM tbl_users ORDER BY userID DESC");
$stmt->execute();
$result = $stmt->fetchALL(PDO::FETCH_ASSOC);

foreach($result as $row)
{

}
 
mga di po gumagana ung code sirs

wait ito po ung codes ko kung sakali


admn_account.php
Code:
        <?php

        $stmt ="SELECT * FROM tbl_users ORDER BY userID DESC";
        $stmt->execute();
		while($row=$stmt->fetch(PDO::FETCH_ASSOC))
		{
			?>
</head>

<body>
    


	<div class="container">
      
        <h2 class="form-signin-heading">Account Management</h2><hr />
        <button class="btn btn-info" type="button" id="btn-add"> <span class="glyphicon glyphicon-pencil"></span>   Add User</button>
        <button class="btn btn-info" type="button" id="btn-view"> <span class="glyphicon glyphicon-eye-open"></span>   View User</button>
        <hr />
        
        <div class="content-loader">
        
        <table cellspacing="0" width="100%" id="example" >
        <thead>
        <tr>
        <th>User ID</th> 		<!-- 1 -->
        <th>Username</th> 		<!-- 2 -->
        <th>First Name</th> 	<!-- 4 -->
		<th>Last Name</th> 	<!-- 4 -->
		<th>Middle Name</th> 	<!-- 4 -->
		<th>Email</th> 	<!-- 4 -->
		<th>Address</th> 	<!-- 4 -->
		<th>Secret Question</th> 	<!-- 4 -->
		<th>Secret Answer</th> 	<!-- 4 -->
		<th>LoA</th> 	<!-- 4 -->
        <th>edit</th>
        <th>delete</th>
        </tr>
        </thead>
        <tbody>
       

        
		


		
			
			<tr> 
			<td><?php echo $row['userID']; ?></td> 			<!-- 1 -->
			<td><?php echo $row['userName']; ?></td>		<!-- 2 -->
			<td><?php echo $row['userfirstName']; ?></td>	<!-- 4 -->
			<td><?php echo $row['userlastName']; ?></td>	<!-- 4 -->
			<td><?php echo $row['usermiddleName']; ?></td>	<!-- 4 -->
			<td><?php echo $row['userEmail']; ?></td>		<!-- 5 -->
			<td><?php echo $row['userAddress']; ?></td>		<!-- 5 -->
			<td><?php echo $row['userSecretQuestion']; ?></td>		<!-- 5 -->
			<td><?php echo $row['userSecretAnswer']; ?></td>		<!-- 5 -->
			<td><?php echo $row['userLOA']; ?></td>		<!-- 5 -->
			
			<td align="center">
			<a id="<?php echo $row['userID']; ?>" class="edit-link" href="#" title="Edit">
			<img src="edit.png" width="20px" />
            </a></td>
			<td align="center"><a id="<?php echo $row['userID']; ?>" class="delete-link" href="#" title="Delete">
			<img src="delete.png" width="20px" />
            </a></td>
			</tr>
		<?php   } ?>
        </tbody>
        </table>
        
        </div>

    </div>
    
    <br />
    
    <div class="container">
      
        <div class="alert alert-info">
        <a href="http://localhost/tags/home.php" target="_blank">Crossway Printing</a>
        </div>

    </div>
    


</body>
</html>





class.user.php
Code:
<?php

require_once 'dbconfig.php';

class USER
{	

	private $conn;
	
	public function __construct()
	{
		$database = new Database();
		$db = $database->dbConnection();
		$this->conn = $db;
    }
	
	public function runQuery($sql)
	{
		$stmt = $this->conn->prepare($sql);
		return $stmt;
	}
	
	public function lasdID()
	{
		$stmt = $this->conn->lastInsertId();
		return $stmt;
	}
 
public function register($uname,$email,$upass,$code,$ufname,$ulname,$umname,$uaddress,$usquestion,$usanswer,$ubirthdate)
{
	try
	{       
	$password = md5($upass);
	$stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode,userfirstName,userlastName,usermiddleName,userAddress,usersecretQuestion,usersecretAnswer,userbirthDate) 
												VALUES(:user_name, :user_mail, :user_pass, :active_code, :user_fname, :user_lname, :user_mname, :user_address, :user_secretquestion, :user_answer, :user_birthdate)");										

	$stmt->bindparam(":user_name",$uname);
	$stmt->bindparam(":user_mail",$email);
	$stmt->bindparam(":user_pass",$password);
	$stmt->bindparam(":active_code",$code);
	$stmt->bindparam(":user_fname",$ufname);
	$stmt->bindparam(":user_lname",$ulname);
	$stmt->bindparam(":user_mname",$umname);
	$stmt->bindparam(":user_address",$uaddress);
	$stmt->bindparam(":user_secretquestion",$usquestion);
	$stmt->bindparam(":user_answer",$usanswer);
	$stmt->bindparam(":user_birthdate",$ubirthdate);
	$stmt->execute(); 
	return $stmt;
	}
	catch(PDOException $ex)
	{
		echo $ex->getMessage();
	}
}

public function newsInsert($authorUserNum,$content,$newsCtg,$title)
{
	try
	{       
		$stmt = $this->conn->prepare("INSERT INTO tbl_news(authorUserNum,content,newsCtg,title) 
													VALUES(:author_UserNum, :topic_content, :news_Ctg, :topic_title)");										

		$stmt->bindparam(":author_UserNum",$authorUserNum);
		$stmt->bindparam(":topic_content",$content);
		$stmt->bindparam(":news_Ctg",$newsCtg);
		$stmt->bindparam(":topic_title",$title);
		$stmt->execute(); 
		return $stmt;
	}
	catch(PDOException $ex)
	{
		echo $ex->getMessage();
	}
}
public function newsUpdate($usernum,$title,$ctg,$content,$id)
{
	try
	{       
		$stmt = $this->conn->prepare("UPDATE tbl_news SET content=:topic_content,newsCtg=:news_Ctg,title=:topic_title WHERE id=:id");										

		$stmt->bindparam(":id",$id);
		$stmt->bindparam(":topic_content",$content);
		$stmt->bindparam(":news_Ctg",$newsCtg);
		$stmt->bindparam(":topic_title",$title);
		$stmt->execute(); 
		return $stmt;
	}
	catch(PDOException $ex)
	{
		echo $ex->getMessage();
	}
}
public function getNewsList()
{
		$stmt = $this->conn->prepare("SELECT * from tbl_news ORDER BY newsDate DESC");
		$stmt->execute();
		return $stmt;
}

public function getNewsDetail($id)
{
		$id = (int)$id;
		$stmt = $this->conn->prepare("SELECT * from tbl_news WHERE id=:id");
		$stmt->bindparam(":id",$id);
		$stmt->execute();
		return $stmt;
}
public function getAuthor($id)
{
		$id = (int)$id;
		$stmt = $this->conn->prepare("SELECT userfirstName from tbl_users WHERE userID=:id ");
		$stmt->bindparam(":id",$id);
		$stmt->execute();
		foreach($stmt as $author){
						return $author->userfirstName;
					}
		//return $stmt;
}
public function doDeleteNews($id)
{
		$id = (int)$id;
		$stmt = $this->conn->prepare("DELETE from tbl_news WHERE id=:id");
		$stmt->bindparam(":id",$id);
		$stmt->execute();
		return $stmt;
}
public function itemInsert($usersession,$itemquantity,$itemcategory,$itemname,$ishidden,$itemprice)
{
	

	try
	{       
		$stmt = $this->conn->prepare("INSERT INTO tbl_product(ItemName,ItemCategory,ItemQuantity,IsHidden,ItemPrice) 
													VALUES(:itemname, :itemcategory, :itemquantity, :ishidden, :itemprice)");										

		$stmt->bindparam(":itemname",$itemname);
		$stmt->bindparam(":itemcategory",$itemcategory);
		$stmt->bindparam(":itemquantity",$itemquantity);
		$stmt->bindparam(":ishidden",$ishidden);
		$stmt->bindparam(":itemprice",$itemprice); 
		$stmt->execute(); 
		return $stmt;
	}
	catch(PDOException $ex)
	{
		echo $ex->getMessage();
	}
}

public function getItemList()
{
		$stmt = $this->conn->prepare("SELECT * from tbl_product ORDER BY ItemID DESC");
		$stmt->execute();
		return $stmt;
}
public function itemUpdate($usersession,$itemquantity,$itemcategory,$itemname,$ishidden,$itemprice)//transform to item again, wait may asikasuhin ako saglit sa database, nagcrash e okss
{
	try
	{       
		$stmt = $this->conn->prepare("UPDATE tbl_product SET ItemName=:item_name,ItemCategory=:Item_Category,ItemQuantity=:item_quantity WHERE ItemID=:id");										

		$stmt->bindparam(":itemname",$itemname);
		$stmt->bindparam(":itemcategory",$itemcategory);
		$stmt->bindparam(":itemquantity",$itemquantity);
		$stmt->bindparam(":ishidden",$ishidden);
		$stmt->bindparam(":itemprice",$itemprice); 
		$stmt->execute(); 
		return $stmt;
	}
	catch(PDOException $ex)
	{
		echo $ex->getMessage();
	}
}

public function getItemDetail($id)
{
		$id = (int)$id;
		$stmt = $this->conn->prepare("SELECT * from tbl_product WHERE ItemID=:id");
		$stmt->bindparam(":id",$id);
		$stmt->execute();
		return $stmt;
}
public function doDeleteItem($id)
{
		$id = (int)$id;
		$stmt = $this->conn->prepare("DELETE from tbl_product WHERE ItemID=:id");
		$stmt->bindparam(":id",$id);
		$stmt->execute();
		return $stmt;
}
public function login($email,$upass)
{
	try
	{
		$stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id");
		$stmt->execute(array(":email_id"=>$email));
		$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
		
		if($stmt->rowCount() == 1)
		{
			if($userRow['userStatus']=="Y")
			{
				if($userRow['userPass']==md5($upass))
				{
					$_SESSION['userSession'] = $userRow['userID'];
					$_SESSION['usertype'] = $userRow['usertype'];
					$result = array (
						'status' => 1,
						'msg' => 'Login Success'
					);
					return $result;
				}
				else
				{
					$result = array (
						'status' => 0,
						'msg' => 'Password Incorrect'
					);
					return $result;
				}
			}
			else
			{
				$result = array (
						'status' => 0,
						'msg' => 'Account Inactive'
					);
					return $result;
			}	
		}
		else
		{
			$result = array (
						'status' => 0,
						'msg' => 'Account Not Found'
					);
					return $result;
		}		
	}
	catch(PDOException $ex)
	{
		echo $ex->getMessage();
	}
}
	
	
	public function is_logged_in()
	{
		if(isset($_SESSION['userSession']))
		{
			return true;
		}
	}
	
	public function is_admin()
	{
		if(isset($_SESSION['usertype']))
		{
			if($_SESSION['usertype']==1)return true;
			else return false;
		}
	}
	
	
	public function is_auditor()
	{
		if(isset($_SESSION['usertype']))
		{
			if($_SESSION['usertype']==2)return true;
			else return false;
		}
	}
	
		public function is_member()
	{
		if(isset($_SESSION['usertype']))
		{
			if($_SESSION['usertype']==0)return true;
			else return false;
		}
	}
	
	
	public function getUserList()
{
		$stmt = $this->conn->prepare("SELECT * from tbl_users ORDER BY userID DESC");
		$stmt->execute();
		return $stmt;
}
	
	
	
	
	
	public function redirect($url)
	{
		header("Location: $url");
	}
	
	public function logout()
	{
		session_destroy();
		$_SESSION['userSession'] = false;
	}
	
 function send_mail($email,$message,$subject)
 {      

	$headers = "From: [email protected]\r\n";
	$headers .= "Reply-To: [email protected]\r\n";
	$headers .= "Return-Path: [email protected]\r\n";
	$headers .= "MIME-Version: 1.0\r\n";
	$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
	mail($email,$subject,$message,$headers);
 
  /*require_once('mailer/class.phpmailer.php');
  $mail = new PHPMailer();
  $mail->IsSMTP(); 
  $mail->SMTPDebug  = 0;                     
  $mail->SMTPAuth   = true;                  
  $mail->SMTPSecure = "ssl";                 
  $mail->Host       = "smtp.gmail.com";      
  $mail->Port       = 465;             
  $mail->AddAddress($email);
  $mail->Username="[email protected]";  
  $mail->Password="a1500m500";            
  $mail->SetFrom('[email protected]','Crossway Printing');
  $mail->AddReplyTo("[email protected]","Crossway Printing");
  $mail->Subject    = $subject;
  $mail->MsgHTML($message);
  $mail->Send();*/
 } 
}



may nakikita po ba kaung kulang kay admn_account.php ?? >_<
 
in view for each($model as $models) {
$models->username
bla bla bla etch..
echo instance/instance::query
return->this (render[view at
$models]);
 
Back
Top Bottom