Hi,
Take a look at this method:
public function insertAuthor($authArray, $PCorder=0)
{
$query = sprintf('SELECT Pid, Pname FROM People
WHERE Pname IN(\\'%s\\') ORDER BY Pid ASC',
implode('\\',\\'', $authArray));
$result = mysql_query($query);
$maxquery = "SELECT MAX(CPid) as max FROM ConfPaper";
$maxresult = mysql_query($maxquery);
$max = mysql_fetch_array($maxresult);
$CPid = $max['max'];
if($result && mysql_num_rows($result) > 0)
{
$sqlValues = array();
while(list($PId, $PName) = mysql_fetch_row($result))
{
if(in_array($PName, $authArray))
{
$sqlValues[] = sprintf("(%d, ".$_GET['CPRid'].",
".$CPid.", %d, now(), 0)", $PId, $PCorder++ );
// Author already exists within the Pname table
// remove user from $authArray
$key = array_search($PName, $authArray);
unset($authArray[$key]);
}
}
$sql = "INSERT INTO PeopleCon(Person_id, PCHid, Pid,
PCorder, PCdateadded, PCdeleted) VALUES \
";
$sql .= implode(",\
", $sqlValues);
$result = mysql_query($sql);
// If there are Authors left within the $authArray
// Add them to the Pname table
if(count($authArray) > 0)
{
$this->insertPersons($authArray); // call insertPersons
method for remaining authors
$this->insertAuthor($authArray, $PCorder); // insert
the remaining auhtors into PeopleCon
}
}
}
Then i call the method like so:
$p = new People();
$authors = array_filter(array_map('mysql_real_escape_string',
$_POST['author']));
$p->insertAuthor($authors);
The query works fine, but it only does the $this->insertPersons($authArray); code IF a person exists, so if this query is true:
$query = sprintf('SELECT Pid, Pname FROM People WHERE Pname IN(\\'%s\\') ORDER BY Pid ASC', implode('\\',\\'', $authArray));
$result = mysql_query($query);
It works, but i need to have it so if there are no matches for Pname still do the insert methods…
Any ideas?