Page 1 of 1

DB query not working...

Posted: Wed Sep 07, 2011 5:48 pm
by someguyhere
Can anyone tell me what I'm doing wrong with this bit of code? I'm fairly sure that it's something to do with the 2nd line but I can't get it to work. If it makes a difference, this is conducted when a visitor clicks a link that's coded to conduct this specific search.

Thanks in advance!

Code: Select all

	if ($_GET['service_category'] == 'Services for Senior Related Businesses'){
		$search_results = $wpdb->get_results("SELECT * FROM wp_network_members WHERE wp_network_categories = 'Services for Senior Related Businesses' AND pub_status = 'publish'");

		echo '<h1>Search Results</h1>' . "\n";

		foreach ($search_results as $value) {

			if (empty($value->profile_photo)) {
				$value->profile_photo = "/wp-content/plugins/wp-members-network/images/no-photo.jpg";
			}
	
			echo '
			<div class="networksearchitem"><br />
			<a href="/' . $network_page . '/' . strtolower($value->f_name) . '-' . sanitize_title($value->l_name) . '/"><img src="' . $value->profile_photo . '" class="networksearchimage" /></a>
			<a href="/' . $network_page . '/' . strtolower($value->f_name) . '-' . sanitize_title($value->l_name) . '/"><img src="' . $value->logo . '" class="networksearchlogo" /></a>
			<h3><a href="/' . $network_page . '/' . strtolower($value->f_name) . '-' . sanitize_title($value->l_name) . '/">' . $value->f_name . ' ' . $value->l_name . ', ' . stripslashes($value->company_name) . '</a></h3>
			<hr class="floatfixer" />
			</div>';
		}
	}

Re: DB query not working...

Posted: Wed Sep 07, 2011 6:02 pm
by twinedev
Well what is happening compared to what you are expecting?

Are you getting errors?

Just getting no results?

What do you get when you manually run the query?

Re: DB query not working...

Posted: Wed Sep 07, 2011 6:13 pm
by someguyhere
I get no results...just a blank page. If you search using the form (drop down menu) it works fine.

If it helps, the link to conduct the search is this:
<a href="http://domain.com/network/search-our-ne ... y=Services for Senior Related Businesses">View Senior Business Resources</a>

Re: DB query not working...

Posted: Wed Sep 07, 2011 6:23 pm
by greip
If you get a blank page, without the h1-element, it means that the initial test

Code: Select all

$_GET['service_category'] == 'Services for Senior Related Businesses'
is false. You could try to insert a phpinfo() statement at the start of the script to verify that $_GET[] contain what you expect.

Re: DB query not working...

Posted: Wed Sep 07, 2011 6:36 pm
by someguyhere
The h1 shows up, but no results.

FYI - I used print_r to display the contents of $_GET when clicking on the link and it appears to have the info it needs to process the search.

If you could take a look here (http://lifelinesacademy.com/lifelines-network/) and see if you can tell what's wrong, I would appreciate it. I'm stumped. You can click the link "View Senior Business Resources" at the bottom of the page.

Re: DB query not working...

Posted: Wed Sep 07, 2011 7:09 pm
by greip
I am getting search results, so I guess you fixed the problem.

Re: DB query not working...

Posted: Wed Sep 07, 2011 7:15 pm
by someguyhere
greip wrote:I am getting search results, so I guess you fixed the problem.
You get results when you click the link which takes you to here: http://lifelinesacademy.com/lifelines-n ... Businesses ?

I know it works using the search form, but I can't get it to work using the link. Are you seeing something different than me?

Re: DB query not working...

Posted: Wed Sep 07, 2011 7:45 pm
by greip
I was using the search box.

Looking at your code, the SQL-statement does not depend on anything sent from the client. My guess is that there simply are no records matching the SQL select-statement. Try to run the query manually.

Re: DB query not working...

Posted: Mon Sep 12, 2011 6:38 pm
by someguyhere
If I do it manually through phpmyadmin I get the following error:

#1054 - Unknown column 'wp_network_categories' in 'where clause'

Which makes no sense because the column is there, and I can conduct the exact search using the form, just not the text link. Any ideas?