Re: [PHP] Search script problem

2007-01-07 Thread Jochem Maas
Wikus Moller wrote:
 Hi.
 
 I am having problems with a script I wrote which searches keywords
 from a field in a mysql db table.
 
 It is a very simple,  one-page script. My site is a toplist, very
 basic, still in it's infancy. When I go to the page, key in the
 keywords and press submit, the head, body etc. part of the result
 script is shown, but no results.
 , although there are rows in my database containing the `keyword` field
 data.
 
 Below is the script, please see if you find any errors, it could be
 that I just made a stupid mistake.

imho your first stupid mistake was writing a script that bloody
unmanagable.

1. check you input
2. do some processing
3. ouput your page (including any error msgs from step 1 and 2)

this is in contrast to the tactic your using, namely: dump some output,
do something, dump more output, perform a query, dump some output, do
stuff, dump some output in a loop, do stuff, dump some output, etc.

P.

read on ...

 
 ?php
 
 echo ?xml version=\1.0\ encoding=\UTF-8\?;
 echo !DOCTYPE HTML PUBLIC \-//W3C//DTD XHTML Mobile 1.0//EN\
 \http://www.wapforum.org/DTD/xhtml-mobile10.dtd\;;
 echo html xmlns=\http://www.w3.org/1999/xhtml\;;
 
 error_reporting(E_ALL ^ E_NOTICE);
 
 $pwd = $_GET[pwd];
 $uid = $_GET[uid];
 $action = $_GET[action];
 $cid = $_GET[cid];
 $sid = $_GET[sid];
 $var = $_GET[q];


