Hi,
I made a php page that retreives data from a MYSQL table. And it checks if the data contains a number if it does, it puts all in one row. If it doesnt it splits into plenty of rows. But for some reason, it doesnt seem to work.
Here is the code:
Thanks for your help,
I made a php page that retreives data from a MYSQL table. And it checks if the data contains a number if it does, it puts all in one row. If it doesnt it splits into plenty of rows. But for some reason, it doesnt seem to work.
Here is the code:
Code:
<?php
$id = $_GET['id'];
$link = mysql_connect ("localhost", "", "");
mysql_select_db ("liguehs_league", $link);
$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']. "";
$table1 = "
<table>
<thead>
<tr>
<th colspan='7'>$team1</th>
</tr>
<tr>
<th>Nom</th>
<th>Contrat</th>
<th>Salaire</th>
<th>Age</th>
<th>Off</th>
<th>Def</th>
<th>Oa</th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan='7'> </th>
</tr>
</tfoot>
";
$table2 = "
<table>
<thead>
<tr>
<th colspan='7'>$team2</th>
</tr>
<tr>
<th>Nom</th>
<th>Contrat</th>
<th>Salaire</th>
<th>Age</th>
<th>Off</th>
<th>Def</th>
<th>Oa</th>
</tr>
</thead>
<tfoot>
<tr>
<th colspan='7'> </th>
</tr>
</tfoot>";
$count1 = substr_count($players1,",");
$count2 = substr_count($players2,",");
$players1 = rawurldecode($players1);
$players1 = explode(",",$players1);
$players2 = explode(",",$players2);
$x1 = 0;
$x2 = 0;
while($count1 > $x1)
{
echo "<br/>$x1<br/>";
$numberOfNumbersFound1 = preg_match("/[0-9]+/", $players1[$x1]);
echo "$players1[$x1] $numberOfNumbersFound1";
if ($numberOfNumbersFound1 == "0" )
{
$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 = "$body1
<tr><td>$players1[$x1]</td><td>$contrat</td><td>$salary</td><td>$age</td><td>$off</td><td>$def</td><td>$oa</td></tr>";
}
else {
$body1 = "$body1
<tr><td colspan='7'>$players1[$x1]</td></tr>";
}
$x1 ++;
}
while($count2 > $x2)
{
$numberOfNumbersFound2 = preg_match("/[0-9]+/", $players2[$x2]);
if ($numberOfNumbersFound2 == "0" )
{
$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>";
}
else
{
$body2 = "
<tr><td colspan='7'>$players2[$x2]</td></tr>";
}
$x2 ++;
}
$close = "</table>";
$response = "$table1 $body1 $close<br/>$table2 $body2 $close";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/URL]">
<!--
Design by Free CSS Templates
[URL]http://www.freecsstemplates.org[/URL]
Released for free under a Creative Commons Attribution 2.5 License
Name : Professional
Description: A two-column, fixed-width design with dark color scheme background.
Version : 1.0
Released : 20081230
-->
<html xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Détails des échanges</title>
<link rel="stylesheet" type="text/css" media="screen" href="../style.css">
<style>
table{
width: 400px;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="header">
<div id="logo">
<h1><a href="#">LHS</a></h1>
<p>Ligue d'Hockey Simule</p>
</div>
<!-- end #logo -->
<?php include("topmenu.php"); ?>
<!-- end #menu -->
</div>
<!-- end #header -->
<div id="page">
<div id="header-pic"></div>
<div id="content">
<div class="post">
<h1 class="title">Reponse</h1>
<div class="entry">
<Center>
<?php echo"$response"; ?>
</center>
</div>
</div>
</div>
<!-- end #content -->
<div id="sidebar">
<div id="sidebar-bgtop"></div>
<div id="sidebar-content">
<div id="sidebar-bgbtm">
<ul>
<?php include("search.php"); ?>
<?php include("sidet_menu.php"); ?>
<?php include("sideb_menu.php"); ?>
</ul>
</div>
</div>
</div>
<!-- end #sidebar -->
<div style="clear:both; margin:0;"></div>
</div>
<!-- end #page -->
</div>
<div id="footer">
<p>© 2008. All Rights Reserved. Design by <a href="[URL]http://www.freecsstemplates.org/">Free[/URL] CSS Templates</a>. Coded and Maintained by <A href="[URL]http://aravinthan.x10hosting.com">Aravinthan</a[/URL]>. </p>
</div>
<!-- end #footer -->
</body>
</html>
Thanks for your help,