|
-
Sep 29th, 2011, 11:02 AM
#1
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Sep 30th, 2011, 11:48 AM
#2
Re: [PHP][MySQL]Selecting multiple records based on multiple conditions into a single
I don't know MySQL well enough. For SQL Server I would use a cross apply
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Oct 4th, 2011, 05:52 AM
#3
Re: [PHP][MySQL]Selecting multiple records based on multiple conditions into a single
 Originally Posted by GaryMazzone
I don't know MySQL well enough. For SQL Server I would use a cross apply
Thanks 
I don't think CROSS APPLY is there in mySQL. But will google it.
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Oct 4th, 2011, 06:14 AM
#4
Re: [PHP][MySQL]Selecting multiple records based on multiple conditions into a single
First of all, what is the scenario here more or less?
Secondly, where do you get the two user ID's from?
Thirdly, in your example the uID 1 is not related to cID 4; why do you want to retrieve it?
Delete it. They just clutter threads anyway.
-
Oct 4th, 2011, 06:31 AM
#5
Re: [PHP][MySQL]Selecting multiple records based on multiple conditions into a single
What I'm trying here is, when a registered user wants to contact the author of a particular content, he could click on the "contact via email" button and a form appears. After entering the message he wants to deliver, he would sent it. One id will be the recipient's and the other one will be the sender's.
It is via jQuery(I'm a mere beginner and don't even know the basics of jQuery, but following tutorials and tricks from other sites, found on Googling)
So, when the form is submitted to a PHP page, it would check whether the current session is a valid user(registered user) or not. If so, it will query the database to find the email ids of both the sender and the author(recipient). Also, it should validate that the content id being passed is belongs to the particular author(which the id is being passed, ie. the second ID). If so, get the email addresses of both of them and also, the content title(which I would be including in the email).
I know how to do it in separate queries. But what I'm trying to do is, I'm trying to combine into a single query to achieve a better performance.
Hope it's clear. 
Thanks
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Oct 4th, 2011, 07:03 AM
#6
Re: [PHP][MySQL]Selecting multiple records based on multiple conditions into a single
It looks like something called GROUP_CONCAT would be a MySQL equivalent to a T-SQL CROSS APPLY.
-
Oct 5th, 2011, 03:01 AM
#7
Re: [PHP][MySQL]Selecting multiple records based on multiple conditions into a single
 Originally Posted by Hack
It looks like something called GROUP_CONCAT would be a MySQL equivalent to a T-SQL CROSS APPLY.
Thanks 
But I'm not sure how it can be used to solve my issue ! After reading about it, it seems to be to concatenate a group into a single record(if I'm correct).
A brief idea on how to use it will be helpful (no need to give me the query string or code, but just the basic idea of how to use it with my query to solve the issue)
I'll try to read other tutorials regarding this, so that the bulb in my head may lightens up after that.
Last edited by akhileshbc; Oct 5th, 2011 at 05:53 AM.
Reason: corrected grammar mistakes :D
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Oct 5th, 2011, 04:33 AM
#8
Re: [PHP][MySQL]Selecting multiple records based on multiple conditions into a single
I don't think putting it all in one query will improve performance and/or readability.
One thing you could pull together is retrieval of the recipients email address and content title.
It would look something like this:
Code:
$recipientId = 3;
$contentId = 4;
$q = "SELECT t2.`Content_title`, t1.`Email`
FROM `Table2` t2
LEFT JOIN `Table1` t1 ON t1.`uID` = t2.`uID`
WHERE t1.`Email` IS NOT NULL
AND t2.`cID` = '$contentId'
AND t2.`uID` = '$recipientId'";
$result = mysql_query($q);
if(($row = mysql_fetch_assoc($result)))
{
// We have a result!
// That means we have verified that the author of $contentId is $recipientId and we found
// the email address for $recipientId
$recipientEmail = $row['Email'];
$contentTitle = $row['Content_title'];
}
else
{
// Something about the input data is invalid.
}
Not tested, but should work
Delete it. They just clutter threads anyway.
-
Oct 5th, 2011, 05:54 AM
#9
Re: [PHP][MySQL]Selecting multiple records based on multiple conditions into a single
Thanks. Will try to experiment with that 
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|