Aravinthan Posted September 13, 2009 Share Posted September 13, 2009 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 More sharing options...
phporcaffeine Posted September 13, 2009 Share Posted September 13, 2009 Can you dump what the contents of $players1 and $players2 when they are presented to this portion of the code? Link to comment https://forums.phpfreaks.com/topic/174120-why-doesnt-this-work/#findComment-917814 Share on other sites More sharing options...
Aravinthan Posted September 13, 2009 Author Share Posted September 13, 2009 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 More sharing options...
phporcaffeine Posted September 13, 2009 Share Posted September 13, 2009 No do something like var_dump($players1); so we can see the actual value of the var Link to comment https://forums.phpfreaks.com/topic/174120-why-doesnt-this-work/#findComment-917819 Share on other sites More sharing options...
Aravinthan Posted September 13, 2009 Author Share Posted September 13, 2009 string(62) "Milan%20Michalek, 5 Los Angels Kings 2010, Jordan%20Foote, " Link to comment https://forums.phpfreaks.com/topic/174120-why-doesnt-this-work/#findComment-917821 Share on other sites More sharing options...
phporcaffeine Posted September 13, 2009 Share Posted September 13, 2009 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 More sharing options...
Aravinthan Posted September 13, 2009 Author Share Posted September 13, 2009 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 More sharing options...
Aravinthan Posted September 14, 2009 Author Share Posted September 14, 2009 UP Link to comment https://forums.phpfreaks.com/topic/174120-why-doesnt-this-work/#findComment-918609 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.