0

I am new to arrays, and was thinking they could help me in my racing project. I have two pages, one displaying the data, and the other, currently used as a php include, that contains the array.

I can get the more simple elements of the array working, but I was hoping to have the array store some code to determine the number of winners and qualifers for each filter, along with the profit. THis is the element I'm struggling with.

Array:

<?php
$qualifiers_array[0] = "SELECT * FROM table WHERE trk is not null and WHERE tfr = \'1\'";
$qualifiers_array[1] = "SELECT * FROM table WHERE tfr=\'2\'";
$qualifiers_array[2] = "SELECT * FROM table WHERE tfr=\'3\'";
?>

Results page:

<?php include($_SERVER['DOCUMENT_ROOT'].'/*****/*****/*****/*****.php');?>

<?php 
echo "<table border='1'>";
echo "<tr> <th>Filter Name</th> <th>Profit</th> <th>Winners</th> <th>Qualifiers</th> <th>%age</th></tr>";

echo	"<tr>";
echo	"<td width='20%'>". $name_array[0] . "</td>";
echo 	"<td width='20%'>". $profit_array[0] . "</td>";
echo 	"<td width='20%'>&nbsp;</td>";
echo 	"<td width='20%'>". $qualifiers_array[0] . "</td>";
echo 	"<td width='20%'>&nbsp;</td>";
echo	"</tr>";

echo	"<tr>";
echo 	"<td width='20%'>". $name_array[1] . "</td>";
echo 	"<td width='20%'>". $profit_array[1] . "</td>";
echo 	"<td width='20%'>&nbsp;</td>";
echo 	"<td width='20%'>". $qualifiers_array[1] . "</td>";
echo 	"<td width='20%'>&nbsp;</td>";
echo	"</tr>";

echo	"<tr>";
echo "<td width='20%'>". $name_array[2] . "</td>";
echo "<td width='20%'>". $profit_array[2] . "</td>";
echo "<td width='20%'>&nbsp;</td>";
echo "<td width='20%'>". $qualifiers_array[2] . "</td>";
echo "<td width='20%'>&nbsp;</td>";
echo	"</tr>";
echo "</table>";
?>

The current result is: http://www.equinefocus.co.uk/random/4l56fdfm/menu/levelone.php

Could anyone steer me in the right direction? Any help is greatly appreciated.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Borderline
1

You need to connect to a database (Such as MySQL) then perform the queries in your arrays (You also need to unescape the quotes after the "tfr", it will stop the query from working).
Try something like this:

<?php
//Why do all three of these have the same name
//Is it your intention to reset them three times?
$qualifiers_array[0] = "SELECT * FROM table WHERE trk is not null AND WHERE tfr = '1'";
$qualifiers_array[1] = "SELECT * FROM table WHERE tfr='2'";
$qualifiers_array[2] = "SELECT * FROM table WHERE tfr='3'";
?>
<html>
<head>
<title>Database Results</title>
</head>
<body>
<?php 
include($_SERVER['DOCUMENT_ROOT'].'/*****/*****/*****/*****.php');
mysql_connect("localhost", "INSERT USER HERE", "INSERT PASS HERE");

$result = mysql_query("NAMES QUERY");
if($result)
{
	$i = 0;
	while($arr = mysql_fetch_array($result))
	{
		//Transfer values from table to result array
		//Ex. $values[0][$i] = $arr['column_name'];
		$i++;
	}
}

//Repeat for other queries

?>
<table border='1'>
<tr>
	<th>Filter Name</th>
    <th>Profit</th>
    <th>Winners</th>
    <th>Qualifiers</th>
    <th>%age</th>
</tr>
<?php
for($i=0;$i<count($values[0]);$i++)
{
	echo "<tr>\n"
	echo "	<td width='20%'>". $result[0][$i] . "</td>\n";
	echo "	<td width='20%'>". $result[1][$i] . "</td>\n";
	echo "	<td width='20%'>&nbsp;</td>\n";
	echo "	<td width='20%'>". $result[2][$i] . "</td>\n";
	echo "	<td width='20%'>&nbsp;</td>\n";
	echo "</tr>\n\n";
?>
</table>
</body>
</html>

But there are problems beyond that. Why not PM me and we can get this sorted out. I can help you fix-up, clean-up, and optimize your code!

Votes + Comments
Thank you!
0

Thanks for your help - I do have an include with the connection data on the original page, but didn'add it to my sample above, appreciate this can be misleading. I'll try your other recommendations now - thank you!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.