0

I have a table called volume_issue that looks like this:

 +----+-------------------------------------------------------+-----------------+-----------+---------------------+
| id | url                                                   | journal_title   | issn      | volume_issue        |
+----+-------------------------------------------------------+-----------------+-----------+---------------------+
|  1 | https://www.ajol.info/index.php/asan/issue/view/17048 | Africa Sanguine | 1560-8646 | Vol 19, No 2 (2018) |
|  2 | https://www.ajol.info/index.php/asan/issue/view/16693 | Africa Sanguine | 1560-8646 | Vol 19, No 1 (2017) |
+----+-------------------------------------------------------+-----------------+-----------+---------------------+

I am trying to extract all records associated with the urls listed in the variable url and insert them in a table known as citations. The code i am using to do this lookw like this:

<?php
$query1 = "SELECT * FROM volume_issue where id between 1 and 2";
$sql = $con->prepare($query1);
$sql->execute();
$sql->SetFetchMode(PDO::FETCH_ASSOC);
while ($row = $sql->fetch()) {
    $volume_issue_id = $row['id'];
    $url = $row['url'];
    $volume_issue = $row['volume_issue'];
    $journal_title = $row['journal_title'];
    $html2 = file_get_html($url);
    $html2 = file_get_html($url);

    foreach ($html2->find('table[class="tocArticle"]') as $div2) {
        $DOM = new DOMDocument();
        $DOM->loadHTML($div2);
        $Detail = $DOM->getElementsByTagName('td');

        $i = 0;
        $j = 0;
        foreach ($Detail as $sNodeDetail) {
            $aDataTableDetailHTML[$j][] = trim($sNodeDetail->textContent);
            $j = $i % count($aDataTableDetailHTML[$j]) == 0 ? $j + 1 : $j;
        }
    }
}

$result = [];
foreach ($aDataTableDetailHTML as $key => $value) {
    foreach ($value as $key1 => $value1) {
        echo '<pre>';
        $result[$key1][] = $value1;
    }
}
array_walk($result, function(&$item) {
    $item = implode('|', $item);
});

foreach ($result as $ref) {
    $newref[] = explode('|', $ref);
}

print_r($newref);

foreach ($newref as $key => $values) {
    $title = $values[0];

    $authors = str_replace(',            ',', ',$values[2]);

    $pages = $values[3];
    $doi = $values[4];
    $query2 = "INSERT INTO citations (title,authors,journal_title,volume_issue,pages,doi) VALUES (:title,:authors,:journal_title,:volume_issue,:pages,:doi)";
    $sql2 = $con->prepare($query2);
    $sql2->execute(array(
        ':title' => $title,
        ':authors' => $authors,
        ':journal_title' => $journal_title,
        ':volume_issue' => $volume_issue,
        ':pages' => $pages,
        ':doi' => $doi,
    ));
}

My problem is that this code is mot inserting journal title and volume_issue correctly as desired. How can i make this code insert the right volume issue for the right citation? I am on my wits end.

2
Contributors
3
Replies
38
Views
5 Days
Discussion Span
Last Post by Gurjit_2
0

How i wish Daniweb had an editing tool to allow editing of questions.

What if i turned line 7 , 9 and 10 into arrays and combined them to form a multidimensional arary? e.g.,

    $volume_issue_id[] = $row['id'];
    $volume_issue[] = $row['volume_issue'];
    $journal_title[] = $row['journal_title'];

    $citations = array($volume_issue_id,$volume_issue,journal_title);

This creates a multidimensional array named citations that looks like this:

Array
(
    [0] => Array
        (
            [0] => 1
            [1] => 2
        )

    [1] => Array`Inline Code Example Here`
        (
            [0] => Vol 19, No 2 (2018)
            [1] => Vol 19, No 1 (2017)
        )

    [2] => Array
        (
            [0] => Africa Sanguine
            [1] => Africa Sanguine
        )

    [3] => Array
        (
            [0] => https://www.ajol.info/index.php/asan/issue/view/17048
            [1] => https://www.ajol.info/index.php/asan/issue/view/16693
        )

)

How do i combine this array with the array $newrefs so that i get citations for each volume issue?

On the other hand,does the problem lie with the mysql query above, because if i run the code manually for id 1 and later for id 2the citations are inserted as desired with corresponding volume_issuesunlike when i run the mysql query for both rows..

Any comments and/or ideas are highly appreciated

Edited by Gurjit_2: edited with an aim of making the question more clear

2

I can't help with the question, but can let you know there's an edit window of 30 minutes where you can change your post. After that, if it's something material to the question that can't be dealt with in a comment then you can always PM one of the admins or mods and we'll edit for you if deemed necessary. Hope that helps a bit for future endeavours.

0

Still stuck here. Desperate for suggestions not necessarily answers

Edited by Gurjit_2

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.