|
Posted by Chris on 07/18/06 15:45
I have a simple search feature that searches 3 fields in 3 separate tables
in a MySQL db, and I'm getting an 'undefined index' error, but only in the
first section (first table)of the results. The undefined index is tied to
the docs.projID in the "if ($row_search['docs.projID'] == 1)". This if
statement is there to control to format of the link as pages are in
different depths of subfolders depending on security needs. Googling this
sort of error seems to reflect problems with the $_POST['keyword'] not
existing when the results are first listed, so I moved the PHP results code
from it's own page (search.php) to the main page, which didn't help. I have
tried several different things and can't seem to get it working right. Here
is what I have:
Form:
<form id="search" name="search" method="post" action="<?php echo
$currentPage?>">
SEARCH<br />
<input name="keyword" type="text" size="20" value=""/>
<input type="image" name="Submit"
src="images/team_icon_go_btn.gif" />
</form>
Results:
<?php if (isset($_POST['search']))
{
$keyword = $_POST['keyword'];
mysql_select_db($database_website, $website);
$query_search = "SELECT Distinct docURL, docTitle, docDesc, docs.projID,
groupCode, projCode, catName FROM docs
JOIN subcat on subcat.subcatID=docs.subcatID
JOIN cat on cat.catID = subcat.catID
JOIN groups on groups.groupID=proj.groupID
JOIN proj on proj.projID=docs.projID
WHERE proj.projID=docs.projID AND docURL LIKE '%$keyword%' OR docTitle LIKE
'%$keyword%' OR docDesc LIKE '%$keyword%'";
$search = mysql_query($query_search, $website) or die(mysql_error());
$row_search = mysql_fetch_assoc($search);
$totalRows_search = mysql_num_rows($search);
$proj = $row_search['projCode'];
?>
<?php if ($totalRows_search < 1)
{
echo "No internal documents matched your request.";
}
else {?>
<p><table width=95%>
<tr><td colspan="3"><font size="+1">Internal Documents:</font></td>
</tr>
<tr>
<td><strong> Link </strong></td>
<td> <strong>Description</strong></td>
<td> <strong>Project </strong></td>
</tr>
<?php
do { ?>
<tr>
<td>
<a href="<?php if ($row_search['docs.projID'] == 1) {
echo $row_search['catName']."/".$row_search['docURL'];
}
else {
echo
$row_search['groupCode']."/".$row_search['projCode']."/".$row_search['catName']."/".$row_search['docURL'];
?>"><?php echo $row_search['docTitle'];
} ?></a></td>
<td><?php echo $row_search['docDesc']; ?></td><td><?php echo
$row_search['projCode']; ?></td>
</tr>
<?php } while ($row_search = mysql_fetch_assoc($search)); ?>
</table>
<?php }?>
</p>
<?php
mysql_select_db($database_website, $website);
$query_search = "SELECT Distinct toolURL, toolName, toolDesc, tools.projID,
projCode FROM tools
JOIN proj on proj.projID=tools.projID WHERE toolURL LIKE '%$keyword%' OR
toolName LIKE '%$keyword%' OR toolDesc LIKE '%$keyword%'";
$search = mysql_query($query_search, $website) or die(mysql_error());
$row_search = mysql_fetch_assoc($search);
$totalRows_search = mysql_num_rows($search);
?>
<?php if ($totalRows_search < 1)
{
echo "No tools matched your request.";
}
else {?>
<p><table width=95%>
<tr><td colspan="3"><font size="+1">Tools:</font></td>
</tr>
<tr>
<td><strong> Link </strong></td>
<td> <strong>Description</strong></td>
<td> <strong>Project </strong></td>
</tr>
<?php do { ?>
<tr>
<td>
<a href="<?php echo $row_search['toolURL']; ?>"><?php echo
$row_search['toolName']; ?></a></td><td><?php echo $row_search['toolDesc'];
?></td><td><?php echo $row_search['projCode']; ?></td>
</tr>
<?php } while ($row_search = mysql_fetch_assoc($search)); ?>
</table>
<?php }?>
</p>
<?php
mysql_select_db($database_website, $website);
$query_search = "SELECT Distinct pageURL, pageName, pageDesc, links.projID,
projCode FROM links
JOIN proj on proj.projID=links.projID WHERE pageURL LIKE '%$keyword%' OR
pageName LIKE '%$keyword%' OR pageDesc LIKE '%$keyword%'";
$search = mysql_query($query_search, $website) or die(mysql_error());
$row_search = mysql_fetch_assoc($search);
$totalRows_search = mysql_num_rows($search);
?>
<?php if ($totalRows_search < 1)
{
echo "No external documents matched your request.";
}
else {?>
<p><table width=95%>
<tr><td colspan="3"><font size="+1">External Documents:</font></td>
</tr>
<tr>
<td><strong> Link </strong></td>
<td> <strong>Description</strong></td>
<td> <strong>Project </strong></td>
</tr>
<?php do { ?>
<tr>
<td>
<a href="<?php echo $row_search['pageURL']; ?>"><?php echo
$row_search['pageName']; ?></a></td><td><?php echo $row_search['pageDesc'];
?></td><td><?php echo $row_search['projCode']; ?></td>
</tr>
<?php } while ($row_search = mysql_fetch_assoc($search)); ?>
</table>
<?php }?>
</p>
<?php
mysql_free_result($search);
}
?>
All guidance is welcome. Maybe I should move the if statement out of the
link or assign a variable. I'm considering changing all of my links in the
db to absolute URLs instead of relative, as this mapping to the location of
a page has become a programming overload nightmare. Perhaps this would
resolve my issue.
Thanks,
Christina
[Back to original message]
|