Search Article

[insert_php]

# FileName=”Connection_pdo_mysql.htm”
# Type=”MYSQL”
# HTTP=”true”
$hostname = “mysql1005.mochahost.com”;
$database = “fosco1_foscopa”;
$username = “fosco1_wp527”;
$password = “S82..2qi9p”;
$connStr = ‘mysql:host=mysql1005.mochahost.com;dbname=fosco1_foscopa’;
$user = ‘fosco1_wp527’;
$pass = ‘S82..2qi9p’;
//set_exception_handler(‘exceptionHandler’);
try
{
$conn = new PDO($connStr, $user, $pass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
showError(“Sorry, an error has occurred. Please try your request
later\n” . $e->getMessage());
}

if(isset($_POST[‘f_search’])){
if (isset($_GET[“page”])) { $page = $_GET[“page”]; } else { $page=1; };
$results_per_page=50;
$start_from = ($page-1) * $results_per_page;

$queried = $_POST[‘f_search’]; // always escape

$keys = explode(” “,$queried);

$article= “SELECT distinct(articles.f_articleid), f_title, f_abstract, f_journal, f_year, f_author, f_affiliation FROM articles inner join authors on authors.f_articleid = articles.f_articleid where f_title like ‘%$queried%’ “;
foreach($keys as $k){
$article .= ” or f_title like ‘%$k%’ or f_author LIKE ‘%$k%’ “;}
$article .= “ORDER BY IF(f_title like ‘%$k%’,1,0)+
IF(f_author LIKE ‘%$k%’,1,0) DESC limit $start_from, $results_per_page “;

$count =”SELECT count(distinct(articles.f_articleid)) as num FROM articles inner join authors on authors.f_articleid = articles.f_articleid where f_title like ‘%$queried%’ “;
foreach($keys as $k){
$count .= ” or f_author LIKE ‘%$k%’ OR f_title like ‘%$k%’ “;}
$no = $conn->query($count);
$num = $no->fetch(PDO::FETCH_ASSOC);
$ncount = $num[‘num’];

}

if ((isset($_GET[‘article’])) && ($_GET[‘article’] != “”)) {
$f_id = ($_GET[‘article’]);

// Build the SQL query to delete the details
$sql_delete = “DELETE FROM articles WHERE f_articleid=:id”;
$sqldelete=$conn->prepare($sql_delete);
$sqldelete->bindParam(“:id”, $f_id);
$result=$sqldelete->execute();

$sql_delete = “DELETE FROM authors WHERE f_articleid=:id”;
$sqldelete=$conn->prepare($sql_delete);
$sqldelete->bindParam(“:id”, $f_id);
$result=$sqldelete->execute();

}

echo ‘

Search Publications

‘;
if(isset($_POST[‘f_search’])) { echo ‘

‘;
if ($ncount==1){echo $ncount. ‘ publications found’;} else if ($ncount > 1){ echo $ncount. ‘publications found’;}
echo ‘

‘; }
echo ‘

‘;
if(isset($_POST[‘f_search’])) {
echo ‘

‘;
foreach($conn->query($article) as $rarticle){

$authors = “SELECT f_authorid, f_author, f_affiliation from authors where authors.f_articleid ='”.$rarticle[‘f_articleid’].”‘”;

echo ‘

‘. $rarticle[‘f_title’].’

    ‘;
    foreach($conn->query($authors) as $a ) {
    echo ‘

  • ‘. $a[‘f_author’] .’
  • ‘;
    }
    echo ‘

‘.

substr($rarticle[‘f_abstract’], 0, 200)

.’

‘;
}

if ($ncount > $results_per_page) {
echo ‘

    ‘;
    for ($i=1; $i<=$total_pages; $i++) { echo '
  • ‘. $i .’
  • ‘;
    }
    echo ‘

‘;
}
echo ‘

‘;
}
[/insert_php]