473,607 Members | 2,674 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem Finding Occurances Of One String Within Another

Can anybody see what is wrong with this code? apparently i have an 'empty
delimiter' on the line that sets $pos - can anybody see what is wrong with
it?
$search_for = $_GET['for'];
$the_items_desc ription = $row ["descriptio n"];
$pos = stristr($the_it ems_description , $search_for);

if ($search_for == "") {
$does_contain_t ext = true;
} elseif ($pos === false) {
$does_contain_t ext = false;
} else {
$does_contain_t ext = true;
}

// end text search
if ($does_contain_ text == true) { // rest of page works fine
Jul 17 '05 #1
5 3195
Matthew Robinson wrote:
Can anybody see what is wrong with this code? apparently i have an 'empty
delimiter' on the line that sets $pos - can anybody see what is wrong with
it?
$search_for = $_GET['for'];
$the_items_desc ription = $row ["descriptio n"];
$pos = stristr($the_it ems_description , $search_for);

if ($search_for == "") {
$does_contain_t ext = true;
} elseif ($pos === false) {
$does_contain_t ext = false;
} else {
$does_contain_t ext = true;
}

// end text search
if ($does_contain_ text == true) { // rest of page works fine


Looks fine here.
Do you have a mismatched quote somewhere before this code?
I mean, before the line that sets $search_for?
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
have a look on the link below for the output
http://www.houseproudlancs.co.uk/sea...+%26+Furniture
the whole page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<body bgcolor="#8C999 B">
<?php
$search_for = $_GET['for'];
$search_categor y = $_GET['category']; global $search_for;
global $search_categor y;
global $the_items_desc ription;
global $does_contain_t ext;
?>

<div align=center>
<form action="http://www.houseproudl ancs.co.uk/search.php"
method="GET"> <br><table bgcolor="#FFF8D 7" cellpadding=6>
<tr> <td> </td> </tr> <tr> <td> <div align=center> Search For:
</div></td> <td> <div align=center> Category: </div></td> </td>
</tr> <tr> <td>
<INPUT name=for value=<?php echo ("$search_for") ; ?>>
</td> <td>
<SELECT NAME=category SIZE=1>
<OPTION <?php if ($search_catego ry == "Search All
Categories") { echo ("SELECTED") ; } ?>>Search All Categories
<OPTION <?php if ($search_catego ry == "Floral Creations") {
echo ("SELECTED") ; }?>>Floral Creations <OPTION <?php if
($search_catego ry == "Decorative Lighting") { echo
("SELECTED") ; }?>>Decorative Lighting <OPTION <?php if
($search_catego ry == "Kitchenwar e & Crockery") { echo
("SELECTED") ; }?>>Kitchenware & Crockery <OPTION <?php if
($search_catego ry == "Fancy Goods & Furniture") { echo
("SELECTED") ; }?>>Fancy Goods & Furniture
</SELECT>
</td> <td>
<INPUT TYPE=submit VALUE="Search">
</td>
</form>
<tr> <td> </td> </tr>
</table>
</div>
<?php
switch ($search_catego ry) {
case "":
exit;
break;
case "Search All Categories":
$filter_categor y = "*" ;
break;
case "Floral Creations":
$filter_categor y = "floral";
break;
case "Decorative Lighting":
$filter_categor y = "lighting";
break;
case "Kitchenwar e & Crockery":
$filter_categor y = "kitchenwar e";
break;
case "Fancy Goods & Furniture":
$filter_categor y = "furniture" ;
break;
default:
echo ("<P>Error - The Selected Category Was Not Found</P>"); break;
}

$dbcnx = @mysql_connect( "srv",
"usr", "pwd"); $select =
@mysql_select_d b("houseproudla ncs_co_uk1"); if ($filter_catego ry ==
"*") {
$command = "SELECT * FROM `stock` WHERE 1 ORDER BY `id`";
} else {
$command = "SELECT * FROM `stock` WHERE 1 AND `category` LIKE
\"$filter_categ ory\" ORDER BY `id`";
}
$qresult = mysql_query($co mmand);

echo ("text search returned true");

$started_table = false;
while ($row = mysql_fetch_arr ay($qresult)) {
//text search
$the_items_desc ription = $row ["descriptio n"];
$pos = stristr($the_it ems_description , $search_for);

echo ("POS = ");
echo ("$pos");
echo ("<br>item description = ");
echo ("$the_items_de scription");
echo ("<br> search for = ");
echo ("$search_for") ;
echo ("<br>");
if ($search_for == "") {
$does_contain_t ext = true;
} elseif ($pos === false) {
$does_contain_t ext = false;
} else {
$does_contain_t ext = true;
}

// end text search
if ($does_contain_ text == true) {

if ($started_table = false) {
echo ("<center><tabl e width=80% cellpadding=5>" ); $tablebgcolor =
"#FFF8D7"; }

if ($tablebgcolor == "#FFF8D7"){ //yellow
$tablebgcolor = "#C5C8FF"; //blue
} else {
$tablebgcolor = "#FFF8D7";
} ?>

<tr ><td> <table border=0 cellspacing=3 width=100% bgcolor=<?php
echo ("$tablebgcolor "); ?>> <tr><td> <table> <tr>
<?php
switch ($row ["category"]) {
case "lighting":
$item_category = "Decorative Lighting"; break;
case "floral";
$item_category = "Floral Creations";
break;
case "kitchenwar e":
$item_category = "Kitchenwar e & Crockery"; break;
case "furniture" :
$item_category = "Fancy Goods & Furniture"; break;
default;
$item_category = "Unknown Category";
break;
}
?>
<td><pre>Name : </pre></td> <td><b><?php echo ($row
["name"]); ?> </b> </td></tr><tr> <td><pre>Descri ption:
</pre></td> <td><?php echo ($row ["descriptio n"]); ?>
</td></tr><tr> <td><pre>Catego ry: </pre></td> <td><?php echo
($item_category ); ?> </td></tr><tr> <td><pre>Pric e:
?</pre></td> <td><?php echo ($row ["price"]); ?>
</td></tr><tr> <td><pre>P&P: ?</pre></td> <td><?php echo
($row ["pandp"]); ?> </td></tr><tr>
<?php $quantity = $row ["quantity"];
if ($quantity != "0") { ?>
<td><pre>Quanti ty: </pre></td> <td><?php echo ($row
["quantity"]); ?> </td></tr><tr><?php } ?>
<td><pre>Produc t ID: </pre></td> <td> <?php echo ($row
["id"]); ?> </td></tr><tr><td>
<?php if ($quantity == "0") { ?>
<td><b> <font color=#DD0000> Temporarily Out Of Stock
</b></font></tr><tr>
<?php } ?>
</td></tr></table>
</td><td width=30%>
<?php $pictureid = $row ["id"]; ?>
<?php $picturepath = "./images/" . $pictureid . ".jpg"; ?>
<?php
if (file_exists($p icturepath)) {
echo ("<div align=\"center\ "><a href=\"$picture path\"
target=LargeIma ge><img src=$picturepat h height=200 alt='Image
Of Product'></a><font size=2><br>Clic k The Image To See It Full
Size In A New Window</font></div>");
} else {
echo ("<div align=\"center\ "><img src=\"/images/nopic.png\"
height=200 alt='No Picture Available'></a><font
size=2><br>Sorr y, There Is No Available Picture For This
Item</font></div>");
}
?>
</td></tr></table></td></tr>
<?php } ?>
</table></center>

<?php } ?>

Jul 17 '05 #3
that post from karen cooke was me - thats my girlfriend and i accidently
clicked her profile
Jul 17 '05 #4
Matthew Robinson wrote:
that post from karen cooke was me - thats my girlfriend and i accidently
clicked her profile


Your problem is in the stristr() call

$search_for is "" (the URL was ....search.php? for=&category.. ..)
and stristr() gives that warning.

Put this before the line that sets $pos

if ($search_for === '') $search_for = ':X:X:';
// hopefully ":X:X:" is something that is *never* in $the_items_desc ription
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #5
thanks again (again) pedro
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6507
by: kong | last post by:
I created a package using pl/sql. In this package i have a dblink to another Database, call it DB2. Meanwhile, Server2 has a DBlink to another Database, call it DB3. Within my package, i have a sql that link to these DB2's view. In the View of this DB2, it call a function from DB3 and take the data from the DB3. I run this package in few locations. This package run fine except for one location.
7
3174
by: addled | last post by:
Hi there, after reading posts here for a few months, I've built the courage to see if someone can see where I"m going wrong in the webpage I've been working on. In particular the horizontal nav bar accross the top of the page. viewd here http://foundations.port5.com/currprojects/babylon.html I am running win XP and have tested in both Avant (MSIE) and Opera 7.23 the result is a different problem in each.
1
2171
by: Andrew Poulos | last post by:
Say I have a page, which has been created by a third party, and the page may contain some pre-specified text. How can I find and replace that text dynamically? For example, if the page I have contains this HTML: <div id=”oDiv” style="margin-bottom:10px;">{when}</div> <div> <table style="border:1px solid gray"> <tr> <td>blah</td>
4
6444
by: David Warner | last post by:
Greetings! In looking into some C coding, I am looking for the C function that will search for multiple occurances of a same character in a string. For Instance: char str = "We the people of the United States"; strchr will be successful if i am looking for the "U". It returns a
4
2161
by: | last post by:
I am stuck in a situation and I do believe that this should work, but it doesn't. I have a unmanaged dll, that uses MFC. This works great. Now I recompile the unmanaged dll so it contains mixed mode managed/unmanaged code, but only use unmanaged code, but this gives a error the moment I want to display a MFC dialog box: Something like unreferenced object,... during runtime.
5
1224
by: Paul | last post by:
Hi, I'm trying to create an array containing the entire contents of a text file and delimit the elements using vbCrLf. The text file is like this.... -text1 -text2 -text3
2
5493
by: Jason Barnett | last post by:
I thought I had seen a method for returning the number of occurances of a substring within a string object, but I can't seem to find it now. Does anyone know of something? I know I can parse the substrings and count them using a loop, but I'm looking for a single function or method to simplify the process.
2
1801
by: brock | last post by:
I'd like to be able to take a string and search within it for all words (of the longest length possible) that are possibly contained within it (in sequence, we're not re-ordering the letters in the string). Obviously the brute force approach (which may be the only solution) is to iterate through a dictionary file searching for occurances of each entry within the string. If anyone has done anything similar to this, were there any other...
0
8049
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7985
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8463
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8128
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5471
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4013
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2461
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1574
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.