Forum Moderators: coopster
This is my form script;
<form style="display: inline;" method="post" action="?searchresult=1">Zoeken: <input type="text" value="" name="zoekterm" /> <input type="image" src="library/arrow.gif" value="Submit" name="B1" /></form>
This is the script for showing the results;
<?
function searchresult()
{
$sql = "SELECT *
FROM cursussen
WHERE cursusnaam LIKE '%$_POST[zoekterm]%'
OR code LIKE '%$_POST[zoekterm]%'
OR examen LIKE '%$_POST[zoekterm]%'
ORDER BY examen ASC
";
$res = mysql_query($sql);
if (mysql_num_rows($res) >= 1)
{
while ($row = mysql_fetch_array($res))
{
echo "<p><font face=Verdana size=1>Cursus: $row[code]<br>";
echo "Examen: $row[examen]<br>";
echo "<a href=\"index.php?pid=3&cursusid=$row[cursusid]&ai=20\">$row[cursusnaam]</a></font></p>";
}
echo "<a href=\"index.php\" title=\"zoek opnieuw\"><font face=Verdana size=1>zoek opnieuw</font></a>";
}
else
{
echo "<p><font face=Verdana size=1>Er is niets gevonden op de zoekterm:<b> $_POST[zoekterm]</b></font></p>";
echo "<p><a href=\"index.php\" title=\"zoek opnieuw\"><font face=Verdana size=1>zoek opnieuw</font></a></p>";
}
}
?>
And this is the code that should place the results in the website, but doesn't work;
<?
if (isset($_REQUEST["pid"]) && isset($inc_myrow))
{
echo "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><TR><TD width=\"200\" valign=\"top\">";
require("inc/menu.inc.php");
echo "</TD><TD class=\"content\" valign=\"top\">".$content."</TD></TR></TABLE>";
} elseif (isset($_REQUEST["searchresult"])) {
echo "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><TR><TD width=\"200\" valign=\"top\">";
require("inc/menu.inc.php");
echo "</TD><TD class=\"content\" valign=\"top\">".searchresult()."</TD></TR></TABLE>";
} else
{
include ("inc/default.inc.php");
}
?>
Anyone who has the solution for showing the results?
[edited by: coopster at 7:47 pm (utc) on Mar. 23, 2006]
[edit reason] removed comments, formatted code [/edit]
let me post the entire script, so you can see where that function comes from;
<?php
require ("inc/config.inc.php");
require ("inc/functions.php");
$extrameta=null;
if (isset($_REQUEST["pid"]))
{
if (isset($_REQUEST["ai"])) // activeitem ;)
{
$menu_query = "SELECT * FROM menu WHERE (parent_id='0' OR parent_id='".$_REQUEST["ai"]."') AND (location='left' OR location='both') ORDER BY rank,parent_id, text";
$menu_result = mysql_query($menu_query) or die("Fout in query :(");
}
else
{
$menu_query = "SELECT * FROM menu WHERE parent_id='0' AND (location='left' OR location='both') ORDER BY rank,parent_id, text";
$menu_result = mysql_query($menu_query) or die("Fout in query :(");
}
while ($menu_myrow = mysql_fetch_assoc($menu_result)) {
$arr_menu[]=$menu_myrow;
}
$inc_query = "SELECT include,include_path FROM menu WHERE id = '".$_REQUEST["pid"]."'";
$inc_result = mysql_query($inc_query) or die("Fout in query :(");
$inc_myrow = mysql_fetch_assoc($inc_result);
if ($inc_myrow["include"])
{
include ($inc_myrow["include_path"]);
}
else
{
$content_query = "SELECT * FROM content WHERE page_id = '".$_REQUEST["pid"]."'";
$content_result = mysql_query($content_query) or die("Fout in query :(");
$content_myrow = mysql_fetch_assoc($content_result);
$content = "<div class=\"pagehead\">".$content_myrow["head"]."</div><br /><br /><div class=\"pagecontent\">".$content_myrow["text"]."</div>";
}
}
$bottom_menu_query = "SELECT * FROM menu WHERE (location='bottom' OR location='both') ORDER BY rank";
$bottom_menu_result = mysql_query($bottom_menu_query) or die("Fout in query :(");
/*
Width = 776px breed zodat op een resolutie van 800x600 de pagina netjes zonder horizontal scrollbars erop past (incl. inactive vertical scrollbar).
Right-side = outerright.gif is 10px breed.
Table framespacing = 1px, wat een totaal van 4px maakt voor de tabel.
Frame 1,4,5,8 = 330px breed.
Frame 2,3,6,7,9: (((776-10)-4)-330) / 2 = 216px per frame.
¦-----------------------¦--------------¦--------------¦
¦ ¦ ¦ ¦
¦ ¦ ¦ ¦
¦ ¦ ¦ ¦
¦ FRAME 1 ¦ FRAME 2 ¦ FRAME 3 ¦
¦ ¦ ¦ ¦
¦ ¦ ¦ ¦
¦ ¦ ¦ ¦
¦-----------------------¦--------------¦--------------¦
¦ FRAME 4 ¦ ¦ ¦
¦-----------------------¦ FRAME 6 ¦ ¦
¦ FRAME 5 ¦ ¦ ¦
¦-----------------------¦--------------¦ FRAME 7 ¦
¦ ¦ ¦ ¦
¦ FRAME 8 ¦ FRAME 9 ¦ ¦
¦ ¦ ¦ ¦
¦-----------------------¦--------------¦--------------¦
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<?=$extrameta?>
<title>V.</title>
<link rel="stylesheet" type="text/css" href="library/style.css" />
<script language="Javascript" type="text/javascript">
function p()
{
window.open('printfrm.php?<?=$_SERVER['QUERY_STRING'];?>', '', 'toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=0,width=300,height=100,left=0,top=0');
}
var activelayer = 'id0';
var lastlayer = activelayer;
function showhide(divID) {
hide();
show(divID);
}
function show(NewDivID) {
if (activelayer!= NewDivID)
{
lastlayer = activelayer;
}
if (document.layers && document.layers[NewDivID]!= null)
{
document.layers[NewDivID].visibility = 'visible';
}
else if (document.all)
{
document.all[NewDivID].style.visibility = 'visible';
}
else if (document.getElementById)
{
document.getElementById(''+NewDivID+'').style.visibility = 'visible';
}
activelayer = NewDivID;
//alert ('Last Layer: '+lastlayer);
}
function hide() {
if (document.layers && document.layers[activelayer]!= null)
{
document.layers[activelayer].visibility = 'hidden';
}
else if (document.all)
{
document.all[activelayer].style.visibility = 'hidden';
}
else if (document.getElementById)
{
document.getElementById(''+activelayer+'').style.visibility = 'hidden';
}
}
</script>
</head>
<body>
<table border="0" align="center" width="766" cellspacing="0" cellpadding="0" class="tblbase1">
<tr>
<!--<td width="10" class="page_start"><img src="library/spacer.gif" width="10" height="10" alt="" /></td>//-->
<td valign="top">
<table border="0" width="100%" cellspacing="0" cellpadding="0" class="tblbase2">
<tr>
<td colspan="3" height="80" class="base1" valign="top">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="448"><img border="0" style="position:absolute; left: 50%; margin-left:-20px; top: 22px;" src="library/dida_logo_prt1.gif" alt="" /><img border="0" style="position:absolute; left: 50%; margin-left:42px; top: 90px; " src="library/dida_logo_prt2.gif" alt="" /></td>
<td width="328" align="right"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3" height="1" bgcolor="#ffffff"><img src="library/spacer.gif" height="1" width="1" alt="" /></td>
</tr>
<tr>
<td width="1" bgcolor="#ffffff"><img src="library/spacer.gif" height="1" width="1" alt="" /></td>
<td height="30" class="base2">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td style="padding-left: 10px;"><img border="0" src="library/base2_itprofs.gif" alt="" /></td>
<td style="padding-right: 3px;" align="right">
<form style="display: inline;" method="post" action="?searchresult=1">Zoeken: <input type="text" value="" name="zoekterm" /> <input type="image" src="library/arrow.gif" value="Submit" name="B1" /></form>
</td>
</tr>
</table>
</td>
<td width="1" bgcolor="#ffffff"><img src="library/spacer.gif" height="1" width="1" alt="" /></td>
</tr>
<tr>
<td colspan="3" valign="top">
<?
if (isset($_REQUEST["pid"]) && isset($inc_myrow))
{
echo "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><TR><TD width=\"200\" valign=\"top\">";
require("inc/menu.inc.php");
echo "</TD><TD class=\"content\" valign=\"top\">".$content."</TD></TR></TABLE>";
} elseif (isset($_REQUEST["searchresult"])) {
echo "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><TR><TD width=\"200\" valign=\"top\">";
require("inc/menu.inc.php");
echo "</TD><TD class=\"content\" valign=\"top\">".searchresult()."</TD></TR></TABLE>";
} else
{
include ("inc/default.inc.php");
}
?>
</td>
</tr>
<tr>
<td width="1" bgcolor="#ffffff"><img src="library/spacer.gif" height="1" width="1" alt="" /></td>
<td height="30" class="base3"> </td>
<td width="1" bgcolor="#ffffff"><img src="library/spacer.gif" height="1" width="1" alt="" /></td>
</tr>
<tr>
<td colspan="3" height="25">
<table border="0" width="100%" cellspacing="1" cellpadding="0">
<tr>
<?
while ($bottom_menu_myrow = mysql_fetch_assoc($bottom_menu_result)) {
echo "<td align=\"center\" class=\"bot_nav\" onclick=\"location.href='?pid=".$bottom_menu_myrow["id"]."';\" onmouseover=\"this.className='bot_nav_active';\" onmouseout=\"this.className='bot_nav';\">".$bottom_menu_myrow["text"]."</td>";
}
?>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3" height="45" align="center" class="base4">
<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td align="center"><img border="0" src="library/logo_vue.jpg" width="73" height="43" alt="" /></td>
<td align="center"><img border="0" src="library/logo_ms_exam.jpg" width="83" height="44" alt="" /></td>
<td align="center"><img border="0" src="library/logo_linux.jpg" width="37" height="40" alt="" /></td>
<td align="center"><img border="0" src="library/logo_cisco.jpg" width="69" height="40" alt="" /></td>
<td align="center"><img border="0" src="library/logo_checkpoint.jpg" width="91" height="40" alt="" /></td>
<td align="center"><img border="0" src="library/logo_mysql.jpg" width="81" height="43" alt="" /></td>
<td align="center"><img border="0" src="library/logo_veritas.jpg" width="60" height="40" alt="" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3" height="1" align="center" class="bg_blue"><img src="library/spacer.gif" height="1" width="1" alt="" /></td>
</tr>
<tr>
<td colspan="3" height="20" align="center" class="base5">© 2005 - Alle rechten voorbehouden</td>
</tr>
<tr>
<td colspan="3" height="1" align="center" class="bg_blue"><img src="library/spacer.gif" height="1" width="1" alt="" /></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
<!--<a href="getcatalogusKim.php">Kim</a>//-->
</html>
<?
// CLOSE DATABASE CONNECTION
mysql_close($connection);
?>
function searchresult() {
echo 'bar';
}
echo 'foo' . searchresult() . 'foo';
That will not print 'foobarfoo' but 'barfoofoo'.
Either rewrite your function:
function searchresult() {
return 'bar';
}
echo 'foo' . searchresult() . 'foo';
or the way you generate output:
function searchresult() {
echo 'bar';
}
echo 'foo';
searchresult();
echo 'foo';
One thing I can see that causes problems is basically this:function searchresult() {
echo 'bar';
}
echo 'foo' . searchresult() . 'foo';That will not print 'foobarfoo' but 'barfoofoo'.
Either rewrite your function:
function searchresult() {
return 'bar';
}
echo 'foo' . searchresult() . 'foo';or the way you generate output:
function searchresult() {
echo 'bar';
}
echo 'foo';
searchresult();
echo 'foo';
You're talking about the searchfunction that should be changed?
This function is working fine, only thing that doesn't work is reaching this function and displaying the results.
Anyway, some basic debugging will easily show whether your function searchresult() gets called or not, and what happens to its output.
Blerfaap, for the sake of readability: keep your posts as short as possible. Please do not quote entire posts, and only post relevant parts of scripts. Thank you.