A little help plz ty <(0.o)>

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

A little help plz ty <(0.o)>

Post by John Cartwright »

Code: Select all

<?php
// Setting variables from the table
    while ( $row = mysql_fetch_array($result) ) { 
		$date =      $row["date"]; 
		$outcome =   $row["outcome"]; 
		$league =    $row["league"];
		$map =       $row["map"];
		$opponent =  $row["opponent"];
		$league =    $row["league"];
		
		if ($map == "de_dust2") {
			$dust2 = "false";
			$de_dust2 = $de_dust2 + 1;
		}elseif ($map == "de_aztec") {
			$aztec = "false";
			$de_aztec = $de_aztec + 1;
		}elseif ($map == "de_nuke")  {
			$nuke = "false";
			$de_nuke = $de_nuke   + 1;
		}elseif ($map == "de_train") {
			$train = "false";
			$de_train = $de_train + 1;
		}elseif ($map == "de_cpl_fire") {
			$fire = "false";
			$de_cpl_fire = $de_cpl_fire + 1;
		}elseif ($map == "de_cpl_mill") {	
			$mill = "false";
			$de_cpl_mill = $de_cpl_mill + 1; 
		}elseif ($map == "de_inferno") {
			$inferno = "false";
			$de_inferno = $de_inferno + 1; 
		}elseif ($map == "de_cbble") {
			$cbble = "false";
			$de_cbble = $de_cbble + 1;  
		}elseif ($map == "de_comrade") {
			$comrade = "false";
			$de_comrade = $de_comrade + 1;  
		}else{
			$unknown = $unknown + 1;
		}

if ($dust2!=="false"){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
}elseif ($aztec!=="false"){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
}elseif ($nuke!=="false"){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
}elseif ($train!=="false"){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
}elseif ($fire!=="false"){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
}elseif ($mill!=="false"){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
}elseif ($inferno!=="false"){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
}elseif ($cbble!=="false"){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
}elseif ($comrade!=="false"){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
}

}
?>
I know this could be A LOT simpler but when I'm done writting this script there is no way around it, trust me. My other problem is that currently I cannot get $map go show up once. How it is setup it checks to see what map is being looped in the database... adds 1 to the certain variable.. sets another variable to false .... then later more if statements check to see if its not equal to false.. if it isnt it adds the row....

but the rows are being added anyways.. :S Anywayz ty for help
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

up
mahara
Forum Commoner
Posts: 37
Joined: Wed Nov 13, 2002 1:08 am
Location: Bandung, Jawa Barat, Indonesia

Post by mahara »

How it is setup it checks to see what map is being looped in the database... adds 1 to the certain variable.. sets another variable to false .... then later more if statements check to see if its not equal to false.. if it isnt it adds the row....
I think you need to debug whether the returned db result contains variables you expect to show. You can use 'print_r()' or 'var_dump()' function to debug variables (includes a instance of an object). It can recursively iterate a variable and show its key and value. The difference between the two is that instead returning the value, 'var_dump()' also return the type of the variable's value.

Hope helps.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

They have being outputted properly.. its just $map is only supposed to be shown once. What is happening is they are shown as many times as there is the variable
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

K technically this should work but it still isnt.. a new row is made each time... even if its the same map :S

Notice the If Statements for de_dust2 and de_aztec are the only updates ones at this point because they are the only two maps I'm using right now.

If you want to take a look at this go to
http://www.jcartonline.com/xe/?p=2&r=cal

Code: Select all

<?php
<? include ("mysql.php"); 

if ($r=="cal") {

// Preparing data from the tables   
   $result = @mysql_query("SELECT * FROM records_cal ORDER BY `date` DESC");
   if (!$result) { 
   echo("<p>Error performing query: " . mysql_error() . "</p>"); 
   exit(); 
    } 
	
}elseif ($r=="scrim") {

// Preparing data from the tables   
   $result = @mysql_query("SELECT * FROM records_scrim ORDER BY `date` DESC");
   if (!$result) { 
   echo("<p>Error performing query: " . mysql_error() . "</p>"); 
   exit(); 
    } 

}

?>

		<table width="100%" border="0" cellpadding="0" cellspacing="0">
  			<tr> 
    			<td height="22" background="records_top_bg.jpg"></td>
   				<td height="22" background="records_top_bg.jpg" colspan="4"><font color="#000000" size="2"><font color="#990000" size="2" face="Arial, Helvetica, sans-serif"><strong>.: Some Match Stats</strong></font></td>
  			</tr>
  			<tr> 
    			<td></td>
    			<td><font size="2">Map</font></td>
    			<td><font size="2">Total Matches Played</font></td>
    			<td><font size="2">% to win</font></td>
  			</tr>

