Recent Topics

1 Dec 08, 2008 11:02    

My b2evolution Version: 2.x

Hello.

Is there an existing routine to list selected columns and rows from the _blogs table?

Thanks in advance.

2 Dec 08, 2008 13:23

It kinda depends what you're after doing, but the results class ( /inc/_core/ui/results/_results.class.php ) can usually handle it

¥

3 Dec 08, 2008 19:55

Thanks ¥åßßå.

I have it working to provide a count as well as fix the error messages of 'Undefined index: th...' , but now I'm at the point of wanting to list the line items of at least blog_ID and blog_shortname for the purpose of capturing it into an array for later use.

Thanks.

4 Dec 08, 2008 22:28

zooooooooooooom, ok, lets approach this from a different angle ... how about you tell me what you're trying to do and I'll attempt to sound like a genius by answering the real problem?

¥

5 Dec 08, 2008 22:47

Thanks for your reply, ¥åßßå.

I'd like to create e.g. an 'in_array' routine from a DB query that contains various data from e.g. the T_blogs or other tables. Once I have the general routine syntax via $Results object or otherwise that provides e.g. the associative array, I'd be able to substitute any table and criteria to gather the data I need at the time now or in the future.

As a first step, I'd like to take something simple as listing the various blogs and any other properties of that table using e.g. $Results and/or $DB object. I've just begun looking into this.

I could do it via PHP mysql_fetch_array(), mysql_fetch_row(), etc., but I'm trying to stick with pre-established b2evo routines. I'm still in the process of learning this software. :-/

Thanks.

6 Dec 08, 2008 23:21

ok, this sounds like you're trying not to recreate the $DB object

... lets hope this is a moment of genius ;) ...

it pretty much works just like normal mysql

global $DB;
$sql = 'SELECT prefix_field FROM T_[ gets interpreted as evoprefix_]_table WHERE prefix_another_field='.
    $DB->quote( $value /* $value will be mysql_real_escape_string()'d as well as quoted */ );
if( $results = $DB->get_results( $sql ) )
{//
  foreach( loop )
  {
    // stuff required in_array() values into an array ;)
  }
}
?>

If that wasn't a moment of genius then the chances are that you'll need to wait for my genii ...geniuses ... whatever the plural is .. you'll have to wait until they regenerate ... so lets hope it was :D

¥

7 Dec 09, 2008 00:28

Thanks for your reply, ¥åßßå.

I was on the right track and retrieved the correct number of records in the table, but yours is a bit cleaner.

Using your code, I have via an external (new) file:

require_once dirname(__FILE__).'/../_core/model/db/_db.class.php';

global $DB;

$sql = 'SELECT blog_ID FROM T_blogs WHERE blog_owner_user_ID=3';
//    $DB->quote( $value /* $value will be mysql_real_escape_string()'d as well as quoted */ );

if( $results = $DB->get_results( $sql ) )
{
etc...

There are 2 records with blog_owner_user_ID=3.

Q: In the foreach, I got the following error message:

Catchable fatal error: Object of class stdClass could not be converted to string in /usr/...

Upon using the 'print_r()' function, it shows the following results:

Array ( [0] => stdClass Object ( [blog_ID] => 5 ) [1] => stdClass Object ( [blog_ID] => 6 ) )

I'm not sure what this error means, yet; it's finding the correct blogs though.

Do you see what's the problem? :?:

Thanks again.

8 Dec 09, 2008 00:45

Oops - I forgot one more note ¥åßßå:

I'm not sure if its geniuses or genii nor do I know in the case of the plural of the mattress, SHOULD it really be mattresses or mattresi? It seems to work for octopuss (octopi). (Feel free to check this spelling - I haven't...)

...and yes, you are at least a [singular] genius :)

9 Dec 09, 2008 11:21

I'm assuming that your foreach looks something like

foreach( $results as $row )
{
  $foo = $row['blog_ID'];
}
?>

You can actually get the results returned as a conventional array like that, but the DB class defaults to returning them as an object ;)

foreach( $results as $row )
{
  $foo = $row->blog_ID;
}

¥

10 Dec 09, 2008 12:01

COOL BEANS!

It was the need to use the object version instead of the conventional version.

You're a 'genii'! ;)

Thanks!


Form is loading...