Jump to content

Need help with a querying a partial column...


Jim R

Recommended Posts

Here is where I'm starting:

 


SELECT * FROM wp_usermeta WHERE meta_key = 'wp_1_s2member_custom_fields' AND meta_value LIKE '%3%'

 

As the PHP produces the page, I'm going to have 15 different options coming from the

meta_value LIKE

  part.  I'm assuming I can set up my 15 different DIVs, each with their own IF  statement involving the meta_value. 

 

Right?  I'm not going to have to have 15 different queries, am I?

 

 

I assume it would start like this:

$query = 'SELECT * FROM wp_usermeta WHERE meta_key = "wp_1_s2member_custom_fields"';
$results = mysql_query($query);
while($line = mysql_fetch_assoc($results)) 

 

But from there, I don't know if it's possible to deal with partial data with IF statements.

 

 

Link to comment
Share on other sites

Yes your one query should be fine.  You can make an "if" using $line['meta_value'] inside the loop.  If you want the results in a particular order you can use an "ORDER BY" clause in your SQL query.

 

I haven't read what Muddy linked yet, but it might answer this question.  Does the *if*....$line['meta_value'] work if I'm just trying to get part of the data in that field? 

 

Here is the raw data:

 

a:1:{s:6:"county";s:1:"4";}

 

From that, I'm going to look for "county" and then figure out if the "#" at the end is 1,2,3,4, or 5.

 

 

Link to comment
Share on other sites

Ok...I'm trying to get it to count the number of relevant items, display the User ID's then show the total number that match.

 

$query = 'SELECT * FROM wp_usermeta WHERE meta_key = "wp_1_s2member_custom_fields"';
$results = mysql_query($query);
while($line = mysql_fetch_assoc($results)) {


$meta_value = unserialize($line['meta_value']);
if ($meta_value['county'] == '1' || $meta_value['county'] == '2') {
	$count1=0;

	foreach ($line as $user) {
	$count1=$count1+1;
	echo $user['user_id'] . '<br> ';
	}

echo $count1;
}
}

 

That code produced:  1 4 w a 41 4 w a 4

 

:)

 

It should show:

 

439

440

2

Link to comment
Share on other sites

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.