Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
  #1  
Old 06-06-2013, 02:39 AM
AndrewSimm AndrewSimm is offline
 
Join Date: Sep 2006
Location: Atlanta, GA
Posts: 222
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default select a category by name instead of id

currently I am using the following code to show the news for an entry in vbdynamics. I currently have to enter the category id into a custom field on the entry to get it to work. The title of the entry will be the exact same as the title of the category and I am looking to knock out a stop. Here is my code. I will have to change $entry['field97'] to $entry['title'] The area betweeen the comment is where I need to make the changes, I think.
PHP Code:
ob_start();  

// Set Your Section ID Here 
global $entry
$section1 '242'
$category1 $entry['field97']; 
// Set The Number of Articles To Display 
$limit1 '9'

if(
$category1 == '')  

echo 
"<span style='margin-left:8px;'>There is no news for this recruit</span>"

else 

$articlegrab1 vB::$db->query_read(
SELECT "
.TABLE_PREFIX."cms_nodeinfo.nodeid 
     , "
.TABLE_PREFIX."cms_nodeinfo.title 
     , "
.TABLE_PREFIX."cms_article.previewimage 
     , "
.TABLE_PREFIX."cms_article.previewtext 
     , "
.TABLE_PREFIX."cms_article.pagetext 
     , "
.TABLE_PREFIX."cms_article.contentid 
     , "
.TABLE_PREFIX."cms_node.nodeid 
     , "
.TABLE_PREFIX."cms_node.parentnode 
     , "
.TABLE_PREFIX."cms_node.contentid 
     , "
.TABLE_PREFIX."cms_node.url 
     , "
.TABLE_PREFIX."cms_node.publishdate 
     , "
.TABLE_PREFIX."cms_category.category 
     , "
.TABLE_PREFIX."cms_category.categoryid  
    , "
.TABLE_PREFIX."cms_node.setpublish 
  FROM "
.TABLE_PREFIX."cms_node 
INNER 
  JOIN "
.TABLE_PREFIX."cms_article 
    ON "
.TABLE_PREFIX."cms_article.contentid = ".TABLE_PREFIX."cms_node.contentid 
INNER 
  JOIN "
.TABLE_PREFIX."cms_nodeinfo 
    ON "
.TABLE_PREFIX."cms_nodeinfo.nodeid = ".TABLE_PREFIX."cms_node.nodeid 
INNER 
  JOIN "
.TABLE_PREFIX."cms_nodecategory 
    ON "
.TABLE_PREFIX."cms_nodecategory.nodeid = ".TABLE_PREFIX."cms_node.nodeid 
INNER
// LOOK HERE FOR WHAT I NEED TO CHANGE 
   JOIN "
.TABLE_PREFIX."cms_category 
    ON "
.TABLE_PREFIX."cms_category.categoryid = ".TABLE_PREFIX."cms_nodecategory.categoryid 
 WHERE "
.TABLE_PREFIX."cms_category.categoryid IN ($category1
   AND ("
.TABLE_PREFIX."cms_node.setpublish != 0) 

// I DONT THINK YOU HAVE TO LOOK PAST HERE
ORDER  
    BY "
.TABLE_PREFIX."cms_node.publishdate DESC LIMIT $limit1 
"
); 




while(
$articleinfo1 vB::$db->fetch_array($articlegrab1)) { 

    
$title1 $articleinfo1['title']; 
    
$text1$articleinfo1['previewtext']; 
    
$nodeid1 $articleinfo1['nodeid']; 
    
$url1 $articleinfo1['url']; 
    
$pagetext1 $articleinfo1['pagetext'];   
    
$unixdate1 $articleinfo1['publishdate'];  
    
$date1 date("F j, Y, g:i a"$unixdate1);   
    
$fulltext1 strip_bbcode($fulltext1); 
    
$text1 preg_replace('/\[ATTACH\=CONFIG\]\d\d\[\/ATTACH\]/'''$text); 
    
$text1 strip_bbcode($text1); 
    
$pagetext1 strip_bbcode($pagetext1); 


    if(
$text1 == ''$pagetext1 substr($pagetext10120); 



    
$centerhtml1 .="<div style='padding-bottom:10px;margin-bottom:10px; margin-left:8px; margin-right:8px;border-bottom:1px solid #cccccc''>"
    
$centerhtml1 .="<b><a href='/content.php?".$nodeid1."-".$url1."'>".$title1."</a></b>"
    
$centerhtml1 .="<p><span style='color:#6f6f6f'>".$date1."</span></p>"
    
$centerhtml1 .="<p>".$pagetext1."...</p></div>"

     

vB::$db->free_result($articlegrab1); 
$tabhtml1 "<div><ul>".$tabhtml1."</ul>"
echo 
$tabhtml1.$centerhtml1."</div>"
//  


$recruitnews ob_get_contents();  
ob_end_clean();   
vB_Template::preRegister('ADV_DYNA_SHOWENTRY',array('recruitnews' => $recruitnews)); 
Reply With Quote
  #2  
Old 06-06-2013, 10:09 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If I understand what you want to do, I think you would want to change the "WHERE" line to:
Code:
 WHERE ".TABLE_PREFIX."cms_category.category IN ('$category1')

and since you really should use escape_string on a string in case it contains any special characters, change the line that sets $category 1 to
Code:
$category1 = vB::$db->escape_string($entry['title']);

One other thing, it looks like the original code is written to allow field97 to be a comma separated list of category ids, and with the modified code you can only have one title.
Reply With Quote
Благодарность от:
AndrewSimm
  #3  
Old 06-06-2013, 11:34 PM
AndrewSimm AndrewSimm is offline
 
Join Date: Sep 2006
Location: Atlanta, GA
Posts: 222
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I get
Warning: mysqli_query() [function.mysqli-query]: (42000/1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Yearby) AND (cms_node.setpublish != 0) ORDER BY cms_node.publishda' at line 28 in [path]/includes/class_core.php on line 1391

The title and category are 2 works with a space and I think that is causing the issue.

Thoughts?

--------------- Added [DATE]1370565728[/DATE] at [TIME]1370565728[/TIME] ---------------

oops nevermind it works!

You are the man!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:28 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04119 seconds
  • Memory Usage 2,208KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (3)post_thanks_box
  • (1)post_thanks_box_bit
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete