Hello -
Please help! I'm creating search pages using Dreamweaver 8, PHP, and MySQL database with Mac OS X. I think my code is good, but when I run my query, I come up with no data, even though I know there is data in the database that should be coming up.
I'm searching two tables that are linked with a foreign key (member_id). The members table is the main table (where "member_id" is an auto increment key) , and the specialty_groups table uses "member_id" to reference which member has what specialty.
I've created a LEFT JOIN with USING (member_id). I've tried modifying the code by hand several times, and still come up with "no data."
My code (as created by Dreamweaver 8) is below: -
<?php
-
$varspecialty_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchspecialty'])) {
-
$varspecialty_rsmembersearchresultsm = $_POST['mbrsearchspecialty'];
-
}
-
$varfirstname_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchfname'])) {
-
$varfirstname_rsmembersearchresultsm = $_POST['mbrsearchfname'];
-
}
-
$varmbrlname_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchlname'])) {
-
$varmbrlname_rsmembersearchresultsm = $_POST['mbrsearchlname'];
-
}
-
$varmbrfirm_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchfirm'])) {
-
$varmbrfirm_rsmembersearchresultsm = $_POST['mbrsearchfirm'];
-
}
-
$varmedia_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchmedia'])) {
-
$varmedia_rsmembersearchresultsm = $_POST['mbrsearchmedia'];
-
}
-
$varfirstname_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchfname'])) {
-
$varfirstname_rsmembersearchresultsm = (get_magic_quotes_gpc()) ? $_POST['mbrsearchfname'] : addslashes($_POST['mbrsearchfname']);
-
}
-
$varmbrlname_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchlname'])) {
-
$varmbrlname_rsmembersearchresultsm = (get_magic_quotes_gpc()) ? $_POST['mbrsearchlname'] : addslashes($_POST['mbrsearchlname']);
-
}
-
$varmbrfirm_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchfirm'])) {
-
$varmbrfirm_rsmembersearchresultsm = (get_magic_quotes_gpc()) ? $_POST['mbrsearchfirm'] : addslashes($_POST['mbrsearchfirm']);
-
}
-
$varmedia_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchmedia'])) {
-
$varmedia_rsmembersearchresultsm = (get_magic_quotes_gpc()) ? $_POST['mbrsearchmedia'] : addslashes($_POST['mbrsearchmedia']);
-
}
-
$varspecialty_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchspecialty'])) {
-
$varspecialty_rsmembersearchresultsm = (get_magic_quotes_gpc()) ? $_POST['mbrsearchspecialty'] : addslashes($_POST['mbrsearchspecialty']);
-
}
-
mysql_select_db($database_connection, $connection);
-
$query_rsmembersearchresultsm = sprintf("SELECT member.member_id, member.firstname, member.lastname, member.businessname, specialty_group.member_id FROM member LEFT JOIN specialty_group USING (member_id) WHERE member.firstname LIKE '%%%s%%' AND member.lastname LIKE '%%%s%%' AND member.businessname LIKE '%%%s%%' AND member.media_contact = '%s' AND specialty_group.specialty = '%s'", $varfirstname_rsmembersearchresultsm,$varmbrlname_rsmembersearchresultsm,$varmbrfirm_rsmembersearchresultsm,$varmedia_rsmembersearchresultsm,$varspecialty_rsmembersearchresultsm);
-
$rsmembersearchresultsm = mysql_query($query_rsmembersearchresultsm, $connection) or die(mysql_error());
-
$row_rsmembersearchresultsm = mysql_fetch_assoc($rsmembersearchresultsm);
-
$totalRows_rsmembersearchresultsm = mysql_num_rows($rsmembersearchresultsm);
-
?>
-
Thank you in advance for taking the time to help.
Best,
Charity
9 2105
Heya, Charity. Welcome to TSDN! -
SELECT
-
`member`.`member_id`,
-
`member`.`firstname`,
-
`member`.`lastname`,
-
`member`.`businessname`,
-
`specialty_group`.`member_id`
-
FROM
-
(
-
`member`
-
LEFT JOIN
-
`specialty_group`
-
USING
-
(`member_id`)
-
)
-
WHERE
-
(
-
`member`.`firstname` LIKE '%%%s%%' -- valid - sprintf()
-
AND
-
`member`.`lastname` LIKE '%%%s%%'
-
AND
-
`member`.`businessname` LIKE '%%%s%%'
-
AND
-
`member`.`media_contact` = '%s'
-
AND
-
`specialty_group`.`specialty` = '%s'
-
)
-
I see nothing immediately wrong with the structure of your query,
Try adding these lines right after you create the query: -
$query_rsmembersearchresultsm = "SELECT ... ";
-
-
echo $query_rsmembersearchresultsm, '<br /><br />';
-
Does the query look right, or are there any missing fields? Try dropping that query into your MySQL client app and see if it is getting results.
Hello and thank you for responding.
I copied the text below and entered it directly into my MySQL client admin and got the response "empty recordset." -
SELECT
-
`member`.`member_id`,
-
`member`.`firstname`,
-
`member`.`lastname`,
-
`member`.`businessname`,
-
`specialty_group`.`member_id`
-
FROM
-
(
-
`member`
-
LEFT JOIN
-
`specialty_group`
-
USING
-
(`member_id`)
-
)
-
WHERE
-
(
-
`member`.`firstname` LIKE '%%%s%%' -- valid - sprintf()
-
AND
-
`member`.`lastname` LIKE '%%%s%%'
-
AND
-
`member`.`businessname` LIKE '%%%s%%'
-
AND
-
`member`.`media_contact` = '%s'
-
AND
-
`specialty_group`.`specialty` = '%s'
-
)
-
I'm not sure where exactly I should put the code below:
Try adding these lines right after you create the query: -
$query_rsmembersearchresultsm = "SELECT ... ";
-
-
echo $query_rsmembersearchresultsm, '<br /><br />';
-
Should I put the code into my .php page after the code I already have, or elsewhere? Sorry - I'm confused! When I put it in my page as it is now after the code I have, the top of the page (as posted) says, "SELECT ..."
Thanks again!
Charity
Hello - I'm back with an edit to my original post.
So I've gotten the query to work by replacing all "="s with "LIKE." However, I'm now running into another problem.
I'm using LEFT JOIN to join my 'members' table and my 'specialty_groups' table (USING member_id). This is supposed to return all rows from the first table ('members'), whether or not there's a match in the second table ('specialty_groups').
Instead, what I'm getting is only rows that are in the 'specialty_groups' table.
I've tried replacing LEFT JOIN with RIGHT JOIN to see if that makes a difference, and it doesn't. I still only get records that have a match on the 'specialty_groups' table.
My code is below: -
<?php
-
$varspecialty_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchspecialty'])) {
-
$varspecialty_rsmembersearchresultsm = $_POST['mbrsearchspecialty'];
-
}
-
$varfirstname_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchfname'])) {
-
$varfirstname_rsmembersearchresultsm = $_POST['mbrsearchfname'];
-
}
-
$varmbrlname_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchlname'])) {
-
$varmbrlname_rsmembersearchresultsm = $_POST['mbrsearchlname'];
-
}
-
$varmbrfirm_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchfirm'])) {
-
$varmbrfirm_rsmembersearchresultsm = $_POST['mbrsearchfirm'];
-
}
-
$varmedia_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchmedia'])) {
-
$varmedia_rsmembersearchresultsm = $_POST['mbrsearchmedia'];
-
}
-
$varfirstname_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchfname'])) {
-
$varfirstname_rsmembersearchresultsm = (get_magic_quotes_gpc()) ? $_POST['mbrsearchfname'] : addslashes($_POST['mbrsearchfname']);
-
}
-
$varmbrlname_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchlname'])) {
-
$varmbrlname_rsmembersearchresultsm = (get_magic_quotes_gpc()) ? $_POST['mbrsearchlname'] : addslashes($_POST['mbrsearchlname']);
-
}
-
$varmbrfirm_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchfirm'])) {
-
$varmbrfirm_rsmembersearchresultsm = (get_magic_quotes_gpc()) ? $_POST['mbrsearchfirm'] : addslashes($_POST['mbrsearchfirm']);
-
}
-
$varmedia_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchmedia'])) {
-
$varmedia_rsmembersearchresultsm = (get_magic_quotes_gpc()) ? $_POST['mbrsearchmedia'] : addslashes($_POST['mbrsearchmedia']);
-
}
-
$varspecialty_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchspecialty'])) {
-
$varspecialty_rsmembersearchresultsm = (get_magic_quotes_gpc()) ? $_POST['mbrsearchspecialty'] : addslashes($_POST['mbrsearchspecialty']);
-
}
-
mysql_select_db($database_connection, $connection);
-
$query_rsmembersearchresultsm = sprintf("SELECT member.member_id, member.firstname, member.lastname, member.businessname, specialty_group.member_id FROM member LEFT JOIN specialty_group ON member.member_id = specialty_group.member_id WHERE member.firstname LIKE '%%%s%%' AND member.lastname LIKE '%%%s%%' AND member.businessname LIKE '%%%s%%' AND member.media_contact LIKE '%%%s%%' AND specialty_group.specialty LIKE '%%%s%%' GROUP BY member.member_id", $varfirstname_rsmembersearchresultsm,$varmbrlname_rsmembersearchresultsm,$varmbrfirm_rsmembersearchresultsm,$varmedia_rsmembersearchresultsm,$varspecialty_rsmembersearchresultsm);
-
$rsmembersearchresultsm = mysql_query($query_rsmembersearchresultsm, $connection) or die(mysql_error());
-
$row_rsmembersearchresultsm = mysql_fetch_assoc($rsmembersearchresultsm);
-
$totalRows_rsmembersearchresultsm = mysql_num_rows($rsmembersearchresultsm);
-
?>
-
Any ideas? I'd be ever so grateful.
Thanks! Charity
Heya, Charity.
You have this in your WHERE clause: -
specialty_group.specialty LIKE '%%%s%%'
-
Which will automatically reject any rows where 'specialty_group'.'specialty' is null.
To fix this, you might want to change your query slightly: -
(specialty_group.specialty LIKE '%%%s%%' OR specialty_group.specialty IS NULL)
-
Thank you!!
You totally rock. That solved it.
Thank you thank you thank you.
Now another question - completely related. This query is on a page that lists the search results as the member's first name, last name, and business name. People can then click on the member's first name to see their entire record (address, phone numbers, etc.).
I'm running the query from two tables - the parent table is the 'member' table, and the child table is the 'specialty_groups' table.
Whenever I run a search for a member that has specialties (which are a search parameter and are housed in the specialty_groups table), their entire record comes up. That's great.
However, when I search for a member that doesn't have any specialties in the specialty_groups table, their member_id (i.e. the 'recordID') is not passed on to the page that gives all of that member's details. The link looks like this: http://www.aialosangeles.org/databas....php?recordID=
The new code as I have it is now this: -
<?php
-
$varspecialty_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchspecialty'])) {
-
$varspecialty_rsmembersearchresultsm = $_POST['mbrsearchspecialty'];
-
}
-
$varfirstname_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchfname'])) {
-
$varfirstname_rsmembersearchresultsm = $_POST['mbrsearchfname'];
-
}
-
$varmbrlname_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchlname'])) {
-
$varmbrlname_rsmembersearchresultsm = $_POST['mbrsearchlname'];
-
}
-
$varmbrfirm_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchfirm'])) {
-
$varmbrfirm_rsmembersearchresultsm = $_POST['mbrsearchfirm'];
-
}
-
$varmedia_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchmedia'])) {
-
$varmedia_rsmembersearchresultsm = $_POST['mbrsearchmedia'];
-
}
-
$varfirstname_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchfname'])) {
-
$varfirstname_rsmembersearchresultsm = (get_magic_quotes_gpc()) ? $_POST['mbrsearchfname'] : addslashes($_POST['mbrsearchfname']);
-
}
-
$varmbrlname_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchlname'])) {
-
$varmbrlname_rsmembersearchresultsm = (get_magic_quotes_gpc()) ? $_POST['mbrsearchlname'] : addslashes($_POST['mbrsearchlname']);
-
}
-
$varmbrfirm_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchfirm'])) {
-
$varmbrfirm_rsmembersearchresultsm = (get_magic_quotes_gpc()) ? $_POST['mbrsearchfirm'] : addslashes($_POST['mbrsearchfirm']);
-
}
-
$varmedia_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchmedia'])) {
-
$varmedia_rsmembersearchresultsm = (get_magic_quotes_gpc()) ? $_POST['mbrsearchmedia'] : addslashes($_POST['mbrsearchmedia']);
-
}
-
$varspecialty_rsmembersearchresultsm = "%";
-
if (isset($_POST['mbrsearchspecialty'])) {
-
$varspecialty_rsmembersearchresultsm = (get_magic_quotes_gpc()) ? $_POST['mbrsearchspecialty'] : addslashes($_POST['mbrsearchspecialty']);
-
}
-
mysql_select_db($database_connection, $connection);
-
$query_rsmembersearchresultsm = sprintf("SELECT member.member_id, member.firstname, member.lastname, member.businessname, specialty_group.member_id FROM member LEFT JOIN specialty_group ON member.member_id = specialty_group.member_id WHERE member.firstname LIKE '%%%s%%' AND member.lastname LIKE '%%%s%%' AND member.businessname LIKE '%%%s%%' AND (member.media_contact LIKE '%%%s%%' OR member.media_contact IS NULL) AND (specialty_group.specialty LIKE '%%%s%%' OR specialty_group.specialty IS NULL) GROUP BY member.member_id", $varfirstname_rsmembersearchresultsm,$varmbrlname_rsmembersearchresultsm,$varmbrfirm_rsmembersearchresultsm,$varmedia_rsmembersearchresultsm,$varspecialty_rsmembersearchresultsm);
-
$rsmembersearchresultsm = mysql_query($query_rsmembersearchresultsm, $connection) or die(mysql_error());
-
$row_rsmembersearchresultsm = mysql_fetch_assoc($rsmembersearchresultsm);
-
$totalRows_rsmembersearchresultsm = mysql_num_rows($rsmembersearchresultsm);
-
?>
-
Any ideas or suggestions are appreciated!
Heya, Charity.
Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
An addendum to my previous edited post:
When I create my query in my recordset in Dreamweaver and run a test, records are shown; however, under the columns 'member.member_id' and 'specialty_group.member_id', there is no information...unless the record has rows in the 'specialty_group' table.
If the person doesn't have any specialties listed in the 'specialty_group' table, then their member.member_id doesn't show up!
Why, why, why??
Thanks for your help!
Heya, Charity.
What does your query look like now?
If the person doesn't have any specialties listed in the 'specialty_group' table, then their member.member_id doesn't show up!
I am facing the similar issue, did you find out the solution for this...???
Sign in to post your reply or Sign up for a free account.
Similar topics
by: DarthMacgyver |
last post by:
Hello,
I recently wrote a survey application. Each question is very similar.
The first questions gives me a problem when there are multiple people
taking the survey (The Database connection...
|
by: Josh Felker |
last post by:
Hey everyone.
I have a daily log form with my investing info. In that form I have 2
subforms, the first shows my profits on all the stocks I traded that day,
the second shows my profits on...
|
by: Marcin Zmyslowski |
last post by:
Hello all!
I have the following problem with MS Access 2003 permissions.
I have two users. One is admin and the second one is user who has full
permissions to enter modify and read data.
I...
|
by: mimo |
last post by:
Hello,
I have seen samples on how to pull data from one table and save back to it
using the Form View control.
How do I pull from multiple tables and save back to multiple tables on one...
|
by: Raj |
last post by:
Hi all,
I have couple of questions some one plzz help
1.I have a query which run for 2 hours on my production machine, it
returns 1.5 millon rows, i looked at the explain plan it is picking up...
|
by: fong.yang |
last post by:
I've got a database with about 300,000 records. There are several
different tables that are set up the same way with identical fields. I
have the same queries individually set up for each table. ...
|
by: mkjets |
last post by:
I have worked for hours on trying to find a solution and have not
figured it out. I am working in Access 2003. I need to create a query
that takes values from 1 table and displays them in...
|
by: crazdandconfusd |
last post by:
I have a database with two tables I use for shipping information. One is for if I'm only shipping one item and the other is for a back page of a report for when I ship multiple items. If I'm...
|
by: HC |
last post by:
Hello, all, I started out thinking my problems were elsewhere but as I
have worked through this I have isolated my problem, currently, as a
difference between MSDE and SQL Express 2005 (I'll just...
|
by: The Frog |
last post by:
Hello Everyone,
I have been asked to try and create a single SQL query to retrieve
product information from a database. The way that data is arranged is
that in some tables there are user...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |