Member Avatar for Borderline

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.

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!

commented: Thank you! +2
Member Avatar for Borderline

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.