PDA

View Full Version : building a search function into a website


chriskq
02-06-2007, 03:17 AM
Hi all,

whats the best way to go about building a search function into a website. Ideally i'd only like to search certain pages (eg: within a articles folder) for the 'term' the user submitted. Then the results page would have appropriate listing(s) with a link

i'd be using php too.

any tut's or examples would be great.

davidj
02-06-2007, 07:25 AM
Ideally i'd only like to search certain pages (eg: within a articles folder)

so is this hard coded content in a file like text or html


Then the results page would have appropriate listing(s) with a link



link to what?

chriskq
02-06-2007, 11:25 AM
found a pretty basic javascript version Dj.... i'll need to tweak it abit, but basically u can assign terms and strings to pages, and it also ranks the result and links to the appropriate hard coded pages.

just wat i want really as i didn't specify this in the orginal quote nor was it discussed at the inital meeting too.

cant wait to show u i come up with. my deisgner should be finished next week.

dj - kno anything about displaying a stock ticker widget?

davidj
02-06-2007, 11:31 AM
just wat i want really as i didn't specify this in the orginal quote nor was it discussed at the inital meeting too.

dont you just love em (Clients)!
scope creep rears its ugly head again


kno anything about displaying a stock ticker widget?


no.. nowt

domedia
02-06-2007, 01:12 PM
dj - kno anything about displaying a stock ticker widget? Are you talking client side, how do display a marquee in a browser, or backend; how to get the stock info?

chriskq
02-07-2007, 01:29 AM
Hi Dom,

im sorta thinking about both things... trying to find an opensource one out on the web, but i've been searching for a few hrs intermidiatly just now with no luck.

ideally something like these widgets would be great eg: http://www.thespringbox.com/widgets/

how would you go about displaying a stock feed dom?

domedia
02-07-2007, 04:05 AM
I can give you a marquee example, does not involve the back end, but is nice implementation where HTML is pure and all the wizardry is in an external js file. It's in one of the books I have, just gotta find it first.

davidj
02-07-2007, 07:30 AM
http://www.scripts.com/javascript-scripts/text-scrolling-scripts/stock-market-javascript-ticker/

or you could look at it another way

try and find an xml feed with stock data then it would be easy to build your ticker engine using ajax or php or flash etc

chriskq
02-07-2007, 09:54 AM
nice one dj. looks pretty nice.
<edit>20 bucks..... hmmm</edit>

still interested in what u have to offer dom.

cheers guys

davidj
02-07-2007, 10:22 AM
$20 yes but take this sum

hourly rate x development time = true cost of your in-house developed free ticker

why reinvent the wheel?

davidj
02-07-2007, 10:31 AM
these are nice

http://www.quotemedia.com/demoarea/tickers/stock.php?t=d1

davidj
02-07-2007, 10:33 AM
or XML data feeds for your own white brand

http://www.quotemedia.com/demoarea/xml.php?t=hm

domedia
02-07-2007, 03:34 PM
Here ya are Chris, just had to digg a little.
The beauty of this one is the JS/HTML/CSS is separate, so you can customize to your own needs. I implemented this on saultstemarie.com last year. Script is by brothercake, one of DJ's countrymen ;)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>scrolling ticker</title>
<script type="text/javascript" src="scripts/scrolling_news_ticker.js"></script>
<link rel="stylesheet" type="text/css" href="css/scrolling_news_ticker.css" />
</head>
<body>
<h1>
How do I make a scrolling news ticker?
</h1>
<div id="newsTicker">
<div id="newsScroller">
<strong>Breaking news:</strong> Liverpool defeats AC Milan in a penalty shootout after a shock comeback from 3-0 down in the second half of the Champions' League final.
</div>
</div>
</body>
</html>

JS:
addLoadListener(initNewsTicker);

