.... a little bit urgent......Dataset empty

Dear all,

On OnValidate event I’ve inserted this code in order to check if there is jet a record for a user:
If I run the select directly on mysql database the answer is correct : i.e. 0 or 1 or better
COUNT(*)
1
Now I have to make a test if the result of select is >0 .
It seems that non result on echo are displayed (like empty).

Am I wronging something or dataset works in different way on a select count ?

// Check for existing record
$check_sql = ‘SELECT COUNT(*) FROM med_therapy_m WHERE med_therapy_m.user_id = {user_id}’;
sc_lookup(dataset, $check_sql);
{check_flag}={dataset}[0][0];
$check_flag = {check_flag};

echo "CHECK_FLAG “. $check_flag .” DATASET ". {dataset};

if ($check_flag > 0) // Error message
{
sc_error_message('Attenzione esiste gi? una scheda aperta per questo nominativo - Warning: An entry with the same user name exists yet ');
}

Thanks so much
Giovannino

Re: … a little bit urgent…Dataset empty

Hello Giovannino.
Try using this code in your Validate event.
// Check for existing record
$check_sql = ‘SELECT COUNT(*) FROM med_therapy_m WHERE med_therapy_m.user_id = {user_id}’;
sc_lookup(dataset, $check_sql);

if (empty({dataset}))
{ // You can insert the data
echo "You can insert the data for = ".{user_id};
} else {
$check_flag = {dataset}[0][0];
echo "CHECK_FLAG “. $check_flag .” DATASET ". {dataset};
sc_error_message('Attenzione esiste gi? una scheda aperta per questo nominativo - Warning: An entry with the same user name exists yet ');
}

Re: … a little bit urgent…Dataset empty

Thanks,

I’ve tried also your hint but the main problem, seems to me, that {dataset} results always empty also if the select count() gives 1 as value.
Do you think that SELECT COUNT(
) can have problems on define the array for dataset ?
If I do the SELECT directly on MYSQL DB the result is correct : COUNT() 0 or COUNT() 1.
Does dataset expect only a field ? I also tried to use COUNT(COL) but nothing changes.
If you like I can attach Application and DB. Let me know.

Re: … a little bit urgent…Dataset empty

Hi.
I used this with my application and it?s right, that works fine for me.
I have a question: the field med_therapy_m.user_id is varchar data type?. Because if this so, then you need change the line with :
$check_sql = "SELECT COUNT(*) FROM med_therapy_m WHERE med_therapy_m.user_id = ‘{user_id}’ ";

Please, try again and let me know.

Regards
JG

Re: … a little bit urgent…Dataset empty

Yes, user_id is an integer.
Did you use it OnValidate ? Is it correct for you ?
Really misterious
Giovannino

Re: … a little bit urgent…Dataset empty

Oh my God,
Umbelivable !!!
" instead of ’
“SELECT COUNT(*) FROM med_therapy_m WHERE med_therapy_m.user_id = {user_id}”;

About two day of headache for one ’ !!

Re: … a little bit urgent…Dataset empty

  • Yes, I used this into a Onvalidate Event, I made this in a form.
  • The test was: I inserted a new row, I wrote a existent ID and a description, when I tried to save using update button the Form shows the message “CHECK_FLAG 1 DATASET Array”. Otherwise, when I wrote a new ID and description, then the Form shows ""You can insert the data for = ID ".
    If you want, you can send me by email your Form and DB backup (Is it a MySql dabatase?).

Re: … a little bit urgent…Dataset empty

Thanks so much !!
But as I mentioned above the only error was ’ instead of ".
Now it works like a charm !
Fix it
Bye … a la prochaine
Giovannino

Re: … a little bit urgent…Dataset empty

I always got into the habit of using:

$check_sql = 'SELECT COUNT(*) FROM med_therapy_m WHERE med_therapy_m.user_id = '.{user_id};

so i did not have to fight the quotes (I like single quotes).

Regards,
Scott.