Robert Granlund
asked on
Query Syntax
I am trying to find a way to use a variable within a query but grabbing the variable and using the variable from within the same query. I have a DB that stores Event ID's and Event Dates in two different tables. I need the Event ID to find the Event Date. If I do two queries I cant order the queries by date because that query is not inside of the original WHILE statement. I am trying to do something like this:
(The ID is the part I am trying to figure out.)
(The ID is the part I am trying to figure out.)
$q ="SELECT magentocatalog_category_entity.entity_id AS id,
magentocatalog_category_entity_datetime.value AS end_date
FROM magentocatalog_category_entity,
magentocatalog_category_entity_datetime
WHERE magentocatalog_category_entity.parent_id='175'
AND magentocatalog_category_entity_datetime.entity_id='id'
ORDER BY end_date ASC";
Maybe something like this?
$id = "175";
$q =
"
SELECT
magentocatalog_category_entity.entity_id AS id,
magentocatalog_category_entity_datetime.value AS end_date
FROM
magentocatalog_category_entity,
magentocatalog_category_entity_datetime
WHERE
magentocatalog_category_entity.parent_id='$id'
AND
magentocatalog_category_entity_datetime.entity_id='$id'
ORDER BY
end_date ASC
"
;
ASKER
I don't know if it is correct. Well, I know it is not correct cause it does not work, But what I am trying to write is closer to your second example:
WHERE magentocatalog_category_entity.parent_id='175'
AND magentocatalog_category_entity_datetime.entity_id='magentocatalog_category_entity.entity_id'
WHERE magentocatalog_category_entity.parent_id='175'
AND magentocatalog_category_entity_datetime.entity_id=magentocatalog_category_entity.entity_id
maybe without quotes???
It would be without the quotes if your intent is to match a numeric data element.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
some data from your tables will be helpfully, as a example...
Line 2 of this snippet is the one that has the quotes out of place.
;-)
~Ray
WHERE magentocatalog_category_entity.parent_id='175'
AND magentocatalog_category_entity_datetime.entity_id='magentocatalog_category_entity.entity_id'
It is OK to quote number strings in a query. It is not necessary to do so. But if you put the quotes around the wrong things, it can be assured that failure is not left to chance!;-)
~Ray
is this code correct???
Open in new window
or you mean :Open in new window