[PHP-DB] mysql joining 101

2002-03-30 Thread Matthew Crouch

Here's an easy one that I can't find laid out for me anywhere:
I want a self join that pairs up the id numbers of a table in every
permutation

e.g. i have id #s 1, 2, and 3
i need this result:
1 2
1 3
2 1
2 3
3 2
3 1

clear enough?


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




[PHP-DB] Re: Database search question

2002-03-30 Thread Kim Kohen

G'day Chris

> I have 3 fields, city, country, type
> I also have an imput box where you can type in a search word.  What I need is,
> say you type in hotels germany, I need the search to break up the sentence and
> then search each 3 fields in the DB looking for a match.
> So, for example: it would find hotels in type and germany in country, see that
> they belong together and then display those results - how can I do this?

I'm far from an expert but what you're describing sounds like a classic use
of the Match command and a multi-column full text index in mysql. Of course
I don't know if you're using mysql.

cheers

kim


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




Re: [PHP-DB] Probably a stupid Array question

2002-03-30 Thread Jason Wong

On Sunday 31 March 2002 13:07, Chris Payne wrote:
> Hi there everyone,
>
> I do this to explode my input line which consists of however many words:
>
> $words = explode(" ", $testb);
>
> Now i've done this and I presume that $words holds all the info as an Array
> (new to arrays, sorry if i'm wrong) however, how can I put each item of the
> array from $words into a different string?  IE:  if there are 3 items, how
> could I have it so that the first word is stored in $word1, the second
> words is stored in $word2 etc???  Please help, thank you all so much :-)

Not sure why you want to do that. The whole point of using arrays is to 
simplify the handling of multiple 'related' variables. 

In the above example you would simply refer to the first word as $words[0], 
the second as $words[1] etc.

If you really want to do $word1, $word2 ..., then read about:

Variable Variables
foreach


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
Give me chastity and continence, but not just now.
-- St. Augustine
*/

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




RE: [PHP-DB] Probably a stupid Array question

2002-03-30 Thread Demitrious S. Kelly

$words[0] would be the first word, $words[1] would be the second word...
$words[10] would be the eleventh word, etc, etc

-Original Message-
From: Chris Payne [mailto:[EMAIL PROTECTED]] 
Sent: Saturday, March 30, 2002 9:08 PM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Probably a stupid Array question

Hi there everyone,

I do this to explode my input line which consists of however many words:

$words = explode(" ", $testb);

Now i've done this and I presume that $words holds all the info as an
Array (new to arrays, sorry if i'm wrong) however, how can I put each
item of the array from $words into a different string?  IE:  if there
are 3 items, how could I have it so that the first word is stored in
$word1, the second words is stored in $word2 etc???  Please help, thank
you all so much :-)

Regards

Chris



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




[PHP-DB] Probably a stupid Array question

2002-03-30 Thread Chris Payne

Hi there everyone,

I do this to explode my input line which consists of however many words:

$words = explode(" ", $testb);

Now i've done this and I presume that $words holds all the info as an Array (new to 
arrays, sorry if i'm wrong) however, how can I put each item of the array from $words 
into a different string?  IE:  if there are 3 items, how could I have it so that the 
first word is stored in $word1, the second words is stored in $word2 etc???  Please 
help, thank you all so much :-)

Regards

Chris



Re: [PHP-DB] Database search question

2002-03-30 Thread Mike de Libero

Hmm to do a search on one table it might actually be quicker to do a query
for every thing in the query.  First convert to all lowercase.  Then explode
the query into an array using " " as the delimiter.  Then implode this array
into a list that looks something like this.  "var1","var2"...)  you can do
this by using implode and putting Quotes at the end.  Then in the query you
can use the IN part of the query.  I'm sorry if this is totally incorrect
but I'm going off my memory.  SELECT fields FROM tbl
WHERE tblFields IN ($query)  it might be
INTO but I'm dang sure it is IN.  Go to Zend.com and phpbuilder.com for some
good resources on search engines you can modify it to suit your needs.  I
this helps a little bit.

-Mike
- Original Message -
From: "Chris Payne" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, March 30, 2002 7:15 PM
Subject: [PHP-DB] Database search question


Hi there everyone,

How can I accomplish the following?

I have a table called search,

I have 3 fields, city, country, type

I also have an imput box where you can type in a search word.  What I need
is, say you type in hotels germany, I need the search to break up the
sentence and then search each 3 fields in the DB looking for a match.

