Hi all,
I am working on a site search for a content management system. The system using a db design that has "paragraphs" of text that may or may not be tied to a "page". For my site search i check the paragraphs for a text match and then check to make sure the paragraph is actually tied to a page. The paragraphs that are not tied/related to a page are then not included in the search results.
I made a function to check the returned paragraphs to see if they are tied to a page:
function getPage($paragraphID) {
$pbQuery = "select pid, bindID, lang from paragraphBinding where pid = '" . $paragraphID . "' and lang = '" . $_SESSION['userLang'] ."'";
// echo $pbQuery;
$pbResult = mysql_query($pbQuery)or die("Died on pbQuery");
if(mysql_num_rows($pbResult) < 1) {
return 0;
} else {
$pbRow = mysql_fetch_array($pbResult);
$ebQuery = "select pBindID, editionID from editionBinding where pBindID = '" . $pbRow['bindID'] . "'";
$ebResult = mysql_query($ebQuery) or die ("Died on ebQuery");
if(mysql_num_rows($ebResult) > 0) {
$ebRow = mysql_fetch_array($ebResult);
$enQuery = "select ID, editionID from edition_new where editionID = '" . $ebRow['editionID'] . "'";
$enResult = mysql_query($enQuery) or die ("Died on enQuery");
if(mysql_num_rows($enResult) > 0) {
$enRow = mysql_fetch_array($enResult);
$steQuery = "select editionID, storyID from story_to_edition where editionID = '" . $enRow['ID'] . "'";
$steResult = mysql_query($steQuery) or die("Died on steQuery");
if(mysql_num_rows($steResult) > 0) {
$steRow = mysql_fetch_array($steResult);
$sQuery = "select storyID, path from pages where storyID = '" . $steRow['storyID'] . "'";
$sResult = mysql_query($sQuery) or die("Died on sQuery");
if(mysql_num_rows($sResult) > 0) {
$sRow = mysql_fetch_array($sResult);
return $sRow['path'];
} else {
return 0;
}
}
}
}
}
}
What i'm wondering is if this can be simplified into a single Select statement? I am no pro with SQL but i am imagining that this can someone how be simplified into a single SQL statement.
My next challenge is to be able to split the returned results into multiple pages. BUT as it stands i can't use LIMIT to do this because my original result set includes paragraphs that i want to exclude (ie: must use above function).
Any help is appreciated!