TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 447
  • Total: 447

[Block] SMF Gallery Random Picture

Started by Thurnok, December 01, 2006, 09:32:24 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

insanemustang

Hum... seems reasonable.  Maybe someone else can help... if not I will get with you and set you up an account on my website... that is... if you are trustworthy  >:D

Thurnok

The answer is "yes".  However, modification to the underlying code is necessary to pull the information from the database and then act on that.  I've added it to my "to-do's" but it might be awhile before I get back into modifications to my various block codes (due to recent events).  Anyone else is free to take a stab at it however.  It is not a very difficult addition.

Ken.

Good to see you Thurnok, we've been missing you.  :up:
" If everything seems under control, you're not going fast enough." - Mario Andretti
Yesterday When I was Young.

ccbtimewiz

I admit this code is quite useful, I used it to customize my own version of the modification, however... That is not the proper way to execute a mysql query in PHP. The code introduces a memory leak.

You are executing a query, fetching a single row, but you don't free up any of the memory that was used the execute the query. You have the store the result of the query in a variable, then use the mysql_fetch_assoc function. After you are done with the query results you MUST call mysql_free_result on the query result variable.


Thurnok

I think you need to review the code again, or ensure you are looking at the full code.  There is in fact a mysql_free_result for the resource I fetch with my query.  It is near the end of the code.

Perhaps you are looking at someone's small subset of the code when they were asking a question?  I'm not sure what code you were looking at, but you will find the full code in the first post in this thread.

Thurnok

By the way, I didn't mention it, but I might as well for those out there that may not know...

mysql_free_result() is actually NOT required as ccbtimewiz tries to indicate.  All result sets from mysql_query()'s are automatically freed at the php script's execution end.  It is good practice however, to use it (as I ALWAYS do), and also it helps if you are making multiple result sets that are very large, since they all take up memory "during" the script execution.

Talliostro

okay I can't help you with the code, but wanted to say thank you for the block, it works perfect on my site :) :up:

ccbtimewiz

Quote from: Thurnok on June 04, 2008, 11:49:17 PM
I think you need to review the code again, or ensure you are looking at the full code.  There is in fact a mysql_free_result for the resource I fetch with my query.  It is near the end of the code.

Perhaps you are looking at someone's small subset of the code when they were asking a question?  I'm not sure what code you were looking at, but you will find the full code in the first post in this thread.

I'm looking at the code in the first post. ^^'

Quote from: Thurnok on June 05, 2008, 12:04:36 AM
By the way, I didn't mention it, but I might as well for those out there that may not know...

mysql_free_result() is actually NOT required as ccbtimewiz tries to indicate.  All result sets from mysql_query()'s are automatically freed at the php script's execution end.  It is good practice however, to use it (as I ALWAYS do), and also it helps if you are making multiple result sets that are very large, since they all take up memory "during" the script execution.

mysql_free_result($gal_result);

^ You can't call the function on an array. Only reason to why the error log isn't showing this error is because SMF is most likely deallocating the array.

Thurnok

What drugs are you on exactly?
You even put a code snippet of my call to free the resource above.

Snippet of my code from the first post in this thread:

$gal_result = mysql_query($gal_query);

.
.
.

<various other stuff here>

.
.
.

mysql_free_result($gal_result);


$gal_result is NOT an array.  It is a variable of type RESOURCE returned from the mysql_query() function.  I'll direct you to the PHP website's own reference to help you better understand php: http://www.php.net/manual/en/function.mysql-free-result.php

Thurnok

Oh... and there is no error in SMF because, well... there is no error.

This website is proudly hosted on Crocweb Cloud Website Hosting.