function initNewsTicker()
{
var newsScroller = document.getElementById("newsScroller");

newsScroller.style.left = 0;

if (retrieveComputedStyle(newsScroller, "position") == "relative")
{
var relativeWidth = newsScroller.offsetWidth;

newsScroller.style.position = "absolute";
newsScroller.calculatedWidth = newsScroller.offsetWidth;

if (relativeWidth > newsScroller.calculatedWidth)
{
newsScroller.calculatedWidth = relativeWidth;
}

newsScroller.style.position = "relative";
}
else
{
newsScroller.calculatedWidth = newsScroller.clientWidth;
}

var stopLink = document.createElement("a");
stopLink.setAttribute("id", "");
stopLink.id = "stopLink";
stopLink.setAttribute("href", "");
stopLink.href = "#";
stopLink.appendChild(document.createTextNode("Stop/start news ticker"));
attachEventListener(stopLink, "click", clickStopLink, false);

var stopButton = document.createElement("div");

stopButton.appendChild(stopLink);

var newsTicker = document.getElementById("newsTicker");

if (newsTicker.nextSibling != null)
{
newsTicker.parentNode.insertBefore(stopButton, newsTicker.nextSibling);
}
else
{
newsTicker.parentNode.appendChild(stopButton);
}

moveNewsScroller();

return true;
}

function moveNewsScroller()
{
var increment = 5;
var newsScroller = document.getElementById("newsScroller");
var currLeft = parseInt(newsScroller.style.left);

if (currLeft < newsScroller.calculatedWidth * -1)
{
newsScroller.style.left = newsScroller.parentNode.offsetWidth + "px";
}
else
{
newsScroller.style.left = (parseInt(newsScroller.style.left) - increment) + "px";
}

newsScroller.timeout = setTimeout("moveNewsScroller()", 50);

return true;
}

function clickStopLink()
{
var stopLink = document.getElementById("stopLink");

if (typeof stopLink.stopped != "undefined" && stopLink.stopped)
{
moveNewsScroller();
stopLink.stopped = false;
}
else
{
clearTimeout(document.getElementById("newsScroller").timeout);
stopLink.stopped = true;
}

return true;
}

function addLoadListener(fn)
{
if (typeof window.addEventListener != 'undefined')
{
window.addEventListener('load', fn, false);
}
else if (typeof document.addEventListener != 'undefined')
{
document.addEventListener('load', fn, false);
}
else if (typeof window.attachEvent != 'undefined')
{
window.attachEvent('onload', fn);
}
else
{
var oldfn = window.onload;
if (typeof window.onload != 'function')
{
window.onload = fn;
}
else
{
window.onload = function()
{
oldfn();
fn();
};
}
}
}

function attachEventListener(target, eventType, functionRef, capture)
{
if (typeof target.addEventListener != "undefined")
{
target.addEventListener(eventType, functionRef, capture);
}
else if (typeof target.attachEvent != "undefined")
{
target.attachEvent("on" + eventType, functionRef);
}
else
{
eventType = "on" + eventType;

if (typeof target[eventType] == "function")
{
var oldListener = target[eventType];

target[eventType] = function()
{
oldListener();

return functionRef();
}
}
else
{
target[eventType] = functionRef;
}
}

return true;
}

function retrieveComputedStyle(element, styleProperty)
{
var computedStyle = null;

if (typeof element.currentStyle != "undefined")
{
computedStyle = element.currentStyle;
}
else
{
computedStyle = document.defaultView.getComputedStyle(element, null);
}

return computedStyle[styleProperty];
}

CSS:
#newsTicker
{
position: relative;
width: 300px;
height: 35px;
overflow: hidden;
background-image: url(../images/news_ticker.jpg);
background-repeat: no-repeat;
}

#newsScroller
{
position: absolute;
position/**/: relative;
height: 35px;
line-height: 35px;
white-space: nowrap;
color: #FFFFFF;
font-size: 80%;
font-family: Arial, Helvetica, sans-serif;
}

#stopLink
{
position: absolute;
width: 35px;
height: 35px;
margin-left: 305px;
margin-top: -35px;
background-image: url(../images/news_ticker_button.jpg);
background-repeat: no-repeat;
text-indent: -9999px;
text-decoration: none;
}