Author Topic: trying to cut down this code a bit and it's locking up my server  (Read 482 times)

0 Members and 1 Guest are viewing this topic.

Offline spdwrenchTopic starter

  • Enthusiast
  • Posts: 94
  • Gender: Male
    • View Profile
    • Abmatch.com
trying to cut down this code a bit and it's locking up my server
« on: September 05, 2007, 12:58:59 PM »
ok I have a bit of code that pulls members thumbnails from the database.

but the original code had alot more information being pulled ... All I need is the filename_1 pulled with the gender and the id

Code: [Select]
$search_query = "SELECT p.id, p.gender, p.name, p.general_info, m.age, f.filename_1 FROM (dt_profile p, dt_photos f, dt_members m, dt_privacy pr) WHERE (p.status='1' AND (pr.featured_yn IS NULL OR pr.featured_yn='') AND pr.member_id=m.id AND p.member_id=m.id AND f.member_id=m.id AND f.filename_1<>'' AND p.gender='$genders[name]') ";

//$search_query = "SELECT p.id, p.gender, f.filename_1 FROM (dt_profile p, dt_photos f) WHERE (p.status='1' AND f.filename_1<>'' AND p.gender='$genders[name]') ";


the second part that is commented out is what I tried to do to cut back the strain on the server but when I run the line that is commented out it seems to be stuck and I get no results.

is there a problem with the syntax in the second part that I have commented out in this code?

thanks for any help

Paul

Offline sdi126

  • Enthusiast
  • Posts: 52
    • View Profile
Re: trying to cut down this code a bit and it's locking up my server
« Reply #1 on: September 05, 2007, 01:11:32 PM »
have you tried to run that second query inside the database itself to see if it returns any rows?

paste that sql statement in your query browser and let it run....it might be returning a bunch of records...which could be what appears to be "hanging"


Offline spdwrenchTopic starter

  • Enthusiast
  • Posts: 94
  • Gender: Male
    • View Profile
    • Abmatch.com
Re: trying to cut down this code a bit and it's locking up my server
« Reply #2 on: September 05, 2007, 01:27:07 PM »
well here is the code that is added to the end of that last bit

Code: [Select]
$search_query .= "ORDER BY RAND()";
        $search_query .= " LIMIT 1";

shouldnt this force it to return only one result???

Is my sytanx in the original post ok?

Paul

Offline recklessgeneral

  • Enthusiast
  • Posts: 67
  • Gender: Male
    • View Profile
    • The Reckless General
Re: trying to cut down this code a bit and it's locking up my server
« Reply #3 on: September 05, 2007, 02:32:20 PM »
Just thought I'd chip in with another idea to explore - wondered whether the "p.member_id=m.id AND f.member_id=m.id" condition had anything to do with it. It seems to be the link between the two tables, although that would also mean having to include the members table in your query.

What I imagine would be happening is the database is attempting to return all combinations of <profile, photo> pairs without restricting the set to only those that make sense (i.e. represent member data). Try the following query:

Code: [Select]
$search_query = "SELECT p.id, p.gender, f.filename_1 FROM (dt_profile p, dt_photos f, dt_members m) WHERE (p.status='1' AND p.member_id=m.id AND f.member_id=m.id AND f.filename_1<>'' AND p.gender='$genders[name]') ";

Cheers,
Darren.
Darren Coleman - http://www.therecklessgeneral.co.uk
Come check out some original acoustic folk-inspired tunes at our website.

Offline fenway

  • MySQL Si-Fu / PHP Resident Alien
  • Global Moderator
  • 'Mind Boggling!'
  • *
  • Posts: 15,444
  • Gender: Male
    • View Profile
Re: trying to cut down this code a bit and it's locking up my server
« Reply #4 on: September 07, 2007, 10:01:57 AM »
Post the EXPLAIN output.
:anim_rules: Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.