Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 12-22-2011, 02:14 AM
HMBeaty's Avatar
HMBeaty HMBeaty is offline
 
Join Date: Sep 2005
Posts: 4,141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Showing data from the database

So, I've spent the last 5 hours rewriting an old modification, making something new out of it, and I am now stuck at a point where I don't know what to do next lol

Basically, I made a random quote database (and it works too (I think)), I just need to find out how to show the quote and the author on the forum side now. This is actually my first time making something this extensive in the AdminCP

Anyway, upon installation, I've made it so it'll add predefined quotes to the database, which looks something like:
Code:
$db->hide_errors();

$db->query_write("CREATE TABLE IF NOT EXISTS `" . TABLE_PREFIX . "usml_quotesdb` (
    `quoteid` int(10) NOT NULL auto_increment,
    `author` varchar(50) NOT NULL,
    `quote` varchar(350) NOT NULL,
    PRIMARY KEY  (`quoteid`)
)");

$db->query_write("INSERT INTO `" . TABLE_PREFIX . "usml_quotesdb` (`quoteid`, `author`, `quote`) VALUES
    (1, 'Author1', 'Quote1'),
    (2, 'Author2', 'Quote2'),
    (3, 'Author3', 'Quote3')
");

$db->show_errors();
Now, back to my original question. How do I display the quotes and the authors? I'm actually going to be showing these randomly (which I can figure out how to do), I just need the help to actually start getting them to display lol

Thanks in advance
Reply With Quote
  #2  
Old 12-22-2011, 02:20 AM
HMBeaty's Avatar
HMBeaty HMBeaty is offline
 
Join Date: Sep 2005
Posts: 4,141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here's the screenshot of what I have so far

Reply With Quote
  #3  
Old 12-22-2011, 02:52 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Are you asking for help displaying these on the forums and are wondering how to put them there?
Reply With Quote
  #4  
Old 12-22-2011, 03:03 AM
HMBeaty's Avatar
HMBeaty HMBeaty is offline
 
Join Date: Sep 2005
Posts: 4,141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
Are you asking for help displaying these on the forums and are wondering how to put them there?
Yes. Not sure exactly where I'm going to put this yet, (probably above the forums in forumhome) but I'd like to show it like this...

If the id = 1, then it shows "Quote 1 - Author 1", if the id = 2, then it shows "Quote 2 - Author 2", etc, etc.
Reply With Quote
  #5  
Old 12-22-2011, 05:01 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So you do the query for the quote..
PHP Code:
$myquote $db->query_first("SELECT quote, author FROM " TABLE_PREFIX "usml_quotesdb WHERE quoteid = '" $somevar "'"); 
Do a query_first and then you can use the variables directly...
PHP Code:
$newTemplate vB_Template::create('quotetemplate);
    $newTemplate->register('
myquote', $myquote);
$newTemplate->render(); 
Now in the quotetemplate, you may use:

HTML Code:
{vb:raw myquote.quote}
{vb:raw myquote.author}

Is that what you were asking?
Reply With Quote
Благодарность от:
HMBeaty
  #6  
Old 12-22-2011, 06:25 PM
HMBeaty's Avatar
HMBeaty HMBeaty is offline
 
Join Date: Sep 2005
Posts: 4,141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think so. I've attached the file to show the contents of what I currently have. Now my question is, if I use:
PHP Code:
$myquote $db->query_first("SELECT quote, author FROM " TABLE_PREFIX "usml_quotesdb WHERE quoteid = '" $somevar "'"); 
is that going to show the quotes one at a time, randomly?

(I'm not too experienced with queries at all . Just trying re-create a different mod to do what I want )

EDIT: oops, forgot to attach the file lol. Anyway, this is going to be located at /admincp/quotesdb.php

PHP Code:
<?php
/*======================================================================*\
|| #################################################################### ||
|| # U.S. Military Life                                                  # ||
|| # Random Quotes 1.0.0                                              # ||
|| # ---------------------------------------------------------------- # ||
|| # Copyright ? U.S. Military Life 2011                              # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------------------------------------------------------- # ||
|| # http://www.USMilitaryLife.com                                      # ||
|| #################################################################### ||
\*======================================================================*/

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### PRE-CACHE TEMPLATES AND DATA ######################
$phrasegroups = array();

$specialtemplates = array();

$globaltemplates = array();

$actiontemplates = array();

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');
require_once(
DIR '/includes/adminfunctions_template.php');

if (empty(
$_REQUEST['do']))
{
    
$_REQUEST['do'] = 'main';
}

if (
$_REQUEST['do'] == 'main')
{
    
print_cp_header("[USML] Random Quotes");

    
print_form_header('quotesdb''manage');
    
print_table_start();
    
print_table_header("Quotes"4);
    
print_cells_row(array("ID""Author""Quote""Action"),1,0,1);

    
$quotes $vbulletin->db->query("SELECT * FROM ".TABLE_PREFIX."usml_quotesdb ORDER BY quoteid ASC");
    while (
$row $vbulletin->db->fetch_array($quotes))
    {
        
$row[quoteid] = htmlspecialchars_uni($row['quoteid']);
        
$row[author] = htmlspecialchars_uni($row['author']);
        
$row[quote] = htmlspecialchars_uni($row['quote']);
        
        
print_cells_row(array("$row[quoteid]","$row[author]","$row[quote]","<a href='?do=editquote&quoteid={$row['quoteid']}'>Edit</a>&nbsp;&nbsp;<a href='?do=quotedel&quoteid={$row['quoteid']}'>Delete</a>"),0,0,1);
    }

    
print_table_footer();
    
    
print_table_footer();
    
print_form_header('quotesdb''newquote');
    
print_table_header("Add a new quote"2);
        
print_input_row("Author"'newqdbauthor');
        
print_textarea_row("Quote"'newqdbquote');
    
print_submit_row("$vbphrase[save]");
    
print_table_footer();
    
    
print_cp_footer();
}

if(
$_POST['do']=="newquote")
{
    
$newauthor $vbulletin->input->clean_GPC('p''newqdbauthor'TYPE_STR);
    
$newauthor =& $db->escape_string($vbulletin->GPC['newqdbauthor']);
    
    
$newquote $vbulletin->input->clean_GPC('p''newqdbquote'TYPE_STR);
    
$newquote =& $db->escape_string($vbulletin->GPC['newqdbquote']);
    
    
$db->query_write("INSERT INTO `" TABLE_PREFIX "usml_quotesdb` VALUES('','".$newauthor."','".$newquote."')");
    
define('CP_REDIRECT''quotesdb.php?do=main');
    
print_stop_message('egr_succces');
}

if (
$_REQUEST['do'] == 'quotedel')
{
    
$quoteid $vbulletin->input->clean_GPC('g''quoteid'TYPE_UINT);

    
$db->query_write("DELETE FROM `" TABLE_PREFIX "usml_quotesdb` WHERE quoteid=$quoteid");
    
define('CP_REDIRECT''quotesdb.php?do=main');
    
print_stop_message('egr_succes');
}

if (
$_REQUEST['do'] == 'editquote')
{
    
$rowid $vbulletin->input->clean_GPC('g''quoteid'TYPE_UINT);
    
$rowid =& $db->escape_string($vbulletin->GPC['quoteid']);    

    
$quotedata $vbulletin->db->query("SELECT * FROM `" TABLE_PREFIX "usml_quotesdb` WHERE quoteid='".$rowid."'");
    
$nu $db->fetch_array($quotedata);

    
$quoteid[data] = htmlspecialchars_uni($nu['quoteid']);
    
$author[data] = htmlspecialchars_uni($nu['author']);
    
$quote[data] = htmlspecialchars_uni($nu['quote']);

    
print_cp_header("Edit Quote");
    
print_table_start();
    
print_form_header('quotesdb''editsave');
    
print_table_header("Edit Quote (id:$quoteid[data])"2);

    echo 
"<input type='hidden' name='quoteid' value='".$quoteid['data']."'>";

    
print_input_row("Author"'newauthor'"$author[data]");
    
print_textarea_row("Quote"'newquote'"$quote[data]");

    
print_submit_row("$vbphrase[save]");

    
print_table_footer();
    
print_cp_footer();

    
define('CP_REDIRECT''quotesdb.php?do=main');
    
print_stop_message('egr_succes');
}

if (
$_REQUEST['do'] == 'editsave')
{
    
$newqdbid $vbulletin->input->clean_GPC('p''quoteid'TYPE_UINT);
    
$newqdbauthor $vbulletin->input->clean_GPC('p''newauthor'TYPE_STR);
    
$newqdbquote $vbulletin->input->clean_GPC('p''newquote'TYPE_STR);

    
$newqdbid =& $db->escape_string($vbulletin->GPC['quoteid']);
    
$newqdbauthor =& $db->escape_string($vbulletin->GPC['newauthor']);
    
$newqdbquote =& $db->escape_string($vbulletin->GPC['newquote']);

    
$db->query_write("UPDATE `" TABLE_PREFIX "usml_quotesdb` SET author='".$newqdbauthor."', quote='".$newqdbquote."' WHERE quoteid='".$newqdbid."'");

    
define('CP_REDIRECT''quotesdb.php?do=main');
    
print_stop_message('egr_succes');
}
?>
Attached Files
File Type: php quotesdb.php (4.9 KB, 1 views)
Reply With Quote
  #7  
Old 12-22-2011, 10:43 PM
HMBeaty's Avatar
HMBeaty HMBeaty is offline
 
Join Date: Sep 2005
Posts: 4,141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think I found something that would work how I need.....
PHP Code:
$myquote $db->query_first("SELECT quote, author FROM `" TABLE_PREFIX "usml_quotesdb` ORDER BY rand() LIMIT 1"); 
Although I'm not sure if
PHP Code:
quoteid 
needs to be in there as well or not...

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

Woohoo! I've got it working (I think)! Now to tidy everything up

One more question....the columns in the admincp (ID, Author, Quote, Action), is it possible to make those a fixed width?
Reply With Quote
  #8  
Old 12-23-2011, 02:46 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The text areas are the size that you define for the <input> area.

Glad you got it working.
Reply With Quote
  #9  
Old 12-23-2011, 02:53 AM
HMBeaty's Avatar
HMBeaty HMBeaty is offline
 
Join Date: Sep 2005
Posts: 4,141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I mean the column width for the columns in the top table. Like, for example, maybe make the ID column 10px wide and the other Action column around 200px wide and I guess the others would expand with what room is left

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

Figured that out as well. Got the code from admincp/block.php

What I did was, above:
PHP Code:
print_table_header("Quotes"4); 
I added:
PHP Code:
print_column_style_code(array('width:50px''''''width:100px')); 
Looks better now
Reply With Quote
Reply


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:10 PM.


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.04536 seconds
  • Memory Usage 2,349KB
  • Queries Executed 12 (?)
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
  • (1)bbcode_code
  • (1)bbcode_html
  • (8)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (1)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (2)postbit_attachment
  • (9)postbit_onlinestatus
  • (9)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
  • postbit_attachment
  • 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