vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   PHP Direct Evaluation problem (https://vborg.vbsupport.ru/showthread.php?t=320915)

Colossal31 11-28-2015 06:34 AM

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>"


bridge2heyday 11-29-2015 07:41 AM

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"); 


Colossal31 11-30-2015 07:22 PM

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?

squidsk 12-01-2015 06:52 PM

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)){

Colossal31 12-02-2015 12:48 AM

Quote:

Originally Posted by squidsk (Post 2559569)
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.

bridge2heyday 12-02-2015 05:26 AM

1 Attachment(s)
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


Colossal31 12-02-2015 08:13 PM

1 Attachment(s)
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.


All times are GMT. The time now is 11:30 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.01439 seconds
  • Memory Usage 1,748KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (6)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete