The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

but what i really want is to be able to do a specific query and get the results back in the form of an associative array, so doing something like

PHP Code:

$temp = $db->query($query)
$user = $db->next_record($temp)

sort of thing where i can then use $user[email] sort of thing. Is this possible?

The other problem i am having is that i do an SQL query which requires a loop through returned results, and sometimes i have to do another sql query inside that loop (to get a specific template - only once it is then stored in a cache) but this mucks up the loop because the query is changed.

For your first problem, remember a while back when I had you adjust the next_record() function in the mysql class? Well thats where this comes into play, first make sure that your next_record() function looks like this:

#Specify to the phplib class to return the next_record
#in the form of an associative array
$db->next_record(MYSQL_ASSOC);

#Assign the current record to the var $user in the form of
#an associative array
$user = $db->Record;

#prints an element form the array
print $user[email];

For you second question, just create two db objects like this

PHP Code:

$db = new DB;
$db2 = new DB;

Then in your loop for the nested query use the $db2 object and use $db2->free() after each nested query. That way your original query will stay in memeory and you can use the $db2 object for nested queries and free it up after each loop of the original query if that makes sense. Let me know if that works for you.

Please don't PM me with questions.
Use the forums, that is what they are here for.

lol, i was just coming back to the forums with that bit you gave me. Just found it and wondered if that was part of the answer (after reading a bit harder through my notes) but thought it a bit weird it is not standard part of phplib.

But yes, solved the problem perfectly. Just tried combining them and this works a tread

PHP Code:

while ($article = $db->row_array()) {

where row_array is what you gave me previously:

PHP Code:

# added by freddydoesphp
/* public: get arrays for each record */
function row_array() {
if (!$this->Query_ID) {
$this->halt("next_record called with no query pending.");
return 0;
}

LOL I had forgotten about the extra function, I think maybe I scrapped that idea once I figured out how to combine this technique into the existing next_record() function. I don't think there is any difference between the two except for the next_record() adjustment makes life a little more modular so to speak, where next_record() becomes a more versatile tool.

Please don't PM me with questions.
Use the forums, that is what they are here for.