PDA

View Full Version : create link to a forum using "title_clean" as tag?


jfk1
05-13-2008, 07:34 AM
hi, i'm new to vbull, new to php.... :(
i am trying to define links to forums using title_clean as the identifier. (i believe this to be the only aplha unique field within table).
can anyone please point me in the right direction...
more info...
what i really want is a link to a forum which coresponds to a specific vbad page. the idea being that the vbad page is the "entry point" for visitor, which then has a link to forum which coresponds to that page. i have created tables in mysql which have identical values for "pageid" and "title_clean".
thanx in advance
jfk

--------------- Added 1210668489 at 1210668489 ---------------

here is an example of what i trying to achieve... tho not correct!... the link must be defined by a variable (to enable multiple entries into db)
$url/forums/forumdisplay.php?f=$foruminfo[title_clean=pageid] ... (title_clean and pageid have identical values in the db) or something like this :confused:

jfk1
05-18-2008, 02:45 PM
i see a lot of views to my post, but no replies :( which probably means i'm not asking the correct question.
here is what i want to do. i have created a list of vb_adv pages. i have created a list of vbul forums. both pages and forums are from the same list. i want to make a link from the "page" to the corresponding "forum" (and vice-versa) using $variable.
i know which data i want to look up, but my problem is that i dont know the syntax.
i would like vbull to look at the page it is currently displaying, using whatever $variable it used to create that page eg. sql_table "adv_pages"- field "title", then take this piece of data and go look in sql_table "forum"- field "title_clean", compare the data and return a match which then displays the relative forum.

i guess i've made this a complicated question again :( .... sorry.

GameWizard
05-19-2008, 12:57 PM
I think the best anyone can offer you is the following:

Use the following conditional in your forumdisplay template:
<if condition="$forumid == X">Your ad here</if>Whereas X is the forum ID where you'd like the content to appear. If you'd like the same ad to appear on a number of boards, then use the following:

<if condition="in_array($forumid, array(X,Y,Z))">Your ad here</if>Where as X Y Z refer to different forum ID's

More conditionals:
http://www.vbulletin.com/forum/showthread.php?t=200894

jfk1
10-22-2008, 11:50 AM
hello again, i'm back! :)
i am sure there are a number of ppl here who can solve this problem for me, if i can just attract their attention for a few mins. i am half way through my second year of vbull license, and still dont have a working forum. this must be a record! :)
i am member of vbulletin (obviously), vbulletin.org, vbadvanced, and vbulletinsetup, and somehow i can't seem to ask the right question.... to get the right answer. i will try a different tack here, again! :)
essentially, i want to "query the sql database". how hard can that be, u might ask? all over the world, vbull scripts must be "querying the database" a million times a second! :) the whole script "survives" on "querying the database". this is precisely why i have opted for vbull, BECAUSE it uses mysql! i am getting a little despondent, at this stage. i should by this time, be an expert in PHP, MYSQL, and any number of programming langs! :)
ok, enough of waffle.
why does this not work?
$get_forumid = $db->query("SELECT forumid FROM " . TABLE_PREFIX . "forum WHERE title LIKE '$getpage'");
where $get_forumid is a new $var that i want to create, $getpage is a preset $var, which i want to submit (compare) to the db, and the result (returned value of $get_forumid) i want to use here:
<a href="http://mysite.com/forums/forumdisplay.php?f="$get_forumid">

Marco van Herwaarden
10-23-2008, 08:26 AM
You probably want to use $db->query_first() instead of $db->query().

also make sure that $getpage is cleaned before using it in the query.

jfk1
10-25-2008, 03:52 PM
You probably want to use $db->query_first() instead of $db->query().

also make sure that $getpage is cleaned before using it in the query.

thanx for reply. i have tried query_first, doesnt appear to make a diference. could u possible give me an example of a "working" query..... or better still suggest a place in the script, where i could drop my query in.... i want to place a link in the navbar. thanx

--------------- Added 1224954048 at 1224954048 ---------------

here is an of what i have tried so far:
here's where i up to.... inserted query here (in vba_cmps_include_top.php)


// Figure out which page to grab
$pagevar = $vba_options['portal_pagevar'];