<?

		$de_dust2 = 1;
		$de_aztec = 1;
		$de_nuke = 1;
		$de_train = 1;
		$de_cpl_fire = 1;
		$de_cpl_mill = 1; 
		$de_inferno = 1; 
		$de_cbble = 1;  
		$de_comrade = 1;  

// Setting variables from the table
    while ( $row = mysql_fetch_array($result) ) { 
		$date =      $row["date"]; 
		$outcome =   $row["outcome"]; 
		$league =    $row["league"];
		$map =       $row["map"];
		$opponent =  $row["opponent"];
		$league =    $row["league"];

		
if ($map == de_dust2 & $de_dust2==1){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
	 $de_dust2 = $de_dust2 + 1;
}elseif ($map == de_aztec & $de_aztec=="1"){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
	 $de_aztec = $de_aztec + 1;
}elseif ($de_nuke=="1"){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
	 $de_nuke = $de_nuke + 1;
}elseif ($de_train=="1"){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
	 $de_train = $de_train + 1;
}elseif ($de_cpl_fire=="1"){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
	 $de_cpl_fire = $de_cpl_fire + 1;
}elseif ($de_cpl_mill=="1"){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
	 $de_cpl_mill = $de_cpl_mill + 1;
}elseif ($de_inferno=="1"){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
	 $de_inferno = $de_inferno + 1;
}elseif ($de_cbble=="1"){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
	 $de_cbble = $de_cbble + 1;
}elseif ($de_comrade=="1"){
echo "<tr>\n". 
     "<td width="1%"></td>\n".
     "<td width="33%"><font size="2">$map</font></td>\n".
     "<td width="33%"><font size="2">$totalplayed</font></td>\n".
     "<td width="33%"><font size="2">$percent</font></td>\n".
     "</tr>\n";
	$de_comrade = $de_comrade + 1;
}

}
echo "$de_dust2";
?>
dsfdd
</table>
?>
K This is the problem now...

the if statements have been changed to ( at least the first one )

Code: Select all

<?php
if ($map == de_dust2 && $de_dust2==1){
?>


which are working fine..

but it is not properly checking the value that $de_dust2==1 must be 1... no matter what I set the value to before hand.. it still doesnt stop it.

Also I know that the value of $de_dust2 is being outputted correct... problem with my coding maybe?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

This is getting really weird.. I inputting a map that wasn't on the if's so there is no reason it should be outputted.. but it still was :S
dirtyoldgoat
Forum Newbie
Posts: 4
Joined: Fri Feb 06, 2004 4:37 pm

Post by dirtyoldgoat »

CounterStrike rules, what website is this code for?

Sorry for being off the wall and not helping... :D
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

my new clan http://www.jcartonline.com/xe/

Its not up yet I just started building it
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

plz someone throw any ideas you have... i ccant figure it out at all
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

<?php
if ($map == de_dust2 && $de_dust2==1){
?>
Should be == $de_dust2 ?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

You're code is way too confusing.

A few questions so we can fix it up:
a) What's in the db? (how many rows and what are the column names and example values)
b) what do you want to display?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

<?php
      $date =      $row["date"]; 
      $outcome =   $row["outcome"]; 
      $league =    $row["league"]; 
      $map =       $row["map"]; 
      $opponent =  $row["opponent"]; 
      $league =    $row["league"]; 
?>
This is what I'm taking out from my database. This is what the script does: It takes the data from the database and it checks to see which maps ($maps) have been used. If the values of maps are the same in 2 different rows in the $maps column, it would only be shown once and not again the a different table. Before the loop itself that outputs all the values into the table, I set the variables of the maps.

For example:
$de_dust2_a = 1;
$de_aztec_a = 1;
$de_nuke_a = 1;
$de_train_a = 1;
$de_cpl_fire_a = 1;
$de_cpl_mill_a = 1;
$de_inferno_a = 1;
$de_cbble_a = 1;
$de_comrade_a = 1;

Then I have an if statement for each map. It goes as follows:

if $map == de_dust2 && de_dust2_a == 1 then do this:
create row
display the map name
add 1 to the value dust_dust2_a
else etc.etc.

