iseriouslyneedhelp Posted July 11, 2012 Share Posted July 11, 2012 I'm trying to make the following code work and can't seem to figure it out. I know it has to do with the line I commented on, but can't figure out how to make it work. I've tried a few different ways with no luck. It's this part "] == "'.$status.'")" I've tried "$status", "'.$status.'", '.$status.','$status' ...Any idea? function showresults($conn) { // DEFAULT RESULTS $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'New' ORDER BY date DESC"); // STATUS RESULTS ('New', 'Hot', 'Warm', 'Cold', 'Rejected', 'Closed') $status = $_GET['status']; if(isset($_GET['status']) && $_GET['status'] == "'.$status.'") // THIS IS THE ISSUE, JUST NOT SURE HOW TO WRITE $status after == $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '.$status.' ORDER BY date DESC"); // BIND AND EXECUTE $stmt->execute(); $stmt->bind_result($ID,$date,$firstname,$lastname,$spousefirst,$spouselast,$primarybday,$spousebday,$phonecell,$phonehome,$phoneoffice,$spousecell,$phoneother,$email,$emailspouse,$emailother,$emailspouseother,$address,$suite,$city,$state,$zipcode,$addressother,$suiteother,$cityother,$stateother,$zipcodeother,$agentassigned,$contacttype,$status,$contactsource,$timing,$password,$subscribesearches,$subscribedrips); while ($stmt->fetch()) { echo' <tr> <td><input type="checkbox" name="checked[]" value="'.$ID.'"></td> <td><a href="/cms/view/?ID='.$ID.'"><strong>'.$firstname.' '.$lastname.'</strong></a></td> <td>'.$phonecell.'</td> <td><a href="mailto:'. $email.'">'.$email.'</a></td> <td>'.date("M jS, g:i A", strtotime($date)).'</td> <td>'.$contactsource.'</td> <td>'.$status.'</td> <td>'.$contacttype.'</td> <td>'.$agentassigned.'</td> <td><a href="/cms/contacts/notes.php?ID='.$ID.'">V </a>+</td> <td><a href="/cms/contacts/todo.php?ID='.$ID.'">V </a>+</td> <td><a href="javascript: removelead('.$ID.')">D</a></td> </tr>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/ Share on other sites More sharing options...
Mahngiel Posted July 11, 2012 Share Posted July 11, 2012 why are you quoting and concatenating? Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360852 Share on other sites More sharing options...
Pikachu2000 Posted July 11, 2012 Share Posted July 11, 2012 Since you've just assigned the value from $_GET['status'] to $status in the previous line of code, there is no need for the $_GET['status'] == $status comparison at all. If you 're trying to make sure $status contains one of the values from the list you have above that (new, hot, warm, etc. . . ), you should put those values in an array and use in_array instead. Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360853 Share on other sites More sharing options...
iseriouslyneedhelp Posted July 11, 2012 Author Share Posted July 11, 2012 why are you quoting and concatenating? Did you not read my post? I'm experimenting: I've tried a few different ways with no luck. It's this part "] == "'.$status.'")" I've tried "$status", "'.$status.'", '.$status.','$status' ... Any idea? Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360854 Share on other sites More sharing options...
iseriouslyneedhelp Posted July 11, 2012 Author Share Posted July 11, 2012 Since you've just assigned the value from $_GET['status'] to $status in the previous line of code, there is no need for the $_GET['status'] == $status comparison at all. If you 're trying to make sure $status contains one of the values from the list you have above that (new, hot, warm, etc. . . ), you should put those values in an array and use in_array instead. I see what you're saying, I was trying to prevent from having to create an array with (new, hot, warm, etc. . . ) because if a user adds a new status type, to the database(contactstatus), I would have to manually go in and change the array, does that make sense? Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360859 Share on other sites More sharing options...
Pikachu2000 Posted July 11, 2012 Share Posted July 11, 2012 No, it doesn't make sense really. You could just as easily run a SELECT COUNT() query to verify whether the value is a valid status or not, but I'm not sure I'd let users edit things like that. Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360865 Share on other sites More sharing options...
iseriouslyneedhelp Posted July 11, 2012 Author Share Posted July 11, 2012 No, it doesn't make sense really. You could just as easily run a SELECT COUNT() query to verify whether the value is a valid status or not, but I'm not sure I'd let users edit things like that. I'll try to explain, maybe I'm approaching this wrong and you can help straighten me out. Here is what I had before: if(isset($_GET['status']) && $_GET['status'] == "New") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'New' ORDER BY date DESC"); if(isset($_GET['status']) && $_GET['status'] == "Hot") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Hot' ORDER BY date DESC"); if(isset($_GET['status']) && $_GET['status'] == "Warm") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Warm' ORDER BY date DESC"); if(isset($_GET['status']) && $_GET['status'] == "Cold") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Cold' ORDER BY date DESC"); if(isset($_GET['status']) && $_GET['status'] == "Rejected") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Rejected' ORDER BY date DESC"); if(isset($_GET['status']) && $_GET['status'] == "Closed") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Closed' ORDER BY date DESC"); Here is what I'm trying to change it to so that if a user adds a new status type into the database it's automatically available to search by (in other words, I don't have to go in and create a new line as in the above code. $status = $_GET['status']; if(isset($_GET['status']) && $_GET['status'] == "'.$status.'") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '.$status.' ORDER BY date DESC"); Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360874 Share on other sites More sharing options...
xyph Posted July 11, 2012 Share Posted July 11, 2012 $_GET['status'] == "'.$status.'" will never be true, if you're defining $status = $_GET['status']; Are you trying to validate that status is a valid option? If so, you're going to have to manually define the array, or build the array form this list of allowed values in the database, and check against that. Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360883 Share on other sites More sharing options...
Drummin Posted July 11, 2012 Share Posted July 11, 2012 Maybe I'm missing something, but how can GET and echo even be in the function showresults($conn) {}? Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360887 Share on other sites More sharing options...
iseriouslyneedhelp Posted July 11, 2012 Author Share Posted July 11, 2012 $_GET['status'] == "'.$status.'" will never be true, if you're defining $status = $_GET['status']; Are you trying to validate that status is a valid option? If so, you're going to have to manually define the array, or build the array form this list of allowed values in the database, and check against that. Not validate that status is a valid option. Instead, what I want is for the leads that have just the status 'Hot' to show or 'Cold' or 'New'. So, what I have is a dropdown with all the options (New, Hot, Cold, etc.) and when one is selected it only displays those leads. Previously I had each one with a statement if(isset($_GET['status']) && $_GET['status'] == "New") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'New' ORDER BY date DESC"); if(isset($_GET['status']) && $_GET['status'] == "Hot") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Hot' ORDER BY date DESC"); And what I want to do is something like this (but it's not working): if(isset($_GET['status']) && $_GET['status'] == '.$status.') $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '.$status.' ORDER BY date DESC"); Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360889 Share on other sites More sharing options...
Drummin Posted July 11, 2012 Share Posted July 11, 2012 if(isset($_GET['status']) && $_GET['status'] == "$status") Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360890 Share on other sites More sharing options...
iseriouslyneedhelp Posted July 11, 2012 Author Share Posted July 11, 2012 if(isset($_GET['status']) && $_GET['status'] == "$status") Thanks, that doesn't do it though. Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360891 Share on other sites More sharing options...
xyph Posted July 11, 2012 Share Posted July 11, 2012 You're over-complicating this. <?php $query = "SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday, phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother, emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother, stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing, password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor')"; if(isset($_GET['status'])) { $status = $conn->escape_string($_GET['status']); $query .= " AND STATUS = '$status'"; } $query = " ORDER BY date DESC"; $conn->prepare($query); ?> Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360897 Share on other sites More sharing options...
mikosiko Posted July 11, 2012 Share Posted July 11, 2012 other alternative (maintaining 'NEW' as the Default option): function showresults() { // DEFAULT $status = 'NEW'; // STATUS RESULTS ('New', 'Hot', 'Warm', 'Cold', 'Rejected', 'Closed') if (isset($_GET['status']) && !empty($_GET['status'])) { $status = $conn->escape_string($_GET['status']); } $query = "SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday, spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother, email,emailspouse,emailother,emailspouseother,address,suite,city, state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother, agentassigned,contacttype,status,contactsource,timing,password, subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '$status' ORDER BY date DESC"; $stmt = $conn->prepare( $query); Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360903 Share on other sites More sharing options...
iseriouslyneedhelp Posted July 11, 2012 Author Share Posted July 11, 2012 other alternative (maintaining 'NEW' as the Default option): function showresults() { // DEFAULT $status = 'NEW'; // STATUS RESULTS ('New', 'Hot', 'Warm', 'Cold', 'Rejected', 'Closed') if (isset($_GET['status']) && !empty($_GET['status'])) { $status = $conn->escape_string($_GET['status']); } $query = "SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday, spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother, email,emailspouse,emailother,emailspouseother,address,suite,city, state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother, agentassigned,contacttype,status,contactsource,timing,password, subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '$status' ORDER BY date DESC"; $stmt = $conn->prepare( $query); THIS IS EXACTLY WHAT I WAS LOOKING FOR!!!! THANK YOU!!! ALSO THANKS TO EVERYONE ELSE WHO CHIMED IN TO HELP!!!! MUCH APPRECIATED!!! Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360911 Share on other sites More sharing options...
iseriouslyneedhelp Posted July 11, 2012 Author Share Posted July 11, 2012 other alternative (maintaining 'NEW' as the Default option) Here is another challenge...Lets say I have another dropdown box on the page with Sources (Website, Referral, etc.) How would I add this in to the function? So I have: function showresults($conn) { // DEFAULT RESULTS $status = 'New'; // STATUS RESULTS ('New', 'Hot', 'Warm', 'Cold', 'Rejected', 'Closed') if (isset($_GET['status']) && !empty($_GET['status'])) { $status = $conn->escape_string($_GET['status']); } $query = "SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '$status' ORDER BY date DESC"; $stmt = $conn->prepare($query); // SOURCE RESULTS if(isset($_GET['contactsource']) && $_GET['contactsource'] == "Website") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND contactsource = 'Buzz' ORDER BY date DESC"); if(isset($_GET['contactsource']) && $_GET['contactsource'] == "Referral") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND contactsource = 'Expired' ORDER BY date DESC"); Because if I do the following, the DEFAULT and STATUS RESULTS DON't SHOW UP function showresults($conn) { // DEFAULT RESULTS $status = 'New'; // STATUS RESULTS ('New', 'Hot', 'Warm', 'Cold', 'Rejected', 'Closed') if (isset($_GET['status']) && !empty($_GET['status'])) { $status = $conn->escape_string($_GET['status']); } $query = "SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '$status' ORDER BY date DESC"; $stmt = $conn->prepare($query); // SOURCE RESULTS ('Website', 'Referral',) if (isset($_GET['contactsource']) && !empty($_GET['contactsource'])) { $contactsource = $conn->escape_string($_GET['contactsource']); } $query = "SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND contactsource = '$contactsource' ORDER BY date DESC"; $stmt = $conn->prepare($query); Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360913 Share on other sites More sharing options...
xyph Posted July 11, 2012 Share Posted July 11, 2012 Combine both of our examples. Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360916 Share on other sites More sharing options...
iseriouslyneedhelp Posted July 11, 2012 Author Share Posted July 11, 2012 Combine both of our examples. When I do that, it doesn't filter by source...it doesn't do anything but keep the default leads displayed. Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360921 Share on other sites More sharing options...
xyph Posted July 11, 2012 Share Posted July 11, 2012 How have you implemented it? Quote Link to comment https://forums.phpfreaks.com/topic/265534-isset-not-cooperating/#findComment-1360936 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.