if (defined('VBA_PAGE'))
{
$getpage = VBA_PAGE;
}
else if(isset($_REQUEST[$pagevar]))
{
$getpage = $_REQUEST[$pagevar];
//jfk
$get_forumid = $db->query("SELECT forumid FROM " . TABLE_PREFIX . "forum WHERE title LIKE '$getpage'");

//end jfk


i figured this is precisely where the page name is set, therefore this is the value i need to submit to the forum table....
then i have inserted this link here (in navbar template)


<!-- nav buttons bar -->
<div class="tborder" style="padding:$stylevar[cellspacing]px; border-top-width:0px">
<table cellpadding="0" cellspacing="0" border="0" width="100%" align="center">
<tr align="center">
<!--######### jfk #############-->
<td class="vbmenu_control"><a href="$vboptions[homeurl]">$vboptions[hometitle]</a></td>
<td class="vbmenu_control"><a href="http://ntra.org.uk/forums/forumdisplay.php?f="$get_forumid">Forum</a></td>


<!--######### end jfk ######### -->


i dont get a "reported error" exactly, however when i look at sourcecode in compiled page i see "<a href="http://ntra.org.uk/forums/forumdisplay.php?f="Resource id #15">

Marco van Herwaarden
10-28-2008, 12:36 PM
$get_forumid = $db->query_first("SELECT forumid FROM " . TABLE_PREFIX . "forum WHERE title LIKE '$getpage'");
This will return an array with the values of the selected data (assuming this will only return a single row!!). In your templates you will need to use $get_forumid[forumid].

jfk1
10-28-2008, 03:31 PM
$get_forumid = $db->query_first("SELECT forumid FROM " . TABLE_PREFIX . "forum WHERE title LIKE '$getpage'");
This will return an array with the values of the selected data (assuming this will only return a single row!!). In your templates you will need to use $get_forumid[forumid].
am i amissing a step somewhere... using $get_forumid[forumid] in the html doesnt show a value. do i need use fetch_array (to interpret db result) even though result will only be a single value... [forumid].... which is an integer.

Marco van Herwaarden
10-29-2008, 08:40 AM
What is the value of $get_forumid after the database call?

jfk1
10-29-2008, 03:54 PM
What is the value of $get_forumid after the database call?
i assume you are asking, what "should" be the value of $get_forumid after the database call, as this exercise is solely intended to ascertain this value (in order that i can use this value in the href). with the present code that i am using i am getting a return value (result) like this... "/forumdisplay.php?f="Resource id #15"> ". the actual value is contained within the "Resource id #15", apparently, and must be "interpreted" in order to use it in php code (or html).
the "real" expected value would be as follows: if i submit (to db) a $pagetitle var which= "Stockport", for example... the query will find a forum which also has a "title" of Stockport, and this would have a "forumid" value of "395". (this is the actual entry in the db)

Marco van Herwaarden
10-30-2008, 08:17 AM
I am not interested in what you expect the value to be, but in the real value. ;) You can use a vardump or echo to list the value.

If you are using query_first then you should not have te message that it is a resource id.

jfk1
10-30-2008, 09:10 AM
I am not interested in what you expect the value to be, but in the real value. ;) You can use a vardump or echo to list the value.

If you are using query_first then you should not have te message that it is a resource id.
well, i finally got a working piece of code! :) (curtesy of PHPbuilder.com). perhaps when u see my code, u will see how simple my question was in the first place. probably my fault, making it appear complicated.

//jfk
$forum_name="$pagetitle";

$query=("SELECT forumid FROM " . TABLE_PREFIX . "forum WHERE title='$forum_name'");
$result=mysql_query($query);
if( mysql_num_rows ($result)) //if it has a match from the database/table
{
$row=mysql_fetch_assoc($result); //lets get that matched row's id, and create a link
$forum_link="<a href=\"/forums/forumdisplay.php?f=".$row["forumid"]."\">$forum_name&nbspForum</a>";
}
//end jfk

i now use the $var "$forum_link" whereever i want the link to appear. this is my hacked version of the code, perhaps u could suggest some tidying that would be more consistent with vbull?

Marco van Herwaarden
10-30-2008, 09:20 AM
Not wrong, but not using teh vB coding standards and functions. Also, unless there is more code, you are not cleaning $forum_name before using it in a query, opening your board to SQL-Injections.

The "correct" ;) vB way to do this:

$forum_name="$pagetitle"; // <-- This need to be cleaned before using it in a query!!!!
$row = $db->query_first("SELECT forumid FROM " . TABLE_PREFIX . "forum WHERE title='$forum_name' LIMIT 1");
$forum_link="<a href=\"/forums/forumdisplay.php?f=".$row["forumid"]."\">$forum_name&nbspForum</a>";

Dismounted
10-30-2008, 09:40 AM
Not really following vB Coding Standards there either, Marco ;).
// "Comments should precede the code they describe, rather than following it."

// "Variables should not be quoted if they do not need to be."
$forum_name = $pagetitle;

