"$db->sql_numrows($result)" no longer works. It did in a previous beta (3 and before, since I think I haven't tried 4). When I try and use this for something I'm doing it chucks out an error; "Fatal error: Call to undefined function: sql_numrows() blah blah"
I take it from that error that this particular function has been removed and/or replaced with something else but I don't know what. I'm still just a novice at all this. Many thanks.
"$db->sql_numrows($result)" - no longer works?
Forum rules
Discussion of general topics related to the new release and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
Discussion of general topics related to the new release and its place in the world. Don't discuss new features, report bugs, ask for support, et cetera. Don't use this to spam for other boards or attack those boards!
-
- Registered User
- Posts: 31
- Joined: Sun Sep 18, 2005 5:39 pm
- DoubleJ
- Registered User
- Posts: 105
- Joined: Thu Jan 13, 2005 4:19 pm
- Location: The Netherlands
- Contact:
Re: "$db->sql_numrows($result)" - no longer works?
That function has been removed since not all database types support it.
I have the following workaround, if you are trying to obtain 1 row:
However, as mentioned this only works if you fetch 1 row. If you fetch multiple rows, you'll have to do something differently.
Somewhere in viewtopic.php is a way to do a count rows.
I have the following workaround, if you are trying to obtain 1 row:
Code: Select all
$sql = "SELECT * FROM " .TABLE. " WHERE foo = foo LIMIT 0, 1";
$result = $db->sql_query($sql);
// check if we have fetched an actual row.
if( !count($row_info = $db->sql_fetchrow($result)) )
{
trigger_error('NO_ROW_WAS_FOUND');
}
// now you can continue with $row_info as your fetch
Somewhere in viewtopic.php is a way to do a count rows.
DoubleJ - Blah
-
- Registered User
- Posts: 31
- Joined: Sun Sep 18, 2005 5:39 pm
Re: "$db->sql_numrows($result)" - no longer works?
Yea, I do need to check more than one row as its for a 'top 10 topics' sort of thing I have on the main index. I'll scour through viewtopic then until I see something to what I need in that case. Thanks.
- Handyman
- Registered User
- Posts: 522
- Joined: Thu Feb 03, 2005 5:09 am
- Location: Where no man has gone before!
- Contact:
Re: "$db->sql_numrows($result)" - no longer works?
There are a couple ways to do that... first, phpBB uses the MySQL "count" function which you need 1 extra query for.
You could also do this:
so basically the foreach takes the place of the "while" loop.
I think in my previous tests, If I remember correctly, I was not able to put the result into an array, count it and still run the "while" loop... but the above method works.
You could also do this:
Code: Select all
<?php $sql = "SELECT * FROM " .TABLE. " WHERE foo = foo LIMIT 0, 1";
$result = $db->sql_query($sql);
$rows = $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
$num_rows = count($rows);//here is your result count... do whatever you wish with it.
foreach ($rows as $row)
{
$template->assign_block_vars('whatever', array(
'FOO_ID' => $row['foo_id'],
'FOO_NAME' => $row['name'],
));
}
unset($rows);
I think in my previous tests, If I remember correctly, I was not able to put the result into an array, count it and still run the "while" loop... but the above method works.
Last edited by Handyman on Fri Feb 02, 2007 11:12 pm, edited 1 time in total.
My phpBB3 Mods || My Mod Queue
Search Engine Friendly (SEO) URLs || Profile link on Avatar and/or Username || AJAX Chat
Display Posts Anywhere || CashMod || AJAX Quick Edit || AJAX Quick Reply
Search Engine Friendly (SEO) URLs || Profile link on Avatar and/or Username || AJAX Chat
Display Posts Anywhere || CashMod || AJAX Quick Edit || AJAX Quick Reply
Re: "$db->sql_numrows($result)" - no longer works?
That's wrong code. $db->sql_fetchrow() returns only 1 row per call or false if rows ended. Use $db->sql_fetchrowset() instead.
Formerly known as CyberAlien.
Free phpBB styles | Premium responsive XenForo styles | Iconify - modern open source replacement for glyph fonts
Free phpBB styles | Premium responsive XenForo styles | Iconify - modern open source replacement for glyph fonts
- Handyman
- Registered User
- Posts: 522
- Joined: Thu Feb 03, 2005 5:09 am
- Location: Where no man has gone before!
- Contact:
Re: "$db->sql_numrows($result)" - no longer works?
CyberAlien wrote: That's wrong code. $db->sql_fetchrow() returns only 1 row per call or false if rows ended. Use $db->sql_fetchrowset() instead.
whoops... I meant to put rowset fixed now.
My phpBB3 Mods || My Mod Queue
Search Engine Friendly (SEO) URLs || Profile link on Avatar and/or Username || AJAX Chat
Display Posts Anywhere || CashMod || AJAX Quick Edit || AJAX Quick Reply
Search Engine Friendly (SEO) URLs || Profile link on Avatar and/or Username || AJAX Chat
Display Posts Anywhere || CashMod || AJAX Quick Edit || AJAX Quick Reply
-
- Registered User
- Posts: 31
- Joined: Sun Sep 18, 2005 5:39 pm
Re: "$db->sql_numrows($result)" - no longer works?
Many thanks for the help. That script worked wonders. Plus it's also much more simple now than the way I had it before, which is always a good thing (and I might be able to use that method for something else that I've been doing where as before it wouldn't work).
Thanks again.
Thanks again.