Categories > TinyButStrong general >

Strange Problem with ezSQL

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Michaelsen
Date: 2008-11-01
Time: 05:12

Strange Problem with ezSQL


Hello there,

I'm facing a funny situation with ezSQL + TBS, look at this:

[finalTable.rank;onformat=tablePoints;block=tr;comm]

function tablePoints($BlockName,&$CurrRec) {

    global $db;
   
    $xplayers = $db->get_var("SELECT count(match_id) FROM tables WHERE match_id = ". $_GET["match_id"] ."");

    if($CurrRec == 1) { $pts = 10; }
    if($CurrRec == 2) { $pts = 6; }
    if($CurrRec == 3) { $pts = 4; }
    if($CurrRec == 4) { $pts = 3; }
    if($CurrRec == 5) { $pts = 2; }
    if($CurrRec == 6) { $pts = 1; }
   
    $CurrRec = $pts * $xplayers;

    }

As long as I use the ezsql query, even if with get_row or get_results, I have only one row displayed. When I retrieve $xplayers externally and make it global inside the function all rows will be displayed as they should in TBS side.

More strange yet is the single returned row for me when using the get_var is showing correctly as it should.

Regards,

- Michaelsen
By: TomH
Date: 2008-11-01
Time: 12:46

Re: Strange Problem with ezSQL


$db->get_var - by definition only retrieves a single row AFAIK

Add the ezsql
$db->debug();
after the query to be sure you are in fact getting the results you expect
By: Michaelsen
Date: 2008-11-02
Time: 00:24

Re: Strange Problem with ezSQL


Hello TomH,

This is the php side:

$tbsquery = "SELECT * FROM tables
JOIN players ON players.player_id = tables.player_id
WHERE match_id = ". $_GET["match_id"] ." and rank > 0 ORDER BY rank ASC LIMIT 6";
$TBS->MergeBlock('finalTable',$db,$tbsquery);

Then in the html side I will use this function:

function tablePoints($BlockName,&$CurrRec) {

    global $db;
   
    $xplayers = $db->get_var("SELECT count(match_id) FROM tables WHERE match_id = ". $_GET["match_id"] ."");

    if($CurrRec == 1) { $pts = 10; }
    if($CurrRec == 2) { $pts = 6; }
    if($CurrRec == 3) { $pts = 4; }
    if($CurrRec == 4) { $pts = 3; }
    if($CurrRec == 5) { $pts = 2; }
    if($CurrRec == 6) { $pts = 1; }
   
    $CurrRec = $pts * $xplayers;

    }

Without the function I have returned the desired 6 rows.

With the function I just receive one row.

If I specify $xplayers in any way with the except of this internal query in the function, I also have the 6 rows returned.

Regards,

- Michaelsen
By: Michaelsen
Date: 2008-11-02
Time: 13:52

Re: Strange Problem with ezSQL


Good to mention it was working fine until my hosting service changed to php5.

Then I upgraded to tbs 3.4 for php5 and also to ezsql 2.

The error didn`t stop. I resolved the issued bringing the variable I needed from outside the function.

Regards,

- Michaelsen
By: TomH
Date: 2008-11-02
Time: 16:34

Re: Strange Problem with ezSQL


As I said originally -- $db->get_var will only return ONE row - no more

Did you try $db->get_results inside the function or not?
By: TomH
Date: 2008-11-02
Time: 16:38

Re: Strange Problem with ezSQL

Also, the correcrt cdall to the func should be
function tablePoints($BlockName,&$CurrRec,$RecNum) {
By: Michaelsen
Date: 2008-11-02
Time: 23:41

Re: Strange Problem with ezSQL


The function will be called for each row returned. The get_var ins't the query building my block, it is supposed to return one row with the attendance of the game.

I tried with $RecNum also.

Thanks,

- Michaelsen
By: Michaelsen
Date: 2008-11-09
Time: 19:11

Re: Strange Problem with ezSQL


Hello again,

This is odd, if I change for the following:

function tablePoints($BlockName,&$CurrRec) {

$result = mysql_query("SELECT match_id,attendance FROM tables WHERE match_id = ". $_GET["match_id"] ."");
$row = mysql_fetch_assoc($result)

if($CurrRec == 1) { $pts = 10; }
if($CurrRec == 2) { $pts = 6; }
if($CurrRec == 3) { $pts = 4; }
if($CurrRec == 4) { $pts = 3; }
if($CurrRec == 5) { $pts = 2; }
if($CurrRec == 6) { $pts = 1; }

$CurrRec = $pts * $row['attendance'];

}

Then it will work fine.

Regards,

- Michaelsen