So, for example: it would find hotels in type and germany in country, see
that they belong together and then display those results - how can I do
this?

I know I need to splitup my search phrase into individual words to search,
but i'm stuck.

Thanks for any help.

Chris



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




RE: [PHP-DB] Database search question

2002-03-30 Thread J. Scott Johnson

Disclaimer: Its late, I'm tired and I haven't tested this code.  Hope it
helps.

Quick Overview:

//make your dictionaries all lower case for ease
$countries = array( 1 => 'us', 2 => 'germany', 3 => 'australia' );
$cities = array( 1 => 'new york', 2 => 'berlin', 3 => 'sydney' );
$lodging = array( 1 => 'hotel', 2 => 'motel', 3 => 'inn', 3 => 'bed and
breakfast' );

$query = "hotel germany";

//user will put it in wrong case.
$query=strtolower($query);

//loop over each array and use it to figure out what column in table to
query
foreach ($countries as $country) {
if $country
if (strstr($query, $country)) {
$column = "country";
//need to break out of loop here
}
}

Hope it helps and isn't too wrong.  I think you get the idea.  Build up some
data dictionaries that map parts of the input to the columns and the
construct query dynamically.  If you can't figure it out, generate a ui on
the fly asking "By X did you mean?" and then 3 radio buttons to set the
right column.

Scott

-Original Message-
From: Chris Payne [mailto:[EMAIL PROTECTED]]
Sent: Saturday, March 30, 2002 10:15 PM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Database search question


Hi there everyone,

How can I accomplish the following?

I have a table called search,

I have 3 fields, city, country, type

I also have an imput box where you can type in a search word.  What I need
is, say you type in hotels germany, I need the search to break up the
sentence and then search each 3 fields in the DB looking for a match.

So, for example: it would find hotels in type and germany in country, see
that they belong together and then display those results - how can I do
this?

I know I need to splitup my search phrase into individual words to search,
but i'm stuck.

Thanks for any help.

Chris


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




[PHP-DB] Database search question

2002-03-30 Thread Chris Payne

Hi there everyone,

How can I accomplish the following?

I have a table called search,

I have 3 fields, city, country, type

I also have an imput box where you can type in a search word.  What I need is, say you 
type in hotels germany, I need the search to break up the sentence and then search 
each 3 fields in the DB looking for a match.

So, for example: it would find hotels in type and germany in country, see that they 
belong together and then display those results - how can I do this?

I know I need to splitup my search phrase into individual words to search, but i'm 
stuck.

Thanks for any help.

Chris



Re: [PHP-DB] using multiple checkboxes to delete from db

2002-03-30 Thread Paul Burney

on 3/30/02 6:33 PM, wesley grubbs:. at [EMAIL PROTECTED] appended the
following bits to my mbox:

> foreach($_POST["del"] as $val) {
> 
> $sql = "DELETE FROM $tablename WHERE id = $val";

Be very careful with this.  If a user spoofs the form and adds the value for
del like this:



Would make the SQL statement:

DELETE FROM table WHERE id=2 OR 1=1

Which would, of course, delete all records in the table.

To remedy that, you could quote the value in the SQL statement and pass the
addslashed $val, like this:

$sql = "DELETE FROM $tablename WHERE id='" . addslashes($val) . "'";

That is a lot harder to get around (though perhaps still possible).

Also...

on 3/30/02 8:31 PM, Hugh Bothwell at [EMAIL PROTECTED] appended the
following bits to my mbox:

> // NOTE: this assumes that 0 is never a valid id; I just
> // stuck it in to make the comma-delimiting come out right
> $query = "DELETE FROM tablename WHERE id IN ( 0";
> 
> foreach($_POST["del"] as $val)
>   $query .= ', '.$val;
> 
> $query .= ' )';

You could use implode for things like this, i.e.,

$sql = "DELETE FROM $tablename WHERE id IN ('" .
implode("','", addslashes($_POST['del'])) . "')";

That would produce something like:

DELETE FROM table WHERE id IN ('3','4','123');

Hope that helps.

Sincerely,

Paul Burney





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




Re: [PHP-DB] using multiple checkboxes to delete from db

2002-03-30 Thread Hugh Bothwell

You can go one better than this, even...
use PHP to construct a single SQL query
using the IN( ) comparator, ie:




"Olinux" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> to make it a little better, make one connection to the
> db before you loop and then close the connection
>
> [connect]
> foreach loop
> [close connect]



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




Re: [PHP-DB] using multiple checkboxes to delete from db

2002-03-30 Thread olinux

to make it a little better, make one connection to the
db before you loop and then close the connection

[connect]
foreach loop
[close connect]

olinux

--- "wesley grubbs:." <[EMAIL PROTECTED]> wrote:
> thanks guys for the aid.
> 
> in the end, i went with creating a check box that
> looks like this:
> 
> 
> 
> and the dirty work of deleting it looks like this::
> 
> foreach($_POST["del"] as $val) {
> 
>  $sql = "DELETE FROM $tablename WHERE id = $val";
> 
> ...connect to database.. run $sql.. close db.. yadda
> yadda..
> 
> }
> 
> i can do this on the same page... it's short and
> pretty easy to follow. ...
> oh .. and it works :)
> 
> wes
> 
> 
> > One way you could do this.  Is have the form point
> to itself i.e.
> $PHP_SELF,
> > then set a variable in the form if it is set when
> the page loads the run
> the
> > form processing script.  As for the delete
> function one way to do it would
> > be since you are holding the checkboxes in an
> array.  Do a while or a for
> > loop doing the delete statement for each id.  Like
> the following code.
> >
> > for($i = 0; $i < count(chkBoxArray); $i++){
> >   $sql = "DELETE FROM tblName WHERE tblID = 
> '$row[$i]'";
> >   if(!sql_query($sql)){
> > echo "ERROR: ".mysql_query();
> >}
> > }
> >
> > Or something of that sort.  Hope it helps.
> >
> > -Mike
> > [EMAIL PROTECTED]
> > http://www.soreye.com
> 
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


__
Do You Yahoo!?
Yahoo! Greetings - send holiday greetings for Easter, Passover
http://greetings.yahoo.com/

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




Re: [PHP-DB] using multiple checkboxes to delete from db

2002-03-30 Thread wesley grubbs:.

thanks guys for the aid.

in the end, i went with creating a check box that looks like this:



and the dirty work of deleting it looks like this::

foreach($_POST["del"] as $val) {

 $sql = "DELETE FROM $tablename WHERE id = $val";

...connect to database.. run $sql.. close db.. yadda yadda..

}

i can do this on the same page... it's short and pretty easy to follow. ...
oh .. and it works :)

