News:

Wondering if this will always be free?  See why free is better.

Main Menu

Getting Variables from the Forum? How

Started by blood618^_^, July 25, 2007, 01:24:24 AM

Previous topic - Next topic

Dragooon

Yeah he is right.
SSI came up first and jacked it up :P

blood618^_^

#21
lol I forgot... this really shows that im not good in coding... i forgot that you should initialize first before calling all functions and variables....

(btw? you call the functions by name(); right?)

*will post if found more errors*

::EDIT::

It showed the whole forum... even the templates... (it was suppose to be topics only right??? but not the Home index.php) i was expecting it to out with just the txt and its link

QuoteWarning: Missing argument 2 for db_query(), called in /home/blood618/public_html/testindex.php on line 57 and defined in /home/blood618/public_html/forums/Sources/Subs.php on line 238

Warning: Missing argument 3 for db_query(), called in /home/blood618/public_html/testindex.php on line 57 and defined in /home/blood618/public_html/forums/Sources/Subs.php on line 238

I've seen the WHOLE template... my avatar, logo header which is not suppose to happen... and then in the error box it shows:

QuoteColumn 'ID_BOARD' in where clause is ambiguous
File:
Line:



45 $result = db_query("
46 SELECT
47 m.id_msg, m.subject, m.body, t.id_topic, t.id_board,
48 b.name AS bname,m.id_member,b.memberGroups
49 FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}members AS mem, {$db_prefix}boards AS b
50 WHERE t.id_board = b.id_board
51 AND m.id_msg = t.id_first_msg
52 AND mem.id_member = m.id_member
53 AND b.memberGroups = b.memberGroups
54 AND $user_info[query_see_board]
55 AND ID_BOARD != $modSettings[recycle_board]
56 ORDER BY t.id_topic  DESC
57 LIMIT 5") or die(mysql_error());
58
59 while ($row = mysql_fetch_assoc($result))
60 {      //The variable which decides the MAX letters it can have.
61 $bodylen = 200;
62 // Limit the length of the message, if the option is set.
63 if (strlen(str_replace('<br />', "\n", $row['body'])) > $bodylen)
64 $row['body'] = htmlspecialchars(substr(str_replace('<br />', "\n", un_htmlspecialchars($row['body'])), 0, $bodylen-3) . '...', ENT_QUOTES);
65


Pure Code:
$result = db_query("
SELECT
m.id_msg, m.subject, m.body, t.id_topic, t.id_board,
b.name AS bname,m.id_member,b.memberGroups
FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}members AS mem, {$db_prefix}boards AS b
WHERE t.id_board = b.id_board
AND m.id_msg = t.id_first_msg
AND mem.id_member = m.id_member
AND b.memberGroups = b.memberGroups
AND $user_info[query_see_board]
AND ID_BOARD != $modSettings[recycle_board]
ORDER BY t.id_topic  DESC
LIMIT 5") or die(mysql_error());

while ($row = mysql_fetch_assoc($result))
{      //The variable which decides the MAX letters it can have.
$bodylen = 200;
// Limit the length of the message, if the option is set.
if (strlen(str_replace('<br />', "\n", $row['body'])) > $bodylen)
$row['body'] = htmlspecialchars(substr(str_replace('<br />', "\n", un_htmlspecialchars($row['body'])), 0, $bodylen-3) . '...', ENT_QUOTES);


spottedhog

I believe the reason you "initialize" first is more related to security than anything else.  Take a close look at the coding in the SSI.php file for a ssi function.  You will see many times where a variable is initialized, but the key is, it is initialized as an empty array.

For example: $return = array();

What this does is to ensure the variable $return has nothing in it before it is populated.

Dragooon

Oh replace the db_query with mysql_query
And also after adding require('pathtosmf/Settings.php'); Add mysql_connect($db_server, $db_user, $db_passwd); and then mysql_select_db($db_name); and then rest of the code

blood618^_^

It worked! :D

but this one didnt

global $scripturl, $db_prefix, $context, $smfFunc, $txt, $user_info, $modSettings;
//Main query
$result = mysql_query("
SELECT
m.id_msg, m.subject, m.body, t.id_topic, t.id_board,
b.name AS bname,m.id_member,b.memberGroups
FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}members AS mem, {$db_prefix}boards AS b
WHERE t.id_board = b.id_board
AND m.id_msg = t.id_first_msg
AND mem.id_member = m.id_member
AND b.memberGroups = b.memberGroups
AND $user_info[query_see_board]
AND ID_BOARD != $modSettings[recycle_board]
ORDER BY t.id_topic  DESC
LIMIT 5") or die(mysql_error());

while ($row = mysql_fetch_assoc($result))
{      //The variable which decides the MAX letters it can have.
$bodylen = 20;
// Limit the length of the message, if the option is set.
if (strlen(str_replace('<br />', "\n", $row['body'])) > $bodylen)
$row['body'] = htmlspecialchars(substr(str_replace('<br />', "\n", un_htmlspecialchars($row['body'])), 0, $bodylen-3) . '...', ENT_QUOTES);


censorText($row['body']);
censorText($row['subject']);

$context['rp'][] = array(
'title' => $row['subject'],
'link' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
'description' => $row['body'],
'category' =>  $scripturl .'?board=' .$row['id_board'] . '.0',
'bname' => $row['bname']
);
}
foreach($context['rp'] as $info)
echo'
<dt><br><a href="', $info['link'], '">', $info['title'], '</a></dt>
<dd>', $info['description'], '<br>posted in <a href ="',$info['category'],'">',$info['bname'],'</a></dd>
</dlv>';


This was the mentioned Error...


Column 'ID_BOARD' in where clause is ambiguous


What i've learn from this is that it doesnt know which field we are using... so definitely we have to initialize the t.ID_BOARD's Column... or is it the 'category' =>  $scripturl .'?board=' .$row['id_board']. '.0', that gives the error?

I really wanna know what are the codes used so i can just do it myself... i love coding... but the problem is i really dont have knowledge on this... specially in mysql... anyways again THANKS! the other one worked already...

whats the difference between t.id_board to board?



Dragooon

OK I figured out why.
In $result = mysql_query("
SELECT
m.id_msg, m.subject, m.body, t.id_topic, t.id_board,
b.name AS bname,m.id_member,b.memberGroups
FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}members AS mem, {$db_prefix}boards AS b
WHERE t.id_board = b.id_board
AND m.id_msg = t.id_first_msg
AND mem.id_member = m.id_member
AND b.memberGroups = b.memberGroups
AND $user_info[query_see_board]
AND ID_BOARD != $modSettings[recycle_board]
ORDER BY t.id_topic  DESC
LIMIT 5") or die(mysql_error());


See the last AND statement it is just ID_BOARD it should be b.ID_BOARD so at end it should be $result = mysql_query("
SELECT
m.id_msg, m.subject, m.body, t.id_topic, t.id_board,
b.name AS bname,m.id_member,b.memberGroups
FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}members AS mem, {$db_prefix}boards AS b
WHERE t.id_board = b.id_board
AND m.id_msg = t.id_first_msg
AND mem.id_member = m.id_member
AND b.memberGroups = b.memberGroups
AND $user_info[query_see_board]
AND b.ID_BOARD != $modSettings[recycle_board]
ORDER BY t.id_topic  DESC
LIMIT 5") or die(mysql_error());


The difference between t.id_board and board is that t.id_Board means it is the board ID from topic table where is board is in just general to nothing.

blood618^_^

#26
wow.. ^^,

I think this is the last one...

How can I apply the [b] bbtags [/b]  (bbcodes) in that page?

::EDIT::
ANSWER: parse_bbc('message here');
::EDIT::

this is really cool... im starting to understand some parts in SMF ^^,

::EDIT::

I wanna learn more about the parts of the code...

I mean, by getting variables from database (in the code) by using this code...  (getting authors and getting everything for a topic things like that)...

I was reading the code and it looked the same... in some parts its not... I wish to learn every part of it...

i'll post another regarding my explanation about thw whole code... and please correct me if im wrong...  thanks :D  i just want to test if i understnad the whole code well...

blood618^_^

The Code Explanation based on my understandng...

$result = mysql_query("
SELECT
m.id_msg, m.subject, m.body, t.id_topic, t.id_board,
b.name AS bname, m.id_member
FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}members AS mem, {$db_prefix}boards AS b
WHERE t.id_board = 1
AND b.id_board = 1
AND m.id_msg = t.id_first_msg
AND mem.id_member = m.id_member
ORDER BY t.id_topic DESC
LIMIT 5") or die(mysql_error());


This is a Small part of code in the file... and by this i will explain further...

$result = mysql_query("

This means the result that mysql_query (a Mysql Command) will have will be placed on the $result variable...

SELECT
m.id_msg, m.subject, m.body, t.id_topic, t.id_board,
b.name AS bname, m.id_member


I dont get this part that much... This selects the table id_msg in the database? i really dont get this part specially why it has prefixes like "m." or "t."

FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}members AS mem, {$db_prefix}boards AS b

means from your forum database prefix (eg. smf_) like smf_topics, messages and members are being called starting there... but again i dont know whats the "AS" mem "AS" B ...

although this looks like the prefix of the variables i still dont get it but it does sound like m.id_msg is M as the table name and id_msg is the column...

WHERE t.id_board = 1
AND b.id_board = 1
AND m.id_msg = t.id_first_msg
AND mem.id_member = m.id_member


somewhat like a condition where they initialize the variables... i dont get it why do they have to change the values for "AND m.id_msg = t.id_first_msg ---and--- AND mem.id_member = m.id_member"...

although im guessing... that it wont replace the variables inside the t.id_first_msg and m.id_member ???

ORDER BY t.id_topic DESC

it is being ORDERED  DESCending sort... in t.id_topic... meaning whoever has the highest id number topic  wll be the first one to be released...

NOTE: id_topic is the column for the numbers where latest and last a differentiated....

LIMIT 5") or die(mysql_error());

it is only limited by 5 and if the mysql_query failes all this arguments... it will stop and die... (die sounds like a harsh word but i think its also a command)



Next line of command is

while ($row = mysql_fetch_assoc($result))
{      //The variable which decides the MAX letters it can have.
$bodylen = 200;
// Limit the length of the message, if the option is set.
if (strlen(str_replace('<br />', "\n", $row['body'])) > $bodylen)
$row['body'] = htmlspecialchars(substr(str_replace('<br />', "\n", un_htmlspecialchars($row['body'])), 0, $bodylen-3) . '...', ENT_QUOTES);


okay next explanation:

while ($row = mysql_fetch_array($result))

i dont know what the mysql_fetch_array($result) is but if it equals to $row (which i also dont know how did it argumented since $row was not declared on the file.. and i dont know how would that equaled to mysql_fetch_array...) mysql_fetch_array it will be moved to the next function...

$bodylen = 200;

Maximum characters lenght...

if (strlen(str_replace('<br />', "\n", $row['body'])) > $bodylen)
$row['body'] = htmlspecialchars(substr(str_replace('<br />', "\n", un_htmlspecialchars($row['body'])), 0, $bodylen-3) . '...', ENT_QUOTES);


Honestly i have a little idea... This talks about the string...  but i dont know what it is because  dont know what are those commands and what are they used for....

=======================
Will be continuing on the next post.! :D

spottedhog

You got the arguement2 and arguement3 errors because you did not have the db_query function properly coded.  The db_query function requires this -->  , __FILE__, __LINE__  at the end of the query.  This serves as the mysql_error code by displaying the file and line number of the error, if there is one.

Dragooon

Ok well.
What you tried to explained actually you were more of asking questions :P
So Here is what it actually means.
$result = mysql_query("
SELECT
m.id_msg, m.subject, m.body, t.id_topic, t.id_board,
b.name AS bname, m.id_member
FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}members AS mem, {$db_prefix}boards AS b
WHERE t.id_board = 1
AND b.id_board = 1
AND m.id_msg = t.id_first_msg
AND mem.id_member = m.id_member
ORDER BY t.id_topic DESC
LIMIT 5") or die(mysql_error());


Well You were right the mysql query is stored in $result so it doesent makes a difference to re-explain it.

Next was SELECT
m.id_msg, m.subject, m.body, t.id_topic, t.id_board,
b.name AS bname, m.id_member

It was selecting rows from table. Now in this m.id_message means id_message row from the table where it was m. I used this because of multiple table assigning.

Then comes the FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}members AS mem, {$db_prefix}boards AS b
Here we selected tables from the tables and assigned them to letters. Like messages table became m. So m.id_message meant id_message row from message table.

Then came ... WHERE t.id_board = 1
AND b.id_board = 1
AND m.id_msg = t.id_first_msg
AND mem.id_member = m.id_member


Well as said it decided conditions.

Rest of the code, I'll explain soon.

Advertisement: