DB query not working...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

DB query not working...

Post 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>';
		}
	}
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: DB query not working...

Post 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?
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: DB query not working...

Post 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>
greip
Forum Commoner
Posts: 39
Joined: Tue Aug 23, 2011 8:23 am
Location: Oslo, Norway

Re: DB query not working...

Post 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.
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: DB query not working...

Post 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.
greip
Forum Commoner
Posts: 39
Joined: Tue Aug 23, 2011 8:23 am
Location: Oslo, Norway

Re: DB query not working...

Post by greip »

I am getting search results, so I guess you fixed the problem.
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: DB query not working...

Post 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?
greip
Forum Commoner
Posts: 39
Joined: Tue Aug 23, 2011 8:23 am
Location: Oslo, Norway

Re: DB query not working...

Post 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.
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: DB query not working...

Post 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?
Post Reply