Jump to content

Why doesnt this work?


Aravinthan

Recommended Posts

Hi,

 

I am making a code that checks if an array has a number inside. If so it outputs it in a single td, if not it searches the players value and inserts it in 7 different td's, but it doesnt work.

 

count1 = substr_count($players1,",");
$count2 = substr_count($players2,",");

$players1 = rawurldecode($players1);

$players1 = explode(",",$players1);
$players2 = explode(",",$players2);

$numberOfNumbersFound = preg_match("/[0-9]+/", $players1[0]);


$x1 = 0;
$x2 = 0;

while($count1 > $x1)
{

$numberOfNumbersFound1 = preg_match("/[0-9]+/", $players1[$x1]);
echo "$players1[$x1] $numberOfNumbersFound1";
if ($numberOfNumbersFound1 > "0" )
{
$body1 = "
<tr><td colspan='7'>$players1[$x1]</td></tr>";
}
else {
				$get_stats = mysql_query("SELECT * FROM `players`  WHERE `name` = '$players1[$x1]'",$link);
				$run_stats = mysql_fetch_array($get_stats) or die(mysql_error());
				$off = "" .$run_stats['off']. "";
				$def = "" .$run_stats['def']. "";
				$oa = "" .$run_stats['oa']. "";
				$age = "" .$run_stats['age']. "";
				$salary = "" .$run_stats['salary']. "";
				$contract = "" .$run_stats['contract_lenght']. "";

$body1 = "
<tr><td>$player</td><td>$contract</td><td>$salary</td><td>$age</td><td>$off</td><td>$def</td><td>$oa</td></tr>";
}
$x1 ++;
}

 

Thanks for your help,

Ara

Link to comment
https://forums.phpfreaks.com/topic/174120-why-doesnt-this-work/
Share on other sites

Sure:

$id = $_GET['id'];

				$get_trade = mysql_query("SELECT * FROM `trade`  WHERE `id` = '$id'",$link);
				$run_trade = mysql_fetch_array($get_trade) or die(mysql_error());
				$team1 = "" .$run_trade['team1']. "";
				$team2 = "" .$run_trade['team2']. "";
				$players1 = "" .$run_trade['players1']. "";
				$players2 = "" .$run_trade['players2']. "";

Link to comment
https://forums.phpfreaks.com/topic/174120-why-doesnt-this-work/#findComment-917815
Share on other sites

You do realize that the first line of the original code you posted was:

count1 = substr_count($players1,",");

AND NOT

$count1 = substr_count($players1,",");

(notice the '$')

 

Was that a posting mistake or could that be one of the issues?

Link to comment
https://forums.phpfreaks.com/topic/174120-why-doesnt-this-work/#findComment-917830
Share on other sites

No, I just copied skipped the $...

 

The thing is this is the output of:

echo "$players1[$x1] $numberOfNumbersFound1";

 

Milan Michalek 0 5 Los Angels Kings 2010 1 Jordan Foote 0

 

It outputs correctly the 3 datas in the string, but it stops there.

 

the reste of the code:

while($count2 > $x2)
{

$numberOfNumbersFound2 = preg_match("/[0-9]+/", $players2[$x2]);
echo "$players2[$x2] $numberOfNumbersFound2";
if ($numberOfNumbersFound2 > 0 )
{
$body1 = "
<tr><td colspan='7'>$players2[$x2]</td></tr>";
}
else
{
				$get_stats = mysql_query("SELECT * FROM `players`  WHERE `name` = '$players2[$x2]'",$link);
				$run_stats = mysql_fetch_array($get_stats) or die(mysql_error());
				$off = "" .$run_stats['off']. "";
				$def = "" .$run_stats['def']. "";
				$oa = "" .$run_stats['oa']. "";
				$age = "" .$run_stats['age']. "";
				$salary = "" .$run_stats['salary']. "";
				$contract = "" .$run_stats['contract_lenght']. "";

$body2 = "
<tr><td>$player</td><td>$contract</td><td>$salary</td><td>$age</td><td>$off</td><td>$def</td><td>$oa</td></tr>";
}
$x2 ++;
}
$close = "</table>";
$response = "$table1 $body1 $close<br/>$table2 $body2 $close";

Link to comment
https://forums.phpfreaks.com/topic/174120-why-doesnt-this-work/#findComment-917834
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.