Page 1 of 1

newbie trying to put it all together.

Posted: Sat Apr 17, 2004 11:39 am
by bufhal
Hello;
This may be rather lengthy and I apologize, but I will post only relevant code in hopes someone can help me.
I am updating a website with three dropdown menus for a user to search City, Agency and Date. The data.dat file holds the information to be queried. A typical row contains these 11 items:
City Date Day Time Agencyname Location Building/room Street Zip Phone# contactperson

This is the code:

<FORM action=results.php name=form>
<?

$content_array = file('data.dat');
$Total_records = count($content_array);

For ($RecCount = 0; $RecCount < $Total_records; $RecCount++)
{
$elements = explode("<|>", $content_array[$RecCount]);
$dates[$RecCount]=$elements[6];
$cities[$RecCount]=$elements[3];
$agencies[$RecCount]=$elements[5];
}
$Udates=array_values(array_unique ($dates));
$Ucities=array_values(array_unique ($cities));
$Uagencies=array_values(array_unique ($agencies));
$Dcount=count($Udates);
$Ccount=count($Ucities);
$Acount=count($Uagencies);

print '<select name=date onChange="form.submit();">';
print "<option value=null><i>Select a Date</i></option>";
for ($i=0; $i<$Ccount; $i++)
print "<option value=$Udates[$i]>$Udates[$i]</option>";
print "</select>";

print '<select name=city onChange="form.submit();">';
print "<option value=null><i>Select a City</i></option>";
for ($i=0; $i<$Ccount; $i++)
{ print "<option value=";
print '"';
print "$Ucities[$i]";
print '"';
print ">$Ucities[$i]</option>";
}
print "</select>";

print '<select name=agency onChange="form.submit();">';
print "<option value=null selected><i>Select an Agency</i></option>";
for ($i=0; $i<$Zcount; $i++)
print "<option value=$Uagencies[$i]>$Uagencies[$i]</option>";
print "</select></form>";

print "<BR><BR><BR><table><tr><td colspan=7>There are actually $Total_records Events</td></tr>";
For ($RecCount = 0; $RecCount < $Total_records; $RecCount++)
{
$elements = explode("<|>", $content_array[$RecCount]);
print "<tr><td>$elements[0]</td><td>$elements[1]</td><td>$elements[2]</td><td>$elements[3]</td><td>$elements[4]</td>
<td>$elements[5]</td><td>$elements[6]</td><td>$elements[7]</td></tr>";
}

?>
</table>

Here is results.php:

<?PHP
error_reporting(E_ALL ^ E_NOTICE);


if ($date!=="null")
Fdate($date);
if ($city!=="null")
Fcity($city);
if ($agency!=="null")
Fagency($agency);
if ($viewAll!=="0")
Fall();


function Fdate ($date)
{
$content_array = file('data.dat');
$Total_records = count($content_array);

Print " These are results for <b>$date<br><br></b>";
For ($RecCount = 0; $RecCount < $Total_records; $RecCount++)
{
$elements = explode("<|>", $content_array[$RecCount]);
if ($elements[6] == $date)
print "<b>$elements[1]</b><br>$elements[2]<br>$elements[3],$elements[4] $elements[5]<br><b>$elements[6] - $elements[7]</b><br><br>";
}

}

function Fagency ($agency)
{
$content_array = file('data.dat');
$Total_records = count($content_array);

Print " These are results for <b>$agency<br><br></b>";
For ($RecCount = 0; $RecCount < $Total_records; $RecCount++)
{
$elements = explode("<|>", $content_array[$RecCount]);
if ($elements[5] == $agency)
print "<b>$elements[1]</b><br>$elements[2]<br>$elements[3],$elements[4] $elements[5]<br><b>$elements[6] - $elements[7]</b><br><br>";

}

}

function Fcity ($city)
{
$content_array = file('data.dat');
$Total_records = count($content_array);

Print " These are results for <b>$city<br><br></b>";
For ($RecCount = 0; $RecCount < $Total_records; $RecCount++)
{
$elements = explode("<|>", $content_array[$RecCount]);
if ($elements[3] == $city)
print "<b>$elements[1]</b><br>$elements[2]<br>$elements[3],$elements[4]
$elements[5]<br><b>$elements[6] - $elements[7]</b><br><br>";
}


}
function Fall ()
{
$content_array = file('data.dat');
$Total_records = count($content_array);

Print " These are all the results <br><br>";
For ($RecCount = 0; $RecCount < $Total_records; $RecCount++)
{
$elements = explode("<|>", $content_array[$RecCount]);
print "$elements[1]-$elements[2]-$elements[3]<br>";
}
}


?>
I want every query a user chooses to pull all 11 items from data.dat.
If anyone can take a look at the code and see why I am not getting all 11 items returned, I would appreciate it. Sorry for the long post-I will post a link to the site if need be...
Bufhal

Posted: Sat Apr 17, 2004 12:20 pm
by feyd
Do you have register_globals on? If not, this

Code: Select all

if ($date!=="null") 
Fdate($date); 
if ($city!=="null") 
Fcity($city); 
if ($agency!=="null") 
Fagency($agency); 
if ($viewAll!=="0") 
Fall();
won't do anything.

Posted: Sat Apr 17, 2004 12:29 pm
by bufhal
The server accepts PHP, all files are chmod 777 and I am receiving some results. I believe register globals are on..

Posted: Sun Apr 18, 2004 4:53 pm
by bufhal
feyd;
can you tell me how to make more items (building room, contact name, phone #) to be pulled out in the search results? I want to be able to get the entire record(row) whether a user selects City, Date, or Agency.
Thank you

Posted: Sun Apr 18, 2004 4:54 pm
by bufhal
do I have to have more elements--all 11?

Posted: Sun Apr 18, 2004 6:01 pm
by Illusionist
maybe it's not getting all 11, because you don't have it get all 11. You only tell it to get 7, and to only get 3 on Fall.....

try changing:

Code: Select all

function Fdate ($date)
{
$content_array = file('data.dat');
$Total_records = count($content_array);

Print " These are results for <b>$date<br><br></b>";
For ($RecCount = 0; $RecCount < $Total_records; $RecCount++)
{
$elements = explode("<|>", $content_array[$RecCount]);
if ($elements[6] == $date)
print "<b>$elements[1]</b><br>$elements[2]<br>$elements[3],$elements[4] $elements[5]<br><b>$elements[6] - $elements[7]</b><br><br>";
}
to something like

Code: Select all

function Fdate ($date)
{
$content_array = file('data.dat');
$Total_records = count($content_array);

Print " These are results for <b>$date<br><br></b>";
For ($RecCount = 0; $RecCount < $Total_records; $RecCount++)
{
$elements = explode("<|>", $content_array[$RecCount]);
if ($elements[6] == $date)
print "<b>$elements[1]</b><br>$elements[2]<br>$elements[3],$elements[4] $elements[5]<br><b>$elements[6] - $elements[7], $elements[8],$elements[9],$elements[10],$elements[11]</b><br><br>";
}

Posted: Sun Apr 18, 2004 6:01 pm
by Illusionist
also change all the function tog et all 11 instead of only 7 or 3...

Posted: Sun Apr 18, 2004 6:10 pm
by bufhal
thank you, Illusionist
sometimes I need a wack in the head with a rolled up newspaper.
:oops:
thanks again..
bufhal