WordPress.org

Ready to get started?Download WordPress

Forums

Trying to Count Number of rows of a custom field (3 posts)

  1. donsony
    Member
    Posted 2 years ago #

    I am using the code to do this. Instead of the variable in the sql string, if I use the actual value, its working. I mean instead of $country I use "USA" its working. But when I use the variable, its not while at the same time $country is outputting USA.

    Can someone help me???? Would greatly appreciate it

    [please mark any code using the code button - http://codex.wordpress.org/Forum_Welcome#Posting_Code ]

    global $wpdb;
    $countries = tgt_get_countries();
    foreach ($countries as $country) {
    $sqlquery="SELECT COUNT(*) FROM ($wpdb->postmeta WHERE meta_value = '".$country."' AND meta_key = 'tgt_job_country')";
    $testcount = $wpdb->get_var($sqlquery);
    echo "
    <li>".$country."(".$testcount.")";}
  2. donsony
    Member
    Posted 2 years ago #

    global $wpdb;
    $countries = tgt_get_countries();
    foreach ($countries as $country) {
    $sqlquery="SELECT COUNT(*) FROM ($wpdb->postmeta WHERE meta_value = '$country' AND meta_key = 'tgt_job_country')";
    $testcount = $wpdb->get_var($sqlquery);
    echo "
    <li>".$country."(".$testcount.")";}

    The above code also doesnt work

  3. donsony
    Member
    Posted 2 years ago #

    corrected it just the additional brackets was the problem....

    <?php
    		global $wpdb;
    		$countries = tgt_get_countries();
    		foreach ($countries as $country) {
    		$testcount = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_value = '$country' AND meta_key = 'tgt_job_country'");
    		if ($testcount !=0)
    		echo "<li>".$country."(".$testcount.")";}
    	?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.