Jump to content

Reading and formating a MYSQL database


Aravinthan

Recommended Posts

Hi guys,

Ok so I tried this for almsot a week and I give up..

 

I have a MYSQL table that has this structure:

id | team1 | team2 | Team2Acc | players1 | players2 | status | accepted | rejected  |

 

And a exemple of a value:

11 | New Jersey Devils | St.Louis Blues  |Accepter  |Peter%20Delmas, | 1 Phoenix Coyotes 2010,  |En Attente | , Buffalo Sabres, Florida Panthers, Calgary Flames|  | 

 

I have a code that splits that splits each players 1 with a comma and inserts it into a row. The same thign for the players 2 colum. When there is 1 player, it is good, but hwne this more I cant make it work...

 

Here is the code so far:

$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']. "";
$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";

 

And I output the $response in the body tag.

 

Thanks for your help,

Ara

 

Link to comment
https://forums.phpfreaks.com/topic/174346-reading-and-formating-a-mysql-database/
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.