webdev007
Programmer
- Sep 9, 2005
- 168
What I need to achieve:
Out of an Ajax cascade of DD boxes (php MySQL driven) a user may select a unique tag
And figure if in a given category something similar exits
The existing tags are stored in my table as serialized array
Ex: a:3:{i:0;s:6:"asasas";i:1;s:4:"dddd";i:2;s:10:"ddddd mmmm";}
The user’s selected tag is named: $tags_selected and passed as GET as well as a head_category
First I select all existing tags within the same category
$result = $db->query("
SELECT
quest, tags
FROM
quest
WHERE
head_category_quest='$head_category_quest'
");
Then I unserialize stored tags
And need to grab a corresponding row value (for example: id)
But I cannot figure how doing the sub query
By matching one element of the unserialized
With the single passed value from ajax.
The following is delivering some odds result
How may I loop through an unserialize array and match any of its value with the single value (passed by GET) thus being able to read the whole row and getting some values out of it?
while ($row=$db->fetch_array($result) )
{
$tags=$row['tags'];
$tags=unserialize($tags);print_r($tags);
if(in_array($tags_selected, $tags))
{
$tags_selected=serialize($tags_selected);//print_r($tags_selected);
$result2 = $db->query("
SELECT
quest, tags
FROM
quest
WHERE
head_category_quest='$head_category_quest'
AND
tags='$tags_selected'
");
while ($row=$db->fetch_array($result2) )
{
$quest=$row['quest'];
echo"AA $quest<br>";
}
}
}
Out of an Ajax cascade of DD boxes (php MySQL driven) a user may select a unique tag
And figure if in a given category something similar exits
The existing tags are stored in my table as serialized array
Ex: a:3:{i:0;s:6:"asasas";i:1;s:4:"dddd";i:2;s:10:"ddddd mmmm";}
The user’s selected tag is named: $tags_selected and passed as GET as well as a head_category
First I select all existing tags within the same category
$result = $db->query("
SELECT
quest, tags
FROM
quest
WHERE
head_category_quest='$head_category_quest'
");
Then I unserialize stored tags
And need to grab a corresponding row value (for example: id)
But I cannot figure how doing the sub query
By matching one element of the unserialized
With the single passed value from ajax.
The following is delivering some odds result
How may I loop through an unserialize array and match any of its value with the single value (passed by GET) thus being able to read the whole row and getting some values out of it?
while ($row=$db->fetch_array($result) )
{
$tags=$row['tags'];
$tags=unserialize($tags);print_r($tags);
if(in_array($tags_selected, $tags))
{
$tags_selected=serialize($tags_selected);//print_r($tags_selected);
$result2 = $db->query("
SELECT
quest, tags
FROM
quest
WHERE
head_category_quest='$head_category_quest'
AND
tags='$tags_selected'
");
while ($row=$db->fetch_array($result2) )
{
$quest=$row['quest'];
echo"AA $quest<br>";
}
}
}