wes


> One way you could do this.  Is have the form point to itself i.e.
$PHP_SELF,
> then set a variable in the form if it is set when the page loads the run
the
> form processing script.  As for the delete function one way to do it would
> be since you are holding the checkboxes in an array.  Do a while or a for
> loop doing the delete statement for each id.  Like the following code.
>
> for($i = 0; $i < count(chkBoxArray); $i++){
>   $sql = "DELETE FROM tblName WHERE tblID =  '$row[$i]'";
>   if(!sql_query($sql)){
> echo "ERROR: ".mysql_query();
>}
> }
>
> Or something of that sort.  Hope it helps.
>
> -Mike
> [EMAIL PROTECTED]
> http://www.soreye.com



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




Re: [PHP-DB] How to lock the entire db?

2002-03-30 Thread Jason Wong

On Sunday 31 March 2002 03:17, andy wrote:
> Hi there,
>
> I know that there is a command lock table but what if I have hundrets of
> tables and want to copy them for backup.
>
> How could I lock the entire db and flush all tables?

Have a look at the manual for whatever database you're using.


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
The magic of our first love is our ignorance that it can ever end.
-- Benjamin Disraeli
*/

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




[PHP-DB] How to lock the entire db?

2002-03-30 Thread andy

Hi there,

I know that there is a command lock table but what if I have hundrets of
tables and want to copy them for backup.

How could I lock the entire db and flush all tables?

Thanx for any help,

Andy



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




Re: [PHP-DB] using multiple checkboxes to delete from db

2002-03-30 Thread John Hughes

I believe what you want to do is create an array with the id and delete as
separate values.

Here's an example using an array of studentdata containing variables
send_mail, this_studentname, this_paid.

The rows of students are output like this:


 
 
 


In this case all of the checkboxes are "checked."

When the form is submitted, those students who have the checkbox checked
have the variable send_mail set to Yes.

When I want to process the array it looks like this:

foreach($studentdata as $student_id => $data)
 {
  $dues_paid = $data[this_paid];
  $studentname = $data[this_studentname];
  $send_mail = $data[send_mail];
   if ($send_mail == "Yes")
  {

 # Your sql statement and processing goes here

   }# end if
}# end for each

