Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
Donovan
Client



Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Tue Nov 21, 2006 9:56 am Reply with quote

In my table I have two divisions. Axis and Allied div_id = 1 and div_id = 2.

I have a script the has a list box that displays all teams from the opposing div_id meaning it displays all teams != to your div_id.

The problem is when I select one of the opposing teams in the list box the only team_id that gets written to the table is the last one.

First I find my current div_id based on my username on the site and if it is listed as a commander.

Code:
//Find the value of the division ID. 

  $nukeusername = $userinfo['username']; 
  $sql = "SELECT div_id FROM " . $prefix . "_eto_divisions
  WHERE (div_commander ='$nukeusername' || div_xo ='$nukeusername')"; 
  $result = $db->sql_query($sql); 
  $mydiv = $db->sql_fetchrow($result);
  $div_id = $mydiv[div_id];


Then I filter the values of the teams I want to display.

Code:
//Filter the values for the list box.

$result = $db->sql_query("SELECT * FROM " . $prefix . "_tc_ladderteams tclt
LEFT JOIN " . $prefix . "_tc_teams tct ON (tclt.team_id = tct.team_id)
LEFT JOIN " . $prefix . "_eto_campaigns ec ON (tclt.ladder_id = ec.cid)
LEFT JOIN " . $prefix . "_tc_ladders tcl ON (tcl.sid = tclt.ladder_id)
WHERE tct.div_id != $div_id
AND tcl.active = 1
AND tct.is_active = 1");


Then I show my list box.

Code:
while ( $row = $db->sql_fetchrow($result) ) {

   $dteam_name = $row["name"];
   $dteam_id = $row["team_id"];
echo "<option value='$dteam_id'>$dteam_name</option>";

}
echo "</select>";// Closing of list box


I may have 8 or 10 teams signed up as Axis but no matter who I choose in the list box the only team_id that gets wriiten is the very last team_id for the Axis. team_id = 153

I'm confused.
 
View user's profile Send private message Visit poster's website ICQ Number
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Thu Nov 23, 2006 10:21 am Reply with quote

It appears the opening <select> is missing. I assume you just aren't showing it Smile

Right after the code in Then I filter the values of the teams I want to display., add this statement to see how many rows are being returned.

echo $db->sql_fetchrow($result);
die();

BTW, this statement $div_id = $mydiv[div_id]; should be $div_id = $mydiv['div_id'];.

In these statements change the " to '. It's more efficient Wink
FROM
$dteam_name = $row["name"];
$dteam_id = $row["team_id"];
TO
$dteam_name = $row['name'];
$dteam_id = $row['team_id'];
 
View user's profile Send private message
Donovan







PostPosted: Thu Nov 23, 2006 11:16 am Reply with quote

Thanks Raven,

Made some changes and here is the whole block of code. Now I only capture dteam_id = 129 no matter what I choose in the list box.


Code:
<?php

echo" <table border=\"0\" width=\"100%\">"
."<tr>"
. "<td width=\"14%\"><p align=\"right\"><b>Enemy Unit: </b></font></td>"
. "<td width=\"16%\"><select name=\"dteam_id\" size=\"1\"><option value=\"\">--- Select Enemy ---</option>";

  //Find the value of the division ID.
  $sql = "SELECT div_id FROM " . $prefix . "_tc_teams WHERE team_id ='$team_id'";
  $result = $db->sql_query($sql);
  $mydiv = $db->sql_fetchrow($result);
  $div_id = $mydiv['div_id'];

  //Filter the values for the list box.
$result = $db->sql_query("SELECT * FROM " . $prefix . "_tc_ladderteams tclt
LEFT JOIN " . $prefix . "_tc_teams tct ON (tclt.team_id = tct.team_id)
LEFT JOIN " . $prefix . "_tc_ladders tcl ON (tcl.sid = tclt.ladder_id)
WHERE tct.div_id != $div_id
AND tcl.active = '1'
AND tct.is_active = '1'");

echo $db->sql_fetchrow($result);
die();

//while ( $row = $db->sql_fetchrow($result) ) {
//   $dteam_name = $row['name'];
//   $dteam_id = $row['team_id'];
//echo "<option value='$dteam_id'>$dteam_name</option>";
//
//}
echo "</select>";// Closing of list box
echo"</tr>"     
."</table>"
."<br>"
."<hr>"
."<input type=\"hidden\" name=\"dteam_id\" value=\"$dteam_id\">"
."<input type=\"hidden\" name=\"team_id\" value=\"$team_id\">"
."<input type=\"hidden\" name=\"tid\" value=\"$tid\">"
."<input type=\"hidden\" name=\"op\" value=\"Attack\">"
."<input type=\"submit\" align=\"center\" name=\"Submit\" value=\"Attack This Unit!\">";
CloseTable();
@include_once("footer.php");
?>
 
Raven







PostPosted: Thu Nov 23, 2006 1:15 pm Reply with quote

So there is only 1 row that is being pulled? If so, then that means your code in //Filter the values for the list box. is not correct.
 
Donovan







PostPosted: Thu Nov 23, 2006 5:36 pm Reply with quote

hmmm.

Code:
//Filter the values for the list box.

$result = $db->sql_query("SELECT * FROM " . $prefix . "_tc_ladderteams tclt
JOIN " . $prefix . "_tc_teams tct ON (tclt.team_id = tct.team_id)
JOIN " . $prefix . "_tc_ladders tcl ON (tcl.sid = tclt.ladder_id)
WHERE tct.div_id != $div_id
AND tcl.active = '1'
AND tct.is_active = '1'");

while ( $row = $db->sql_fetchrow($result) ) {
   $dteam_name = $row['name'];
   $dteam_id = $row['team_id'];
echo "<option value='$dteam_id'>$dteam_name</option>";

}
echo "</select>";// Closing of list box
echo"</tr>"     
."</table>"


Here is the structure of my tables and relevent fields:

tc_teams
team_id
name
div_id
is_active

tc_ladders
sid
active

tc_ladderteams
ladder_id
team_id
name

The reason I am joining them is to get all teams who have joined the ladder that is active. Each team need to be active as well in the teams table.

Then query all teams that don't belong to your div_id meaning they belong to the other div_id.

Would I need to add div_id in the bottom as a hidden field?

Code:
."<input type=\"hidden\" name=\"div_id\" value=\"$div_id\">"
 
Donovan







PostPosted: Thu Nov 23, 2006 7:57 pm Reply with quote

Did some testing and I don't think it is the SELECT statement. I made it as simple as possible and it still only writes team_id 156 to the table no matter what team I select in the list box.

Code:
<?php

echo" <table border=\"0\" width=\"100%\">"
."<tr>"
. "<td width=\"14%\"><p align=\"right\"><b>Enemy Unit: </b></font></td>"
. "<td width=\"16%\"><select name=\"dteam_id\" size=\"1\"><option value=\"\">--- Select Enemy ---</option>";

  //Find the value of the division ID.
  $sql = "SELECT div_id FROM " . $prefix . "_tc_teams WHERE team_id ='$team_id'";
  $result = $db->sql_query($sql);
  $mydiv = $db->sql_fetchrow($result);
  $div_id = $mydiv['div_id'];

//Filter the values for the list box.
$result = $db->sql_query("SELECT team_id, name, div_id FROM " . $prefix . "_tc_teams WHERE div_id != '$div_id'");

while ( $row = $db->sql_fetchrow($result) ) {
   $dteam_name = $row['name'];
   $dteam_id = $row['team_id'];
echo "<option value='$dteam_id'>$dteam_name</option>";

}
echo "</select>";// Closing of list box   


I put in your

Code:
 echo $db->sql_fetchrow($result); 

die();


and do not get any rows displayed.

I f I enter this in the SQL pane in phpmyadmin

SELECT team_id, name, div_id
FROM nuke_tc_teams
WHERE div_id !=1

I get 8 rows returned. My teams div_id is 1 so this shows me the query is correct.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©