When the loop goes back to the start for the next row and it is the same map, the value of dust2, for example, wont be 1 anymore it would be 2 and would not be accepted in the if statemnt... but i duno why its not working.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I have really redone most of the coding.. but it is still not working... and this is getting really annoiying :( :( :( Heres what I changed it to and theoretically work :|

Code: Select all

<?php
<? include ("mysql.php"); 

if ($r=="cal") { 

// Preparing data from the tables    
   $result = @mysql_query("SELECT * FROM records_cal ORDER BY `date` DESC"); 
   if (!$result) { 
   echo("<p>Error performing query: " . mysql_error() . "</p>"); 
   exit(); 
    } 
    
}elseif ($r=="scrim") { 

// Preparing data from the tables    
   $result = @mysql_query("SELECT * FROM records_scrim ORDER BY `date` DESC"); 
   if (!$result) { 
   echo("<p>Error performing query: " . mysql_error() . "</p>"); 
   exit(); 
    } 

} 

?> 

      <table width="100%" border="0" cellpadding="0" cellspacing="0"> 
           <tr> 
             <td height="22" background="records_top_bg.jpg"></td> 
               <td height="22" background="records_top_bg.jpg" colspan="4"><font color="#000000" size="2"><font color="#990000" size="2" face="Arial, Helvetica, sans-serif"><strong>.: Some Match Stats</strong></font></td> 
           </tr> 
           <tr> 
             <td></td> 
             <td><font size="2">Map</font></td> 
             <td><font size="2">Total Matches Played</font></td> 
             <td><font size="2">% to win</font></td> 
           </tr> 

<? 

$pastmap = ""; // so that the first map always gets outputted. 

// Setting variables from the table 
    while ( $row = mysql_fetch_array($result) ) { 
      $date =      $row["date"]; 
      $outcome =   $row["outcome"]; 
      $league =    $row["league"]; 
      $map =       $row["map"]; 
      $opponent =  $row["opponent"]; 
      $league =    $row["league"]; 

if ($pastmap != $map) { 
    echo "<tr>\n". 
     "<td width="1%"></td>\n". 
     "<td width="33%"><font size="2">$map</font></td>\n". 
     "<td width="33%"><font size="2">$totalplayed</font></td>\n". 
     "<td width="33%"><font size="2">$percent</font></td>\n". 
     "</tr>\n"; 
		}

$pastmap = $map; // set the current map to the past map. 

} 



 
?> 
 
</table> 

?>
User avatar
Michael 01
Forum Commoner
Posts: 87
Joined: Wed Feb 04, 2004 12:26 am

Post by Michael 01 »

This thread is really confusing. 8O

If you are pulling out the data for the maps, to see which one has been played last you can do this quite a bit differently.

If you are pulling out the data for maps to see which one is the most popular, again, there is better ways.

Creating rows is bad idea in this type of code. If you happen to hit a loop by accident because if the number is incremental, there could be huge problems.

Simply put, if you wish to have some sorted tracking of your maps, than try a couple of different alternatives such as adding a variable that inputs into another column called "Total_plays" in which it inserts a incremental (via scirpt, or SQL functino) number every time its played. Than, to display the last played map, or most popular, a simple SQL statement can be made just off of the number in ASC or DESC style.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

K let me clarify this o ne more time GRRR :)

This is a records page for a gaming clan, and this script displays a little stats about the clan. Lets say our database looked like this

map ----------- league ----------- date ----------- opponent
------------------------------------------------------------------
de_dust2--------cal--------2004-01-01------------clan1
de_dust2--------cal--------2004-02-02------------clan1
de_aztec--------cal--------2001-01-01------------clan2
de_aztec--------cal--------2004-01-01------------clan5
de_cbble--------cal--------2004-01-01------------clan6
-------------------------------------------------------------------


Okay Now this is what the script will do it will check what map each row in the database has. Let me take you through it step by step:

1. $pastmap is set to blank
2. Checks if $pastmap is equal to $map ( current map being displayed )
3. If they arnt, then it creates the row
4. $pastmap is set to current map
5. Loop restarts

So in the end each map will only be shown once. That's all I'm asking

Also this is so weird... check at the top of my script its like

if r=cal
----do this query
elseif r=scrim
---do this query

For some reason when r=scrim is loaded instead of cal it works fine :S

http://www.jcartonline.com/xe/?p=2&r=scrim
http://www.jcartonline.com/xe/?p=2&r=cal
Post Reply