close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Basic Search Form

Thread begun 7/20/2014 9:43 pm by Jason | Last modified 8/28/2014 7:46 am by Jason | 11105 views | 101 replies |

Jason

Ridiculously complex search Form

Can someone please help me figure out what I did wrong in this code? I'm trying to type a first and last name into the 2 search boxes and then have it output the results that match $ServingQuery. Right now nothing happens though.



<?php require_once('Connections/local_i.php'); ?>
<?php require_once('webassist/mysqli/rsobj.php'); ?>
<?php
$UserFirstName = new WA_MySQLi_RS("UserFirstName",$local_i,0);
$UserFirstName->setQuery("SELECT pcms2_users.UserID, pcms2_users.UserFirstName FROM pcms2_users");
$UserFirstName->execute();
?>
<?php
$UserLastName = new WA_MySQLi_RS("UserLastName",$local_i,0);
$UserLastName->setQuery("SELECT pcms2_users.UserID, pcms2_users.UserLastName FROM pcms2_users");
$UserLastName->execute();
?>
<?php
$ServingQuery = new WA_MySQLi_RS("ServingQuery",$local_i,1);
$ServingQuery->setQuery("SELECT pcms2_users.UserID, pcms2_users.UserFirstName, pcms2_users.UserLastName, kids_program_shifts.kp_team_id, kids_program_shifts.kp_volunteer, cleaning_team_shifts.cleaning_team_id, cleaning_team_shifts.ct_volunteer, serving_team.* FROM pcms2_users INNER JOIN kids_program_shifts ON pcms2_users.UserID = kids_program_shifts.kp_volunteer INNER JOIN cleaning_team_shifts ON pcms2_users.UserID = cleaning_team_shifts.ct_volunteer INNER JOIN serving_team ON cleaning_team_shifts.cleaning_team_id = serving_team.id AND kids_program_shifts.kp_team_id = serving_team.id");
$ServingQuery->execute();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<form method="get">
<input type="search" name="UserFirstName" id="UserFirstName">
<input type="search" name="UserLastName" id="UserLastName">
<input type="submit" name="search" value="search">
<?php
while(!$ServingQuery->atEnd()) {
?>
<?php echo($ServingQuery->getColumnVal("UserFirstName")); ?>
<?php echo($ServingQuery->getColumnVal("UserLastName")); ?>
<?php echo($ServingQuery->getColumnVal("team")); ?>
<?php
$ServingQuery->moveNext();
}
$ServingQuery->moveFirst(); //return RS to first record
?>
</form>
</body>
</html>

Sign in to reply to this post

Jason ByrnesWebAssist

1) You don't need 3 recordsets, only 1

2) In the recordset you need to add a where clause to filter the first and last name columns on the entered values

WHERE UserFirstName = paramFirstName OR UserLastName = paramLastName

then in the variables section create 2 new variables as:
name: paramFirstName
type: Text
default Value: -1
Runtime value: <?php echo(isset($_GET['UserFirstName'])?$_GET['UserFirstName'];""); ?>

name: paramLastName
type: Text
default Value: -1
Runtime value: <?php echo(isset($_GET['UserLastName'])?$_GET['UserLastName'];""); ?>

Sign in to reply to this post

Jason

Followed your instructions. When I try to test that page now I get this error:
Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\serving\Untitled-2.php on line 16

And this is line 16:
$ServingQuery->bindParam("s", "".(isset($_GET['UserFirstName'])?$_GET['UserFirstName'];"") ."", "-1"); //paramFirstName

Here's the rest of the page after making the changes in case you need to see it.

<?php require_once('Connections/local_i.php'); ?>
<?php require_once('webassist/mysqli/rsobj.php'); ?>
<?php
$ServingQuery = new WA_MySQLi_RS("ServingQuery",$local_i,1);
$ServingQuery->setQuery("SELECT pcms2_users.UserID, pcms2_users.UserFirstName, pcms2_users.UserLastName, kids_program_shifts.kp_team_id, kids_program_shifts.kp_volunteer, cleaning_team_shifts.cleaning_team_id, cleaning_team_shifts.ct_volunteer, serving_team.* FROM pcms2_users INNER JOIN kids_program_shifts ON pcms2_users.UserID = kids_program_shifts.kp_volunteer INNER JOIN cleaning_team_shifts ON pcms2_users.UserID = cleaning_team_shifts.ct_volunteer INNER JOIN serving_team ON cleaning_team_shifts.cleaning_team_id = serving_team.id AND kids_program_shifts.kp_team_id = serving_team.id WHERE pcms2_users.UserFirstName = ? AND pcms2_users.UserLastName = ?");
$ServingQuery->bindParam("s", "".(isset($_GET['UserFirstName'])?$_GET['UserFirstName'];"") ."", "-1"); //paramFirstName
$ServingQuery->bindParam("s", "".(isset($_GET['UserLastName'])?$_GET['UserLastName'];"") ."", "-1"); //paramLastName
$ServingQuery->execute();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<form method="get">
<input type="search" name="UserFirstName" id="UserFirstName">
<input type="search" name="UserLastName" id="UserLastName">
<input type="submit" name="search" value="search">
<?php
while(!$ServingQuery->atEnd()) {
?>
<?php echo($ServingQuery->getColumnVal("UserFirstName")); ?>
<?php echo($ServingQuery->getColumnVal("UserLastName")); ?>
<?php echo($ServingQuery->getColumnVal("team")); ?>
<?php
$ServingQuery->moveNext();
}
$ServingQuery->moveFirst(); //return RS to first record
?>
</form>
</body>
</html>

Sign in to reply to this post

Jason ByrnesWebAssist

My apologies, I Had a syntax error for the run time values in the parameters, they should be:


name: paramFirstName
Runtime value: <?php echo(isset($_GET['UserFirstName'])?$_GET['UserFirstName']:""); ?>

name: paramLastName
Runtime value: <?php echo(isset($_GET['UserLastName'])?$_GET['UserLastName']:""); ?>

Sign in to reply to this post

Jason

That may or may not have worked. The search fields and button display correctly now, but I'm not getting any results. When I test the query it says no data. I'm guessing that means I made a mistake in my query?

Sign in to reply to this post

Jason ByrnesWebAssist

I'll need to troubleshoot directly, see the private message section.

Sign in to reply to this post

Jason

See private message

Sign in to reply to this post

Jason

See private message.

Sign in to reply to this post

Jason ByrnesWebAssist

your query was set to use a inner join on 3 other tables, those tables did not have any related records, so the query was not retunring any records, even without the where clause.

i changed the inner join to left join

Sign in to reply to this post

Jason

We're getting closer, but not quite what I was going for. I'll detail it out a little better in the private message section.

Sign in to reply to this post
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...