MySQL Select

MySQL Select

paintitblackpaintitblack Posts: 60Questions: 20Answers: 0
edited October 2017 in Editor

Hi,

I want to read out entries which are older than one hour and than update them with an external API request.

To do this I have to read the "old" entries, but I don't know how to get them into the while area.

Can anybody please give me an example or an advice?

Here is my current try:

// DataTables PHP library
include( "../editor/php/DataTables.php" );

$sql = "SELECT * FROM _stocks WHERE lastRequest < DATE_SUB(NOW(), INTERVAL 1 HOUR)";


$result = mysql_query($sql);
#$result = mysqli_query($db, $sql);

while($row = mysql_fetch_array($result)) {
#while($row = mysqli_fetch_assoc($result)){

}
$result = $db->select("_stocks", "*");
$result = $db->sql( 'SELECT * FROM _stocks;' );

echo "<pre>";
         print_r($result);
echo "</pre>";`

Cheer pib

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    I might be wrong, but this doesn't look like an Editor specific question, but rather a generic PHP / MySQL one?

    It looks like you already have the query to get the old entries. $row['id'] (or whatever the primary key is) would get the row id.

    Allan

  • paintitblackpaintitblack Posts: 60Questions: 20Answers: 0

    Hi Allan,

    yes it's more a php question, because I use the editor json function.

    Unfortunatly I got this kind of errors:
    Notice: Constant datatables already defined in C:\Users\XXX\DataTables.php on line 13

    Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\Users\XXX\stocks.php on line 25

    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\Users\XXX\stocks.php on line 28

    Can you kindly give me an example of how to use the DataTables PHP library with a select while?

    Thanks in advance

    paintitblack

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    If you are using Editor, then the best way is to use its PHP libraries which are fully documented and there are plenty of examples.

    If you need to make a PDO or mysqli connection to your database to read the data directly, you would be best reading one of the many tutorials available on the web for it (for example).

    Allan

This discussion has been closed.