Skip Navigation

[Resolved] error in query

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 8 years ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 -
- - - - - - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 1 voice.

Last updated by kathyM 8 years ago.

Assisted by: Tia.

Author
Posts
#452874

I am trying to: write a query where I have added a new custom field to the wp_users table called u-status

I visited this URL:

I expected to see: something

Instead, I got: no results

<?php
/*
Template Name: Set User Inactive 01
*/
 	$current_user = wp_get_current_user();

    	if ( ( ! ($current_user instanceof WP_User) ) || ( ! current_user_can('administrator') ) )
	{
	      print ("<script language='JavaScript'>");
	      print (" window.parent.location='<em><u>hidden link</u></em>';");
	      print ("</script>");
	      exit();
	}
?>

<?php
    get_header(); 
?>

<?php
	$sql = "SELECT 
	A.ID,  A.user_login, A.user_nicename,
	A.user_email,  B.meta_value
	FROM wp_users A 
	INNER JOIN wp_usermeta B  ON A.ID = B.user_id
	WHERE B.meta_key = 'wpcf-u-status'";

	global $wpdb;
	$result = $wpdb->get_results ( $sql );

	if (!$result) 
	{
	   echo 'Could not run query: ' . mysql_error();
	   exit;
	}


?>


	<div id="main-content" class="main-content">
	
		<div id="primary" class="content-area">
			<div id="content" class="site-content" role="main">

			<br/><br/>
			<div align="center" style="font-family:Arial;font-weight:normal;font-size:30px;">Set Salespeople Inactive</div>

			<br/>
			<div align="center">

			<form name="Form1" id="Form1" action="<em><u>hidden link</u></em>" method="post" >
			<table width="700" align="center">
			<tr height="20">
				<td colspan=4 align=right>
				<a href="<em><u>hidden link</u></em>"><img src="<em><u>hidden link</u></em>" width="30" /></a>
				</td>
			</tr>

			<tr bgColor="gainsboro" height="40">
				<td>
				<span style="font-weight:bold;">User ID</span>
				</td>
				<td align="left">
				<span style="font-weight:bold;">Username</span>
				</td>
				<td align="left">
				<span style="font-weight:bold;">Email</span>
				</td>
				<td align="left">
				<span style="font-weight:bold;">User Status</span>
				</td>
			</tr>

			    </tr>

SOMETH8ING GOES HERE


			</table>


			<br/><br/>


			<br/><br/>



	</div>
	
	<br/><br/>
	<br/><br/>




<?php
	get_footer();
?>

#453160

Hi

I have updated my code as follows, but it still isn't working
I need to display in a table format only those users who
have the role of Salesperson.
I have tried everything and I can't seem to get this query
working at all.


<?php
/*
Template Name: Set User Inactive 01
*/
 	$current_user = wp_get_current_user();

    	if ( ( ! ($current_user instanceof WP_User) ) || ( ! current_user_can('administrator') ) )
	{
	      print ("<script language='JavaScript'>");
	      print (" window.parent.location='<em><u>hidden link</u></em>';");
	      print ("</script>");
	      exit();
	}
?>

<?php
    get_header(); 
?>

<?php

	// $blogusers = get_users( 'blog_id=1&orderby=nicename&role=Salesperson' );


	$sql =  "SELECT 
   	A.ID AS 'User ID',
    	A.display_name AS Name,
   	A.user_email AS Email,
	B.meta_value AS Status,
	C.meta_value AS Role,
	FROM wp_users A 
	INNER JOIN wp_usermeta B   ON A.ID = B.user_id
	INNER JOIN wp_usermeta C   ON A.ID = C.user_id
	WHERE B.meta_key 	= 'wpcf-u-status' 
	AND C.meta_key = 'salespeople' ";
 





	$result = mysql_query($sql);

	if (!$result) 
	{
	   echo 'Could not run query: ' . mysql_error();
	   exit;
	}
	else
	{
	   print ("there are results\n\n\n\n");
	}


$result = mysql_query($sql);
if (!$result) {
    die("Query to show fields from table failed");
}




$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";




$fields_num = mysql_num_fields($result);

echo "<h1>Table: {$table}</h1>";
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
    echo "<tr>";

    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell)
        echo "<td>$cell</td>";

    echo "</tr>\n";
}
mysql_free_result($result);



?>

#453180

Hi

Sorry for all the emails... I'm stuck for sure now

Here is my code... I don't know how to reference the newly created
field wpcf-u-status and how I would go about updating it as well



	$sql = "SELECT u.ID, u.display_name,  u.user_email
	FROM $wpdb->users u
	INNER JOIN $wpdb->usermeta m ON m.user_id = u.ID
	WHERE m.meta_key = 'wp_capabilities' AND m.meta_value LIKE '%salesperson%'

// need to check for value of this field:  wpcf-u-status - in the usermeta table


	ORDER BY u.user_registered";

	$result = mysql_query($sql);

	if (!$result) 
	{
	   echo 'Could not run query: ' . mysql_error();
	   exit;
	}


#453213

not really, but I am going to re-post

The forum ‘Types Community Support’ is closed to new topics and replies.