close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

RS if/else

Thread begun 6/12/2020 3:24 am by Jamie | Last modified 6/15/2020 2:44 pm by Ray Borduin | 2224 views | 11 replies |

Jamie

RS if/else

Hey Ray

Have got a recordset that I need to wrap in an if, but will be several if and not sure if an if else would be right?

So basically

I need to filter based on if there is a certain value in the StaffJob column and if it satisfies a specific url slug so below would be if the url is /family-children and StaffJob = Head of Family Children then a certain person is placed at the top of the results.

<?php if (strpos($_SERVER['REQUEST_URI'],"/family-children") !== false) { ?>
<?php
$People = new WA_MySQLi_RS("People",$DBConnection,0);
$People->setQuery("SELECT service_contents.*, join_expertise.*, staff.* FROM service_contents INNER JOIN join_expertise ON service_contents.ServicesID = join_expertise.RowsExpertiseContentID INNER JOIN staff ON join_expertise.RowsStaffContentID = staff.StaffID WHERE service_contents.ServicesID = ? GROUP BY StaffID ORDER BY IF(Locate('Head of Family Children',StaffJob)=1,0,1), StaffOrder ASC");
$People->bindParam("i", "".($PageContents->getColumnVal('ServicesID')) ."", "-1"); //WAQB_Param1
$People->execute();
?>
<?php } ?>



I need to do this and check against:

/family-finance / Head of Family Finance
/personal-injury / Head of Personal Injury
/employment / Head of Employment
/court-of-protection / Head of Court of Protection

And then if none are satsified, this recordset gets used

<?php
$People = new WA_MySQLi_RS("People",$DBConnection,0);
$People->setQuery("SELECT service_contents.*, join_expertise.*, staff.* FROM service_contents INNER JOIN join_expertise ON service_contents.ServicesID = join_expertise.RowsExpertiseContentID INNER JOIN staff ON join_expertise.RowsStaffContentID = staff.StaffID WHERE service_contents.ServicesID = ? GROUP BY StaffID ORDER BY StaffOrder ASC");
$People->bindParam("i", "".($PageContents->getColumnVal('ServicesID')) ."", "-1"); //WAQB_Param1
$People->execute();
?>



Just not sure how to best do it?

Thanks

Jamie

Sign in to reply to this post

Ray BorduinWebAssist

php:
<?php 

$searchfor 
"";
if (
strpos($_SERVER['REQUEST_URI'],"/family-children") !== false) {
  
$searchfor "Head of Family Children";
} else if (
strpos($_SERVER['REQUEST_URI'],"/family-finance") !== false) {
  
$searchfor "Head of Family Finance";
} else if (
strpos($_SERVER['REQUEST_URI'],"/personal-injury") !== false) {
  
$searchfor "Head of Personal Injury";
} else if (
strpos($_SERVER['REQUEST_URI'],"/employment ") !== false) {
  
$searchfor "Head of Employment";
} else if (
strpos($_SERVER['REQUEST_URI'],"/court-of-protection") !== false) {
  
$searchfor "Head of Court of Protection";
}
?>
<?php
$People 
= new WA_MySQLi_RS("People",$DBConnection,0);
$People->setQuery("SELECT service_contents.*, join_expertise.*, staff.* FROM service_contents INNER JOIN join_expertise ON service_contents.ServicesID = join_expertise.RowsExpertiseContentID INNER JOIN staff ON join_expertise.RowsStaffContentID = staff.StaffID WHERE service_contents.ServicesID = ? GROUP BY StaffID ORDER BY IF(Locate(?,StaffJob)=1,0,1), StaffOrder ASC");
$People->bindParam("i""".($PageContents->getColumnVal('ServicesID'))  ."""-1"); //WAQB_Param1
$People->bindParam("s""".($searchfor)  ."""-1"); //WAQB_Param2
$People->execute();
?>
Sign in to reply to this post
Did this help? Tips are appreciated...

Jamie

thats great, many thanks...however, doesnt seem to be working for 2 of them personal injury and court of protectimon.

have attached the page if it helps and link to the live page in PM

Sign in to reply to this post

Ray BorduinWebAssist

It should be:

IF(Locate(?,StaffJob)<>0,1,0)

Sign in to reply to this post
Did this help? Tips are appreciated...

Jamie

I changed it to = as none of them were being displayed in the first position

Have changed it to IF(Locate(?,StaffJob)<>1,0,1) DESC now (adding DESC) and that has worked for some but still not personal injury and court of protectimon.

Sign in to reply to this post

Ray BorduinWebAssist

I think it should be:
IF(Locate(?,StaffJob)<>0,1,0) DESC

Sign in to reply to this post
Did this help? Tips are appreciated...

Jamie

thats great, thank you.

Now on a similar vein, I am trying to do the same for the search on the attached page - if someone does a search with the dropdown, if there is a match 'head of ...' in the StaffJob column then that person gets put into position 1 of the results.

Not sure how I do this?

Cheers

J

Sign in to reply to this post

Ray BorduinWebAssist

It should be the same thing, just using a WHERE clause instead of ORDER BY like:

WHERE Locate(?,StaffJob) <> 0
Sign in to reply to this post
Did this help? Tips are appreciated...

Jamie

sorry Ray, am not sure how that would work? Doersnt it somehow need to check against whats been searched and then depending on that show the relevant person in the first position?

Sign in to reply to this post

Ray BorduinWebAssist

I guess I'm not sure what you are asking for. I thought this was to search by the value not just display it first.

If you just want to display it first, then you could use the exact same code as before, just get the $searchFor value from the submitted form element instead of setting it from the URL like:


if (isset($_GET["selectName"])) $searchfor = $_GET["selectName"];

Sign in to reply to this post
Did this help? Tips are appreciated...
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...