Yes I understand that (it is annoying). Why can't I specify a path from the root that would be the same for wherever the script was running. I would have thought that / would be the root of my site (obviously? not)
Maybe the whole premise of what I'm trying to do is wrong and there's a much better way of doing it.
Basically I have a function which is contained in an included file, the function takes an SQL query string and some other parameters and displays the output of the query as a large? table with the specified number of column or column sets (there would be 2 per set if I wanted to display userID, username for each record), one of the columns can be specified as a link which will link to a detail page where all that records details would be displayed.
In order not to have to pass the database query results to the function I do all the database connection and reading inside the function.
The code to connect to the database is contained in another include file which is included by the function
this is why I need to specify a root relative path to the include file. If I can't then I'll have to pass the include file location in a parameter to the function (seems wrong).
OK well I wasn't going to, but here goes, I've included the code for the function so you can see what I'm talking about better.
Function FormatQueryResults($dbSQL, $tblNoCols, $fieldsPerColset, $colHeadings, $linkField, $urlField, $linkPage, $fontSize) {
Function to display a master record page using a variable number of columns (with a varying number of columnsets)
with a link to the detail page.
#
$dbSQL string: SQL query string
$tblNoCols int: number of column sets in table (x by fields per column)
$fieldsPerColset int: number of fields per columnset
$colHeadings array: field headings for each columnset (must be same as table fieldnames)
$linkField int: the number of the field to be wrapped in an <a href> tag to use as a link to the detail page ZERO BASED
$urlField int: the number of the field to use as the URL parameter in the linked field ZERO BASED
$linkPage string: the page to link to ie 'view_morrisons_detail.php'
$fontSize int: relative fontsize (ie -4) for table text
#
#
#
#TEST DATA
$dbSQL="SELECT StoreNo, StoreName FROM SiteDetails where Scheme = 'Myscheme' ORDER BY StoreName ASC";
$tblNoCols=8;
$fieldsPerColset=2;
$colHeadings = array("StoreNo", "StoreName");
$linkField=1; # StoreName
$urlField=0; # StoreNo
$linkPage="view_sites_detail.php";
$fontSize=-4;
#END TEST DATA
if (count($colHeadings) <> $fieldsPerColset) {
$countColHeadings = count($colHeadings);
die("\$fieldsPerColset=$fieldsPerColset and only $countColHeadings headings in \$colHeadings");
}
if ($linkField >= $fieldsPerColset or $urlField >= $fieldsPerColset) {
die("Illegal value for links: \$linkField/\$urlField must be less than fields per column set - \$linkField=$linkField, \$urlField=$urlField, \$fieldsPerColset=$fieldsPerColset");
}
include('../Connections/Directou.php');<-- THIS IS THE BIT I WANT TO MAKE ROOT RELATIVE
mysql_select_db($database_Directou, $Directou);
$query=$dbSQL;
$result = mysql_query($query) or die("Query failed: " . mysql_error());
$totalRows_result = mysql_num_rows($result);
$tblNoRows=intval($totalRows_result / $tblNoCols);
while (($tblNoRows $tblNoCols) < $totalRows_result) {
/
If the number of records is not exactly divisible by the number of
column groups, we need to increase the number of rows so that all the
results fit in the table, this results in some blank cells in the
last column at the end of the table.
*/
$tblNoRows ++;
}
echo "\n<table border=\"1\">\n <tr>\n";
for ($i=0; $i<$tblNoCols; $i++) {# for each columnset
for ($j=0; $j<$fieldsPerColset; $j++) {# output column headings
echo str_repeat(" ",4) . "<td><div align=\"center\"><strong><font size=$fontSize color=\"#000000\">$colHeadings[$j]</font></strong></div></td>\n";
}
}
echo str_repeat(" ",2) . "</tr>\n";
for ($i=0; $i<=$tblNoRows-1; $i++) {# for each row in table
echo str_repeat(" ",2) . "<tr>\n";
for ($j=0; $j<$tblNoCols; $j++) {# for each columnset
if ($i+($j*$tblNoRows) <= ($totalRows_result-1)) {
ie if we've not yet reached the end of the recordset
trying to seek beyond recordset causes a warning if warning are on
so we avoid it...
if (mysql_data_seek($result,($i+($j*$tblNoRows)))) {
$row[$j]=mysql_fetch_array($result);
for ($k=0; $k<$fieldsPerColset; $k++) {#For each field in columnset
if ($row[$j][$colHeadings[$k]] == "") {
$row[$j][$colHeadings[$k]] = "???";
}
}
for ($k=0; $k<$fieldsPerColset; $k++) {
if ($k == $linkField) {# this field is to be used for the link
#echo str_repeat(" ",4) ."<td><font size=$fontSize>" . strtoupper($row[$j][$colHeadings[$k]]) . "</font></td>\n";
echo str_repeat(" ",4) . "<td><font size=$fontSize><a href=" . "\"" . $linkPage . "?" . $colHeadings[$urlField] . "=" . $row[$j][$colHeadings[$urlField]] . "\">" . strtoupper($row[$j][$colHeadings[$linkField]]) . "</a></font></td>\n";
}
else {
echo str_repeat(" ",4) ."<td><font size=$fontSize>" . strtoupper($row[$j][$colHeadings[$k]]) . "</font></td>\n";
}
}
}
}
else {
# mysql_data_seek($result,($i+($j*$tblNoRows))) is trying to seek
# beyond the end of the recordset. This occurs at the end of the last
# column in the table if the number of records in the recordset is not
# exactly divisible by the number of column groups in the table, so
# we need to have blank cells...
for ($k=0; $k<$fieldsPerColset; $k++) {
echo str_repeat(" ",4) . "<td> </td>\n";
}
}
}
echo str_repeat(" ",2) . "</tr>\n";
}
echo "</table>";
mysql_free_result($result);
}
Gary