0

Hi every one,

I am using this funtion

function get_last_inserted_id($table) {
    include "dbsetting/adm_vars_config.php";
    include "dbsetting/classdbconection.php";
    $dbacosis = new dbacosis();
    $sqlacosis  = $dbacosis->queryacosis("SELECT LAST_INSERT_ID() AS `last_id` FROM `pcosis_courses`;");
        if(!$sqlacosis or   mysql_num_rows($sqlacosis) == 0) {
            return false;
        } else  {
            $data = mysql_fetch_array($sqlacosis);
            return $data['last_id'];
        }
}

$id = get_last_inserted_id("courses");
echo $id;

but it reture zero. anybody have idea.

Edited by rahia307

3
Contributors
3
Replies
18
Views
3 Years
Discussion Span
Last Post by diafol
0
$data = mysql_fetch_array($sqlacosis);
return $data['last_id'];

When you say 'zero' do you mean 'false' (first conditional branch result) or do you mean $data['last_id'] = 0 ?

Also the code above - are you certain that you're getting a mysql resource? Not sure about you mixing a db object and free range procedural...

Aren't they...

$sqlacosis->num_rows

and

$data = $sqlacosis->fetch_assoc()

Or something similar?

1

ALternatively, you could, on an autoincrement PK, just select the last item by

... ORDER BY pkeyfield DESC LIMIT 1
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.