View Full Version : Search bar help
D0gSoldi3r
07-14-2008, 04:57 PM
Right guys i have this search bar on my site and it works but once you type a search in it displays everything on one page, i could type "and" in and it would display 500 results on 1 page with the result "and" what i'm wanting to do is break it down. I could type nothing in and do a search and it would display everything on my server 700+ pages worth of it on one single page. I've been scratching my head with this problem and haven't came close to a fix so could some of you guys help me with this search bar source code below.
All i'm looking for is some code that would display the results on various pages. :) instead of one.
<form action="index.php" method="post" name="mod_seyret_search_form">
<input type="text" id="mod_seyret_search_key" name="searchkey" size="40" class="mod_seyret_search_box"/>
<button type="submit" class="mod_seyret_search_inputbox"> Search</button>
<a href="/search" class="style5">advanced</a>
<p>
<input type="hidden" name="option" value="com_seyret" />
<input type="hidden" name="task" value="searchvideos" />
</p>
</form>
Assuming you're reading from a database, maybe this link (http://php.about.com/od/phpwithmysql/ss/php_pagination.htm) may be helpful...
D0gSoldi3r
07-14-2008, 05:18 PM
TNX. Okay i read some of it by glancing through the pages and noticed on the front page of the code that i was to add my username and password into that php code which i obviously don't feel comfortable with.
Falcon1986
07-14-2008, 06:14 PM
Have you thought about letting Google Search (http://www.askdavetaylor.com/how_can_i_add_a_google_search_box_to_my_web_site.h tml) handle your searches?
D0gSoldi3r
07-14-2008, 09:07 PM
Right so how exactly does this part of the script work "r2b2"
// Connects to your Database
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());
mysql_select_db("address") or die(mysql_error());
I don't feel comfortable inputting my server details for anybody to read that data on page source.
shadmego
07-14-2008, 09:34 PM
php is not interpreted by the browser. It is handled by the server. If you write that on a page and then view the page in your browser, you won't see that code. The only way someone could get that information is to download that page before it is interpreted by the browser, which is unlikely unless they have access to your account information.
To help secure even further, you could write that code in a script named, say, "db_conn.php" and then in the page a connection to the database is needed, you could use:
require_once('db_conn.php');
or
include_once('db_conn.php');
That way you can place db_conn.php in a location that is unavailable to outsiders, but available to scripts you are using to connect to your database -- say, /home/account.
~regards
D0gSoldi3r
07-15-2008, 04:48 AM
Still slightly confused on how i would do this been trying myself but i keep getting errors, since i'm new to all this php would somebody be able to fill the blanks for me using fake usernames and "your.hostaddress.com" stuff. Could somebody make a quick fake template for me to give me an idea how to make an advanced search form.
right guys i've been using this
========================
<div id="line2">
<?php
?>
<div align="center">
<form action="index.php" method="post" name="mod_seyret_search_form">
<input type="text" id="mod_seyret_search_key" name="searchkey" size="40" class="mod_seyret_search_box"/>
<button type="submit" class="mod_seyret_search_inputbox"> Search</button>
<a href="/search" class="style5">advanced</a>
<p>
<input type="hidden" name="option" value="com_seyret" />
<input type="hidden" name="task" value="searchvideos" />
</p>
</form>
</div>
=================================
Now the code above adds a nice little search bar in my site, and i was told to add this to the code above too make it that little bit more advanced.
==============================================
<?php
// Connects to your Database
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());
mysql_select_db("address") or die(mysql_error());
//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($pagenum)))
{
$pagenum = 1;
}
//Here we count the number of results
//Edit $data to be your query
$data = mysql_query("SELECT * FROM topsites") or die(mysql_error());
$rows = mysql_num_rows($data);
//This is the number of results displayed per page
$page_rows = 4;
//This tells us the page number of our last page
$last = ceil($rows/$page_rows);
//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
//This sets the range to display in our query
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
============================================
But i must be filling in something wrong by not filling in a "http://" or a ".ftp somewhere, could somebody Pretend this is a fake account and help me fill in the blanks, Sry if i'm not able to thank you later for helping cause i'm going on Holiday early tomorrow :)
pghcollectibles
07-15-2008, 12:45 PM
$con=mysql_connect("localhost", "username", "password") or die("Could not connect:" . mysql_error());
mysql_select_db("name_of_your_database",$con) or die("Could not connect:" . mysql_error());
localhost is the name of the server and if you include notes with your die/error messages it will make it easier to troubleshoot as well. i have concerns with this part of your code...
//Here we count the number of results
//Edit $data to be your query
$data = mysql_query("SELECT * FROM topsites") or die(mysql_error());
$rows = mysql_num_rows($data);
it says $data will be your query but unless this is a different part of the code from your search you will want to add options to your query string either by not selecting all(*) or by adding a LIMIT or however you want to do it. the variable coming from the submit action will be $_POST["searchkey"] you could use some if statements at the top of your page like:
$searchkey=$_POST["searchkey"];
if (strlen($searchkey)<"4"){
//do something about it
echo "alert('search word too short')";
//dont allow the query to find anything either
$searchkey="alongwordlikethisorwhatever";
}
then modify your query. here is a link (http://www.w3schools.com/php/php_mysql_intro.asp) for help since i was just there anyway. ;)
shadmego
07-15-2008, 01:49 PM
I looked at your site and am starting to wonder what is going on. I have Joomla! as my core management system as well, and my search function automatically creates pages for results that are longer than X number of entries. Have you messed with the core functionality of the search module?
If yours is not working properly, rather than manually editing the code, why not try to download and install a third party search module.
Give a start here (http://extensions.joomla.org/index.php?option=com_mtree&task=listcats&cat_id=1825&Itemid=35) and see where it takes you ...
~regards
D0gSoldi3r
07-27-2008, 08:22 AM
Yeah i'm back now went away on my holidays before i was able to fix this problem, and no shadmego this is a separate search bar module for a Seyret video component that only looks for videos and nothing more on my website. the module wasn't doing what i wanted so i decided to take the modules php code and add it to my index.php which is giving me more options and i was having this issue with the module before i altered it and none of the seyret experts could help so i decided to ask for you guys. The joomla core search works fine and i'm leaving that alone but i was looking for a kinda youtube search on my site which is why i'm looking forward in getting this fixed. so yeah if somebody types in a search they get every single search result on 1 page which could be like 750 results which will eat up my bandwidth.
edit
=============
This is already a different search bar than the core search bar, i haven't touched my proper default core search what i'm messing around with is some module search bar code i decided to put on my index.php code so i could have full control over the search as this is an important part of my site. I also purchased a Seyret search bar for $15.00 and that didn't work either and was giving me the same problems so i went back to the free module i was working on.
D0gSoldi3r
07-28-2008, 10:53 PM
Bump, no :( ah well ya can't blame a guy for trying.
shadmego
07-28-2008, 10:59 PM
If you purchased a script from the company, why not ask them to redo the script to allow for pagination? You should never have to modify any core files like the index.php file of your Joomla! install. It could seriously degrade performance or open up huge security holes.
You can also read up on the API for Joomla! and create your own search module specific to your needs. It shouldn't be too difficult to tie into Joomla! and your video program for searching.
~regards
D0gSoldi3r
07-29-2008, 08:44 AM
A search bar isn't really going to cause a security risk though is it, it's only templates i'm messing around with the .php anyway if something goes horribly wrong which hasn't happened i can always create a new template. And no the guys @ seyret never listen to constructive criticism anything you tell them they always think it's a glitch on your side and rarely want to help you which gets really frustrating.
shadmego
07-29-2008, 08:54 AM
A search bar offers a way for users to input strings into the system. If they put the right string in, they may get more than you bargined for. Any form input always carried a potential for security vulnerabilities.
On the other hand, I thought you were modifying the main index.php file for Joomla!, which would be inherently more dangerous than just doing it with the index.php file for the template.
I tell you what, if I can find time this week I will try to learn how to create modules for Joomla! (what version are you using?) and I will see if I can come up with something for you to start playing with.
~regards
D0gSoldi3r
07-29-2008, 05:46 PM
Are you sure cause i don't want to sound like i'm taking advantage of you but if you have time to help me out with this problem that would be cool :) But yeah it's just 1 of the many templates that i have which i'm modifying, my websites on my signature below if you want to test my search bar on the top center of my page (the box not the link in the menu).
p.s i'm using Joomla 1.0
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.