// Not necessary to separate into newlines if not long, but it looks better aesthetically.
$row = $db->query_first("
SELECT forumid
FROM " . TABLE_PREFIX . "forum
WHERE title = $forum_name
LIMIT 1
");

// "Strings should be quoted with single quotes if they contain no variables or control characters, otherwise use double quotes."
// "The choice between using string evaluations or string additions is yours to make, depending upon the circumstances."
// "Array keys should be quoted if they are strings or variables, even if you know that the variable evaluates to an integer. Quoting should follow the same rules as defined for string quoting."
$forum_link = '<a href="/forums/forumdisplay.php?f=' . $row['forumid'] . '">' . $forum_name . '&nbspForum</a>';

// This is also OK
$forum_link = "<a href=\"/forums/forumdisplay.php?f=$row[forumid]\">$forum_name&nbspForum</a>";

jfk1
10-30-2008, 10:53 AM
oh! i started a fight! :eek: (just kidding)
it is very nice to have TWO distinguished coders helping me with my little problem! :)
i will study comments re quotes very carefully, as i know from experince how important those little jobbies can be!

--------------- Added 1225368751 at 1225368751 ---------------

with regard to "cleaning" $pagetitle. i am dropping this piece into an existing script, in which $pagetitle is preset... can i not assume that this is var is clean? this will not be introduced as an $input... or from a form etc...

--------------- Added 1225370809 at 1225370809 ---------------

Not really following vB Coding Standards there either, Marco ;).
// "Comments should precede the code they describe, rather than following it."

// "Variables should not be quoted if they do not need to be."
$forum_name = $pagetitle;

// Not necessary to separate into newlines if not long, but it looks better aesthetically.
$row = $db->query_first("
SELECT forumid
FROM " . TABLE_PREFIX . "forum
WHERE title = $forum_name
LIMIT 1
");

// "Strings should be quoted with single quotes if they contain no variables or control characters, otherwise use double quotes."
// "The choice between using string evaluations or string additions is yours to make, depending upon the circumstances."
// "Array keys should be quoted if they are strings or variables, even if you know that the variable evaluates to an integer. Quoting should follow the same rules as defined for string quoting."
$forum_link = '<a href="/forums/forumdisplay.php?f=' . $row['forumid'] . '">' . $forum_name . '&nbspForum</a>';

// This is also OK
$forum_link = "<a href=\"/forums/forumdisplay.php?f=$row[forumid]\">$forum_name&nbspForum</a>";
hmmm... this code produces "database error" without single quotes round $forum_name in the query

--------------- Added 1225371729 at 1225371729 ---------------

could i ask another question please?
this code (immediately above) doesnt have an "if" condition in it, as i previously had.... does this matter? what would happen it the query fails (no match in the db)?

Dismounted
10-31-2008, 05:54 AM
hmmm... this code produces "database error" without single quotes round $forum_name in the query
Overlooked that, sorry :).
could i ask another question please?
this code (immediately above) doesnt have an "if" condition in it, as i previously had.... does this matter? what would happen it the query fails (no match in the db)?
I only corrected Marco's code, but yes, you should check the data exists.
// "Comments should precede the code they describe, rather than following it."

// "Variables should not be quoted if they do not need to be."
$forum_name = $pagetitle;

// Not necessary to separate into newlines if not long, but it looks better aesthetically.
$row = $db->query_first("
SELECT forumid
FROM " . TABLE_PREFIX . "forum
WHERE title = '$forum_name'
LIMIT 1
");

if (!empty($row))
{
// "Strings should be quoted with single quotes if they contain no variables or control characters, otherwise use double quotes."
// "The choice between using string evaluations or string additions is yours to make, depending upon the circumstances."
// "Array keys should be quoted if they are strings or variables, even if you know that the variable evaluates to an integer. Quoting should follow the same rules as defined for string quoting."
$forum_link = '<a href="/forums/forumdisplay.php?f=' . $row['forumid'] . '">' . $forum_name . '&nbspForum</a>';

// This is also OK
$forum_link = "<a href=\"/forums/forumdisplay.php?f=$row[forumid]\">$forum_name&nbspForum</a>";
}

jfk1
10-31-2008, 10:35 AM
thanx for reply (and amendment). could u comment on "cleaning" $pagetitle. am i correct in my assumption?

Marco van Herwaarden
11-06-2008, 12:17 PM
Create Secure Mods (https://vborg.vbsupport.ru/showthread.php?t=154411&highlight=secure)

jfk1
11-07-2008, 07:54 PM
Create Secure Mods (https://vborg.vbsupport.ru/showthread.php?t=154411&highlight=secure)
thanx for reply, and for useful link. i am sure i will need this info in near future :)
regards

--------------- Added 1226095204 at 1226095204 ---------------

while i am here, would u like to comment on the following? this is the reciprocal link back to "page" from the forum
//jfk
$home_pageid = $forumTitle;

$page_link = '<a href="/index.php?pageid=' . $home_pageid . '">' . $home_pageid . '&nbspPage</a>';

//end jfk