View Full Version : PHP Direct Evaluation problem
Colossal31
11-28-2015, 06:34 AM
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.
$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
$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
$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
$query = "SELECT team_id, win, loss FROM match_results WHERE season_id=12";
Use this?
$myquery = vB::$db->query_read("SELECT team_id, win, loss FROM match_results WHERE season_id=12");
--------------- Added 1448921015 at 1448921015 ---------------
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:
while($row = mysql_fetch_array($result)){
To:
while($row = vB::$db->fetch_array($result)){
Colossal31
12-02-2015, 12:48 AM
You'll also need to update the condition of the while loop.
From:
while($row = mysql_fetch_array($result)){
To:
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
This code is tested
$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
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.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.