please, if anyone wants to critique this script. i'm interested in making it as efficient as possible.
the purpose of this script is to parse a table full of text blobs in a mysql database, parse the text blobs for specific pieces of data based on certain keywords, then echo out html based on the query results.
i know large text blobs are not as efficient as smaller varchar fields for holding smaller pieces of information. i am not able to change the design of the database, as it is structured this way to optimize it for another purpose outside this script.
so outside of database design comments, if anyone has comments on how i can improve the efficiency of this cript i'd appreciate it. the table in the database will hold approximately 80-100 large text blobs. this script will be hit pretty heavily on our webserver. our server has 2 gig ram and dual pentium 2 ghz.
thanks, the script is below
<?
function between ($this, $that, $inthat)
{
return before($that, after($this, $inthat));
};
function before ($this, $inthat)
{
return substr($inthat, 0, strpos($inthat, $this));
};
function after ($this, $inthat)
{
if (!is_bool(strpos($inthat, $this)))
return substr($inthat, strpos($inthat,$this)+strlen($this));
};
$db_host='db.host.com';
$db_user='user';
$db_pass='pass';
$db_dbase='my_db';
$dbtable = 'my_db_placement'; // Table Name
$dbtable2 = 'my_db_entry'; // Table Name
$result = mysql_connect($db_host,$db_user,$db_pass);
if (!$result)
echo "Could not connect to the database - please try again later.";
if (!mysql_select_db($db_dbase))
echo "Could not connect to the database - please try again later.";
echo "<table width=\"100%\" border=\"0\">
<tr>
<td width='10%'><b>Docket number</b></td>
<td width='15%'><b>Case Name</b></td>
<td width='15%'><b>Oral Argument</b></td>
<td width='20%'><b>Opinion</b></td>
<td width='20%'><b>Lower Court</b></td>
<td width='20%'><b>Issues</b></td>
</tr>";
$sql="SELECT * FROM $dbtable";
$sql.=" WHERE placement_entry_id != 0";
$sql.=" AND placement_blog_id=4";
$sql.=" AND placement_category_id=53";
$query = mysql_query($sql);
$rowcount==0;
while ($result=mysql_fetch_array($query)){
$placement_entry_id=$result['placement_entry_id'];
$sql2="SELECT * FROM $dbtable2";
$sql2.=" WHERE entry_id = $placement_entry_id";
$sql2.=" AND entry_blog_id=4";
$sql2.=" AND entry_status=2";
$sql2.=" AND entry_text like '%Docket:%'";
$query2 = mysql_query($sql2);
$result2=mysql_fetch_array($query2);
$entry_id=$result2['entry_id'];
$entry_id_array[$rowcount]=$entry_id;
$entry_text=$result2['entry_text'];
$number=str_pad($entry_id, 6, "0", STR_PAD_LEFT);
$docket_number=between ('<!--begin docket number-->', '<!--end docket number-->', $entry_text);
$oral_argument=between ('<!--begin oral argument date-->', '<!--end oral argument date-->', $entry_text);
$opinions_issued=between ('<!--begin opinions issued-->', '<!--end opinions issued-->', $entry_text);
$appealed_from=between ('<!--begin appealed from-->', '<!--end appealed from-->', $entry_text);
$issues=between ('<!--begin subject-->', '<!--end subject-->', $entry_text);
$entry_title=$result2['entry_title'];
//echo $entry_id;
$number_array[$rowcount]=$number;
$docket_number_array[$rowcount]=trim($docket_number);
$oral_argument_array[$rowcount]=$oral_argument;
$opinions_issued_array[$rowcount]=$opinions_issued;
$appealed_from_array[$rowcount]=$appealed_from;
$issues_array[$rowcount]=$issues;
$entry_title_array[$rowcount]=$entry_title;
$docket_number_sort=str_replace('-','',trim($docket_number));
$docket_number_sort_array[$rowcount]=$docket_number_sort;
$rowcount++;
}
$counter==0;
while($counter <= $rowcount)
{
echo "<table width=\"100%\" border=\"0\">
<tr>";
// <td width='10%'>".$docket_number."</td>
// <td width='20%'><a href='http://www.myhost.com/my_db/archives/".$number.".php'>".$entry_title."</a></td>
//<td width='10%'>".$oral_argument."</td>
//<td width='20%'>".$opinions_issued."</td>
//<td width='20%'>".$appealed_from."</td>
//<td width='20%'>".$issues."</td>
//</tr>";
array_multisort($docket_number_sort_array,SORT_ASC,$docket_number_array,$number_array,$entry_title_array,$oral_argument_array,$opinions_issued_array,$appealed_from_array,$issues_array);
echo "<td width='10%'>".$docket_number_array[$counter]."</td>";
echo "<td width='20%'><a href='http://www.myhost.com/my_db/archives/".$number_array[$counter].".php'>".$entry_title_array[$counter]."</a></td>";
echo "<td width='10%'>".$oral_argument_array[$counter]."</td>";
echo "<td width='20%'>".$opinions_issued_array[$counter]."</td>";
echo "<td width='20%'>".$appealed_from_array[$counter]."</td>";
echo "<td width='20%'>".$issues_array[$counter]."</td>";
echo "</tr>";
$counter++;
}
echo "</table>";
exit;
?>