Hope this helps.

John Hughes


- Original Message -
From: "wesley grubbs:." <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, March 30, 2002 4:58 AM
Subject: [PHP-DB] using multiple checkboxes to delete from db


> i've been playing half the day with trying to get php to delete rows when
a
> checkbox is checked.
>
> i have a page that pulls all the data from db in a table. one row contains
> checkboxes. i want it so that whereever a checkbox is checked and then
> submit, all the selected rows will be deleted.
>
> 
>  //get results from db
> while($row = mysql_fetch_array ($result)) {
> ?>
> 
> 
> 
>  }
> ?>
> 
>
> what's the proper function i should write for this?
> also, can i put the function on the same page without useing SWITCH?
> i'm trying to minimize the number of files i have.
>
> thanks in advance for any help.
> wes
> www.devedeset.com
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>


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




Re: [PHP-DB] using multiple checkboxes to delete from db

2002-03-30 Thread Mike de Libero

One way you could do this.  Is have the form point to itself i.e. $PHP_SELF,
then set a variable in the form if it is set when the page loads the run the
form processing script.  As for the delete function one way to do it would
be since you are holding the checkboxes in an array.  Do a while or a for
loop doing the delete statement for each id.  Like the following code.

for($i = 0; $i < count(chkBoxArray); $i++){
  $sql = "DELETE FROM tblName WHERE tblID =  '$row[$i]'";
  if(!sql_query($sql)){
echo "ERROR: ".mysql_query();
   }
}

Or something of that sort.  Hope it helps.

-Mike
[EMAIL PROTECTED]
http://www.soreye.com


- Original Message -
From: "wesley grubbs:." <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, March 30, 2002 4:58 AM
Subject: [PHP-DB] using multiple checkboxes to delete from db


> i've been playing half the day with trying to get php to delete rows when
a
> checkbox is checked.
>
> i have a page that pulls all the data from db in a table. one row contains
> checkboxes. i want it so that whereever a checkbox is checked and then
> submit, all the selected rows will be deleted.
>
> 
>  //get results from db
> while($row = mysql_fetch_array ($result)) {
> ?>
> 
> 
> 
>  }
> ?>
> 
>
> what's the proper function i should write for this?
> also, can i put the function on the same page without useing SWITCH?
> i'm trying to minimize the number of files i have.
>
> thanks in advance for any help.
> wes
> www.devedeset.com
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


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




[PHP-DB] using multiple checkboxes to delete from db

2002-03-30 Thread wesley grubbs:.

i've been playing half the day with trying to get php to delete rows when a
checkbox is checked.

i have a page that pulls all the data from db in a table. one row contains
checkboxes. i want it so that whereever a checkbox is checked and then
submit, all the selected rows will be deleted.









what's the proper function i should write for this?
also, can i put the function on the same page without useing SWITCH?
i'm trying to minimize the number of files i have.

thanks in advance for any help.
wes
www.devedeset.com


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




RE: [PHP-DB] Problem with PHP connectivity with mySQL (RedHat package)

2002-03-30 Thread J. Scott Johnson

For the future, run this very simple and make sure that MySQL support (or
whatever is part of your build).



Scott

-Original Message-
From: CK Raju [mailto:[EMAIL PROTECTED]]
Sent: Saturday, March 30, 2002 7:40 AM
To: Saulo Silva; [EMAIL PROTECTED]
Subject: Re: [PHP-DB] Problem with PHP connectivity with mySQL (RedHat
package)


On Saturday 30 March 2002 08:12, Saulo Silva wrote:
>Hi everybody
>
>I can't get PHP to work with mySQL. I'm using PHP as an Apache module
>(RedHat) and the error message I get is the following message:

Check out all the mysql- rpms and install the correct ones. They would
work, if you can login in to the mysql monitor.

Raju



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




Re: [PHP-DB] Problem with PHP connectivity with mySQL (RedHat package)

2002-03-30 Thread CK Raju

On Saturday 30 March 2002 08:12, Saulo Silva wrote:
>Hi everybody
>
>I can't get PHP to work with mySQL. I'm using PHP as an Apache module
>(RedHat) and the error message I get is the following message:

Check out all the mysql- rpms and install the correct ones. They would 
work, if you can login in to the mysql monitor.

Raju



** Message from InterScan E-Mail VirusWall NT **

** No virus found in attached file noname.htm

This is a virus free message scanned by Zyberway
* End of message ***




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