echo 'is this your expected input? : pre';
var_dump($_GET)
echo '/pre';

 
 include (function.php);
 include (config.php);
 connect($dbserver,$dbname,$dbuser,$dbpass);
 
 
 
 /Search main page
 if(!isset($var)){
 echo head;
 echo titleSearch Engine/title;
 echo style type=\text/css\
 .m3 {background-color: #291C6F;}
.n1 {background-color: #A0A0A0;}
.n2 {background-color: #88;}
 .c2 {color: #00;}
 .m2 {color: #91D0FF;}
 body   {font-family: Arial, sans-serif;
 font-size: 12px;
 color: #ff;
 background-color: #33;
 margin-left: 0px;
 margin-right: 0px;
 margin-top: 0px;}
 .ct1 {font-family: Arial, sans-serif;
 font-size: 12px;
 color: #800080;}
 .cre {background-color: #1300A4;
 padding: 2px 2px 2px 2px;
 margin: 3px 0 0;
 font-size: 12px;
 color:#00;
 text-align: center;
 border-width:1px 0;
 border-style:solid;
 border-color:#00;}

use a css file and save a bit of band width (and scrolling in my case).

 /style;
 echo /head;
 echo body;
 echo table;
 echo div class=\cre\;
 echo bSearch Engine/b/div;
 echo form method=\GET\
 action=\search.php?uid=$uidamp;pwd=$pwd\; ///the uid and pwd is
 nessecary cause my member features are very basic and the urls is used
 to keep the user 'logged in'

basic is the wrong word if your are thinking in terms of security -
non-existent is closer to the truth. http://phpsec.org is a good place to
and learn about security on all [php] fronts

 echo Keywords: input type=\text\ name=\q\ /br/;
 echo input type=\submit\ name=\Submit\/;
 echo /form;
 echo /table;
 echo div class=\cre\img src=\images/home.gif\ alt=\*\/a
 href=\index.php?uid=$uidamp;pwd=$pwd\Home/a/div;
 echo /body;
 echo /html;
 }
 
 ///Display Results
 
 if(isset($var)){

the following line is pointless given the line about and the
fact that you have already set $var in exactly the same way at the
top of your script.

 $var = $_GET[q];
 $trimmed = trim($var); //trim whitespace from the stored variable
 echo head;
 echo titleSearch Results/title;
 echo style type=\text/css\
 .m3 {background-color: #291C6F;}
.n1 {background-color: #A0A0A0;}
.n2 {background-color: #88;}
 .c2 {color: #00;}
 .m2 {color: #91D0FF;}
 body   {font-family: Arial, sans-serif;
 font-size: 12px;
 color: #ff;
 background-color: #33;
 margin-left: 0px;
 margin-right: 0px;
 margin-top: 0px;}
 .ct1 {font-family: Arial, sans-serif;
 font-size: 12px;
 color: #800080;}
 .cre {background-color: #1300A4;
 padding: 2px 2px 2px 2px;
 margin: 3px 0 0;
 font-size: 12px;
 color:#00;
 text-align: center;
 border-width:1px 0;
 border-style:solid;
 border-color:#00;}
 /style;
 echo /head;
 echo body;
 echo div class=\cre\;
 echo bSearch Results/b/div;
 echo table;
 // Get the search variable from URL
 
 
 
 // check for an empty string and display a message.
 if ($trimmed == )
  {
  echo Please enter a search...;
  exit;
  }
 
 
 
 if($pg==0)$pg=1;
  $pg--;
  $lmt = $pg*20;
  $pg++;
  $cou =$lmt+1;

is your table called 'table'? that is the WORST name in the world for
a table - and it will break your queries unless you stick them in 

Re: [PHP] Search script problem

2007-01-07 Thread Jochem Maas
please keep it on the list.

Wikus Moller wrote:
 Let me repeat myself, SIMPLE, this was just the starting point.

niether 'simple' or 'starting point' equate to 'ugly' or 'shit'
though do they. even simple scripts deserve error checking and
a managable layout.

I wasn't pointing that out to make you feel bad but to give you a
leg up in better script writing ...

 
 The error was caused due to a field being created after there were
 already rows in the table.

that *shouldn't* cause you any errors. the most likely reason it
did is your scripts assumption of the physical field order of your table.

I would recommend not using mysql_fetch_array() instead switch to
mysql_fetch_assoc() and reference the elements in the returned array
by name rather than by number - this has 2 advantages:

1. you won't get bitten by fields that were added to the table after
the script was written.
2. the output you generate using the returned array is alot more understandable:

e.g. $row['name'] as compared to $row[0]

 
 It works like a dream and now I will correct the errors you pointed
 out and which you assumed I didn't know and which had no relevance to
 my query after I stated so boldly that it was simple.

a. I merely assumed that you *may* not be aware of the things I pointed
out, if you are aware of those points then there was really no harm done,
if you weren't then you would have been armed some new info ...

b. you can't control the answer, only the question, stop trying :-)

 
 Thanks

...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Search script problem

2007-01-07 Thread Jochem Maas
top posting.

what sucks?

-

still having trouble keeping your posts on lists?
if you want to put me in my place, that's fine but please
keep it on list where it belongs - if only because private flames
wars are so boring.

Wikus Moller wrote:
 Oops, I gave you the wrong link, here is the correct one where you can
 gain some knowledge:
 
 http://google.com/search?q=How+to+answer+questions+without+trying+to+look+smart
 

firstly, I can't actually see anything very specific to the query in the 
results.
secondly the first item in the results is primarily aimed at *you* (given that
you asked the question).

with regard to this page: http://catb.org/~esr/faqs/smart-questions.html
I am aware of it, I've read it a number of times, it's been posted on this
list numerous times and at least 1 long time list member actually carries the
link in his signature.

with regard to the last section on that page entitled
'How To Answer Questions in a Helpful Way' I don't feel I
transgressed any on of the points made, other than possibly 'be gentle' -
obviously you didn't consider it a gentle reply but it was comparitively gentle
by my usual standards.

with regard to looking smart - I don't kind looking smart at all, I consider 
myself
smart  *reasonably* knowledge with regard to using php - not perfect, not 
gifted, not
exceptional in anyway, but smart nonetheless. if that makes you feel inferior
you have one simple recourse - become, in your mind, smarter than me :-) I'll 
welcome
it, it would mean one more mind on this list capable of solving problems and
help raise the level of php hacking in general.

 
 
 On 1/8/07, Wikus Moller [EMAIL PROTECTED] wrote:
 Thats fine with me ^.^

 Here are some tips for you when you answer a question next time:

 http://google.com/search?p=How+to+answer+a+question+without+trying+to+look+smart


 Thanks
 Wikus


 On 1/7/07, Jochem Maas [EMAIL PROTECTED] wrote:
  please keep it on the list.
 
  Wikus Moller wrote:
   Let me repeat myself, SIMPLE, this was just the starting point.
 
  niether 'simple' or 'starting point' equate to 'ugly' or 'shit'
  though do they. even simple scripts deserve error checking and
  a managable layout.
 
  I wasn't pointing that out to make you feel bad but to give you a
  leg up in better script writing ...
 
  
   The error was caused due to a field being created after there were
   already rows in the table.
 
  that *shouldn't* cause you any errors. the most likely reason it
  did is your scripts assumption of the physical field order of your
 table.
 
  I would recommend not using mysql_fetch_array() instead switch to
  mysql_fetch_assoc() and reference the elements in the returned array
  by name rather than by number - this has 2 advantages:
 
  1. you won't get bitten by fields that were added to the table after
  the script was written.
  2. the output you generate using the returned array is alot more
  understandable:
 
  e.g. $row['name'] as compared to $row[0]
 
  
   It works like a dream and now I will correct the errors you pointed
   out and which you assumed I didn't know and which had no relevance to
   my query after I stated so boldly that it was simple.
 
  a. I merely assumed that you *may* not be aware of the things I pointed
  out, if you are aware of those points then there was really no harm
 done,
  if you weren't then you would have been armed some new info ...
 
  b. you can't control the answer, only the question, stop trying :-)
 
  
   Thanks
 
  ...
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Search script problem

2007-01-06 Thread Wikus Moller

Hi.

I am having problems with a script I wrote which searches keywords
from a field in a mysql db table.

It is a very simple,  one-page script. My site is a toplist, very
basic, still in it's infancy. When I go to the page, key in the
keywords and press submit, the head, body etc. part of the result
script is shown, but no results.
, although there are rows in my database containing the `keyword` field data.

Below is the script, please see if you find any errors, it could be
that I just made a stupid mistake.

?php

echo ?xml version=\1.0\ encoding=\UTF-8\?;
echo !DOCTYPE HTML PUBLIC \-//W3C//DTD XHTML Mobile 1.0//EN\
\http://www.wapforum.org/DTD/xhtml-mobile10.dtd\;;
echo html xmlns=\http://www.w3.org/1999/xhtml\;;

error_reporting(E_ALL ^ E_NOTICE);

$pwd = $_GET[pwd];
$uid = $_GET[uid];
$action = $_GET[action];
$cid = $_GET[cid];
$sid = $_GET[sid];
$var = $_GET[q];

include (function.php);
include (config.php);
connect($dbserver,$dbname,$dbuser,$dbpass);



/Search main page
if(!isset($var)){
echo head;
echo titleSearch Engine/title;
echo style type=\text/css\
.m3 {background-color: #291C6F;}
.n1 {background-color: #A0A0A0;}
.n2 {background-color: #88;}
.c2 {color: #00;}
.m2 {color: #91D0FF;}
body   {font-family: Arial, sans-serif;
font-size: 12px;
color: #ff;
background-color: #33;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;}
.ct1 {font-family: Arial, sans-serif;
font-size: 12px;
color: #800080;}
.cre {background-color: #1300A4;
padding: 2px 2px 2px 2px;
margin: 3px 0 0;
font-size: 12px;
color:#00;
text-align: center;
border-width:1px 0;
border-style:solid;
border-color:#00;}
/style;
echo /head;
echo body;
echo table;
echo div class=\cre\;
echo bSearch Engine/b/div;
echo form method=\GET\
action=\search.php?uid=$uidamp;pwd=$pwd\; ///the uid and pwd is
nessecary cause my member features are very basic and the urls is used
to keep the user 'logged in'
echo Keywords: input type=\text\ name=\q\ /br/;
echo input type=\submit\ name=\Submit\/;
echo /form;
echo /table;
echo div class=\cre\img src=\images/home.gif\ alt=\*\/a
href=\index.php?uid=$uidamp;pwd=$pwd\Home/a/div;
echo /body;
echo /html;
}

///Display Results

if(isset($var)){
$var = $_GET[q];
$trimmed = trim($var); //trim whitespace from the stored variable
echo head;
echo titleSearch Results/title;
echo style type=\text/css\
.m3 {background-color: #291C6F;}
.n1 {background-color: #A0A0A0;}
.n2 {background-color: #88;}
.c2 {color: #00;}
.m2 {color: #91D0FF;}
body   {font-family: Arial, sans-serif;
font-size: 12px;
color: #ff;
background-color: #33;
margin-left: 0px;
margin-right: 0px;
margin-top: 0px;}
.ct1 {font-family: Arial, sans-serif;
font-size: 12px;
color: #800080;}
.cre {background-color: #1300A4;
padding: 2px 2px 2px 2px;
margin: 3px 0 0;
font-size: 12px;
color:#00;
text-align: center;
border-width:1px 0;
border-style:solid;
border-color:#00;}
/style;
echo /head;
echo body;
echo div class=\cre\;
echo bSearch Results/b/div;
echo table;
// Get the search variable from URL



// check for an empty string and display a message.
if ($trimmed == )
 {
 echo Please enter a search...;
 exit;
 }



if($pg==0)$pg=1;
 $pg--;
 $lmt = $pg*20;
 $pg++;
 $cou =$lmt+1;
 $scount = mysql_fetch_array(mysql_query(SELECT COUNT(*) FROM table
WHERE keywords like \%$trimmed%\ AND banned='0' AND hitsin =
'2'));
 $pgs = ceil($scount[0]/20);
 // Build SQL Query
 $sql = SELECT * FROM table WHERE keywords like \%$trimmed%\ AND
banned='0' and hits_in ='2' ORDER by hin DESC LIMIT .$lmt., 20;;
// EDIT HERE and specify your table and field names for the SQL query
 $sites=mysql_query($sql);


while ($site = mysql_fetch_array($sites))
{
   $dscr =htmlspecialchars($site[11]);
   $snm=htmlspecialchars($site[1]);
   echo trtd align=\left\a
href=\index.php?action=vsiteamp;sid=$site[0]amp;uid=$uidamp;pwd=$pwd\$snm/a/td/tr;
   echo trtd align=\left\$dscr/td/tr;
   $cou++;
}
$npage = $pg+1;
$ppage = $pg-1;
if($pg$pgs)
//this is just for clicking on the 

[PHP] Search Script????

2004-01-20 Thread Student
I have my web site with file extensions .php .php3 .html .htm .shtml  Now i
(am looking for a script or) would like to write a php script so that users
can search my web site for information Can anyone help me get started.
I want to include a search in my web site..

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Search Script????

2004-01-20 Thread John Nichel
Student wrote:

I have my web site with file extensions .php .php3 .html .htm .shtml  Now i
(am looking for a script or) would like to write a php script so that users
can search my web site for information Can anyone help me get started.
I want to include a search in my web site..
Cross post bad.  Mean people come and bite off your kneecaps.

--
By-Tor.com
It's all about the Rush
http://www.by-tor.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] search script

2003-02-24 Thread Bryan Brannigan
Ok, my problem of the day.  I need to take a field from a form that has either a first 
name, last name or both and then search the database for all records that match one of 
those items.  The problem, the database only has one field for the name.. where both 
the first and last name are stored.

Is there anyway I can do this?

Re: [PHP] search script

2003-02-24 Thread Ernest E Vogelsinger
At 18:40 24.02.2003, Bryan Brannigan spoke out and said:
[snip]
Ok, my problem of the day.  I need to take a field from a form that has 
either a first name, last name or both and then search the database for all 
records that match one of those items.  The problem, the database only has 
one field for the name.. where both the first and last name are stored.

Is there anyway I can do this?
[snip] 

$atokens = explode(' ', $_REQUEST['name']);
$sql = null;
foreach ($atokens as $name)
$sql .= ($sql ? 'or ') . name ilike '%$name%';
$sql = 'select * from tablename where name ' . $sql;

this is for PostgreSQL; for MySQL replace ilike '%$name%' with 
INSTR(name,'$lname')  0

Disclaimer: completely untested.


-- 
   O Ernest E. Vogelsinger 
   (\) ICQ #13394035 
^ http://www.vogelsinger.at/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php