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 11-28-2015, 06:34 AM
Colossal31 Colossal31 is offline
 
Join Date: Mar 2015
Posts: 31
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default PHP Direct Evaluation problem

I am trying to pull data from my DB and display it as a table in a Forum Side Block. I can not figure out where I am going wrong I have looked at multiple posts on here and Vbulletin.com and none of them seem to help me. When viewing this please keep in mind I am self taught and a novice at this. Here is my code for the side block..... If you see where I screwed up or know a better way to pull this info please let me know.

PHP Code:
$query "SELECT team_id, win, loss FROM match_results WHERE season_id=12"
$result mysql_query($query);

echo 
"<table>"

while(
$row mysql_fetch_array($result)){   
echo 
"<tr><td>" $row['Team'] . "</td><td>" $row['Wins'] . "</td><td>"  .$row['Losses'] . "</td></tr>";
}

echo 
"</table>"
Reply With Quote
  #2  
Old 11-29-2015, 07:41 AM
bridge2heyday's Avatar
bridge2heyday bridge2heyday is offline
 
Join Date: Aug 2014
Location: Egypt
Posts: 141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

you should return value not echo
PHP Code:
$query "SELECT team_id, win, loss FROM match_results WHERE season_id=12";  
$result mysql_query($query); 

$output "<table>";  

while(
$row mysql_fetch_array($result)){    
$output .= "<tr><td>" $row['Team'] . "</td><td>" $row['Wins'] . "</td><td>"  .$row['Losses'] . "</td></tr>"


$output .= "</table>";  
return 
$output
you should also avoid using the depreciated MySQL extension , you can use vBulletin database class.
for example
PHP Code:
$myquery =  vB::$db->query_read("SELECT team_id, win, loss FROM match_results WHERE season_id=12"); 
Reply With Quote
Благодарность от:
Lynne
  #3  
Old 11-30-2015, 07:22 PM
Colossal31 Colossal31 is offline
 
Join Date: Mar 2015
Posts: 31
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

alright just so I am understanding right in place of
PHP Code:
$query "SELECT team_id, win, loss FROM match_results WHERE season_id=12"
Use this?
PHP Code:
$myquery =  vB::$db->query_read("SELECT team_id, win, loss FROM match_results WHERE season_id=12"); 
--------------- Added [DATE]1448921015[/DATE] at [TIME]1448921015[/TIME] ---------------

Ok used the new pieces of code you gave me and I no longer get the string error but the data is not being displayed. Is there something else I am missing?
Reply With Quote
  #4  
Old 12-01-2015, 06:52 PM
squidsk's Avatar
squidsk squidsk is offline
 
Join Date: Nov 2010
Posts: 969
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You'll also need to update the condition of the while loop.

From:
Code:
while($row = mysql_fetch_array($result)){
To:
Code:
while($row = vB::$db->fetch_array($result)){
Reply With Quote
  #5  
Old 12-02-2015, 12:48 AM
Colossal31 Colossal31 is offline
 
Join Date: Mar 2015
Posts: 31
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by squidsk View Post
You'll also need to update the condition of the while loop.

From:
Code:
while($row = mysql_fetch_array($result)){
To:
Code:
while($row = vB::$db->fetch_array($result)){



Tried this and still no display. Still have no idea what I am doing wrong or if a forum block is even capable of displaying this info. Any more assistance is appreciated.
Reply With Quote
  #6  
Old 12-02-2015, 05:26 AM
bridge2heyday's Avatar
bridge2heyday bridge2heyday is offline
 
Join Date: Aug 2014
Location: Egypt
Posts: 141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This code is tested
PHP Code:
$query        "SELECT team_id, win, loss FROM match_results WHERE season_id=12";
$result       vB::$db->query_read($query);
$tableresults '<table style="width:100%"><tr><th><b>Team</b></th><th><b>Wins</b></th><th><b>Losses</b></th></tr>';
while (
$row vB::$db->fetch_array($result)) {
    
$tableresults .= "<tr><td>" $row['team_id'] . "</td><td>" $row['win'] . "</td><td>" $row['loss'] . "</td></tr>";
}
$tableresults .= '</table>';
return 
$tableresults
Attached Images
File Type: jpg blov.jpg (24.3 KB, 0 views)
Reply With Quote
  #7  
Old 12-02-2015, 08:13 PM
Colossal31 Colossal31 is offline
 
Join Date: Mar 2015
Posts: 31
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That does work but their are multiple match results for each team Id is there a way to sum up the wins and losses for each team id? SO that it doesnt come out like below.
Attached Images
File Type: png Screenshot (11).png (36.5 KB, 0 views)
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 09:51 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04264 seconds
  • Memory Usage 2,269KB
  • Queries Executed 14 (?)
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
  • (4)bbcode_code
  • (6)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (1)post_thanks_box_bit
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (2)postbit_attachment
  • (7)postbit_onlinestatus
  • (7)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_postinfo_query
  • fetch_postinfo
  • 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
  • postbit_attachment
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete