Jump to content

Counting MySQL Rows


Recommended Posts

When I do the following:

$query_count = "SELECT COUNT(*) FROM ".TABLE_PREFIX."schedules WHERE aircraft=".$aircraft->id." AND depicao='$location'";
$rowcount = DB::get_row($query_count);
echo $rowcount;

I get the error:

Catchable fatal error: Object of class stdClass could not be converted to string in /Users/Nout/Desktop/ZE Site/core/templates/realschedulelite/realschedulelite_airport_details.tpl on line 56

What I have in place is a table of flights per airport which pilots can then book. Thus I use "foreach" to display a new table-row per flight. That works perfectly for any airport with more than one flight departing it.

For an airport with only one flight departing it, the table is shown but above it theres an ugly error reading:

Warning: Invalid argument supplied for foreach() in /Users/Nout/Desktop/ZE Site/core/templates/realschedulelite/realschedulelite_airport_details.tpl on line 133

So what I want is to count rows and if theres is only one applicable row I remove the foreach and use DB::get_row otherwise the foreach clause is used with DB::get_results.

Cheers,

Nout

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...