Re: [PHP-DB] Searching many-to-many map tables

2007-02-07 Thread J R

you must have three tables
user (have at least user_id field)
group (have at least groupd_id field)
user_group (have 2 fields: user_id and group_id, you can also have
user_group_id - depends on your need)

/* if you only need the user id */
select user_id from user_group where group_id in (1,2);

/* if you need other info */
select UG.user_id, U.*, G.*  from user_group UG left join user U on
UG.user_id = U.userid left join group G on UG.group_id = G.group_id where
UG.group_id in (1,2);


hth,
~ John


On 2/7/07, Steve McGill [EMAIL PROTECTED] wrote:


Hello,

I am trying to find out how to search a many-to-many map table
efficiently.

I have an example table:

user,user_group
1,1
1,2
2,1
3,2

I want to find out all the users who are a member of BOTH groups 1 AND 2.
In
this example, this would just be the user with id 1.

Until now, I can either do this with multiple queries and using PHP
array_intersect, or one really ugly MySQL query:

select user, count(user_group) as num_groups_found from users_groups where
group IN (1,2) GROUP BY user HAVING num_groups_found=2

i.e. narrows down the groups I'm looking for and makes sure that they are
all found for a user

It works quite reliably I think but it's such a rubbish query that I was
hoping that somebody could teach me some syntax that is better.

Many thanks in advance,
Steve

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





--
GMail Rocks!!!


Re: [PHP-DB] retaining form information when someone presses back

2007-01-01 Thread J R

try using:
header http://www.php.net/header(Cache-control: private);

i'm not sure that will work, try playing with header cache-control. anyway
as Bastien metioned it is better to have your form redisplayed with values
the user entered when validation failed rather than asking the user to click
the back button of their browser.

try this sample (not tested, too lazy :) but should work):
?php

$var1= NULL;
$var2= NULL;

if (isset($_POST)) {
   $var1= $_POST['var1'];
   $var2= $_POST['var2'];
}

echo 'form method=\'post\'';
echo input type='text' name='var1' value='$var1' /;
echo input type='text' name='var2' value='$var2' /;
echo 'input type=\'submit\'';
echo '/form';

?

On 1/1/07, Flint Million [EMAIL PROTECTED] wrote:


This might not be relavent for this forum, so if not please direct me
to the proper one; although I do like to keep my email list
subscriptions down.

I have a custom application in PHP in which a user fills out a form of
information. When the user submits, I perform sanity checking on the
user's submitted data and refuse to actually process/insert it if
those checks fail. However, my users are complaining that when they
press back to correct, all the data is gone from the form and they
have to re-enter it all. I know many websites that can retain the form
data when someone presses back; how is this done?

Flint M

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





--
GMail Rocks!!!


Re: [PHP-DB] Generating pages with full stories

2006-11-13 Thread J R

Here's how you should do this (IMHO):

On you front page make a sql query say you want to display the latest 3
events. Your query probably will look like this:

select event_table_id, title from event_table order by date_created desc
limit 3;

then from the result make a while or for loop (for example your result is
stored in an array $aResult)

foreach ($aResult as $value) {
   echo 'a
href=eventFullStories.php?eventId='.$value['event_table_id'].''.$value['title'].'/a;
}


Then on your eventFullSyories.php just query the event_table for that
eventId and display the event full story.


hth,
john

On 11/14/06, [EMAIL PROTECTED] [EMAIL PROTECTED]
wrote:


I'd answer question number 3.

Well, it is just about an update section that the administrators will
input on the database for updates and event for a company, saying the
website has an updated page or simply putting an event for the public to
know.

Right now, I want to know how get a URL like this:

http://www.myhomepage.com/thispage.php?variable1=value_X?var2=val_Y

Using anchor (link) tags, not from form tags.

 Yes...

 But, the experts on this list need more info in order to help you out.

 1. Where are the stories going to come from? If you plant to take news
 stories from other sites and use them on your own site, there are
 serious legal issues involved.

 2. If you want to write the stories yourself, or invite visitors to
 write your stories, then you probably want a simple content management
 system using PHP and MySQL. There are a lot of them about. Google or ask
 for recommendations.

 3. If you'd prefer to make the site yourself in order to learn PHP +
 MySQL programming, you can find lots of tutorials. Google PHP Tutorials
 and look around.

 Good luck,

 Jeffrey


 [EMAIL PROTECTED] wrote:
 I've got a website using PHP and MySQL. I would like to make a news
 preview on the webpage's frontpage with a link to the full story.

 Is it possible to use one (1) .PHP file to generate full stories, with
 MySQL involved?

 I'm just a newcomer in the world of PHP but I am doing my best in
 reading
 materials for PHP.

 Thanks in advance.



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





--
GMail Rocks!!!


Re: [PHP-DB] month

2006-10-15 Thread J R

search the archive.

On 10/16/06, Ron Piggott (PHP) [EMAIL PROTECTED] wrote:


I have completely missed it and need to try again.





--
GMail Rocks!!!


Re: [PHP-DB] Distinct Partial Matches: RegExp

2006-08-30 Thread J R

i'm a bit confused. if i'm getting you right heres my 2 cents:

first you do sql query using DISTINCT

when the result are returned to you, you can then run thru the result array
using preg_replace. heres an example:

$aVar= array(
   'animal-dog-5',
   'animal-dog-3',
   'animal-cat-1',
   'animal-cat-22',
   'animal-bird-5',
   );

$aResult= array();
foreach ($aVar as $value) {
   $tmp= preg_replace('/-\d*$/', '', $value);
   $aResult[$tmp]= $tmp;
   // if you want to conserve a bit of resources asign NULL;
   // $aResult[$tmp]= NULL;
}
var_dump($aResult);


hth,

john

p.s.
i'm not sure if it is possible to use regular expression in a sql query. can
anyone comment on this? thanks.

On 8/31/06, Kevin Murphy [EMAIL PROTECTED] wrote:


Well, its not really a search that would be way easier. :-) What
I'm looking for is a query that will give me the complete list of
items that are distinct, minus the last number after the last hyphen.

animal-dog
animal-cat
animal-bird

--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326


On Aug 30, 2006, at 4:34 PM, Micah Stevens wrote:


 Select DISTINCT area from table like '$searchterms%';

 In SQL, you can use the 'LIKE' keyword along with the '%' and '_'
 wildcards.. '_' is one character, '%' is any number of chars.

 -Micah


 Kevin Murphy wrote:
 This might be really easy, but I'm just not sure how to write this
 query and my searching on google isn't finding me things, probably
 because I am searching for the wrong terms.

 I have a bunch of records where the area column is like:

 animal-dog-5
 animal-dog-3
 animal-cat-1
 animal-cat-22
 animal-bird-5

 What I want to do is run a distinct query on just the part
 previous to the number.

 animal-dog
 animal-cat
 animal-bird

 So in other words, something like this, but I am not sure if this
 is the right way to go:

 $query = SELECT DISTINCT area FROM table WHERE REGEXP
 'anynumberofletters dash anynumberofletters dash '


 Of course, I could be barking up the wrong tree with the REGEXP
 thing. Anyone care to point me in the right direction?


 --Kevin Murphy
 Webmaster: Information and Marketing Services
 Western Nevada Community College
 www.wncc.edu
 775-445-3326




 --Kevin Murphy
 Webmaster: Information and Marketing Services
 Western Nevada Community College
 www.wncc.edu
 775-445-3326










--
GMail Rocks!!!


Re: [PHP-DB] Distinct Partial Matches: RegExp

2006-08-30 Thread J R

thanks for the info. didn't know this. :). i'll be googling how this is
done. :D and perhaps post back a solution to your problem kevin, if i find
one :).

On 8/31/06, Micah Stevens [EMAIL PROTECTED] wrote:



You can do regular expression matching in MySQL and I think a few other
servers too, but that's not the same as regular expression replacement
like you can do with PHP.. It just returns a boolean true/false
depending on whether or not the match works.

-Micah

J R wrote:
 i'm a bit confused. if i'm getting you right heres my 2 cents:

 first you do sql query using DISTINCT

 when the result are returned to you, you can then run thru the result
 array
 using preg_replace. heres an example:

 $aVar= array(
'animal-dog-5',
'animal-dog-3',
'animal-cat-1',
'animal-cat-22',
'animal-bird-5',
);

 $aResult= array();
 foreach ($aVar as $value) {
$tmp= preg_replace('/-\d*$/', '', $value);
$aResult[$tmp]= $tmp;
// if you want to conserve a bit of resources asign NULL;
// $aResult[$tmp]= NULL;
 }
 var_dump($aResult);


 hth,

 john

 p.s.
 i'm not sure if it is possible to use regular expression in a sql
 query. can
 anyone comment on this? thanks.

 On 8/31/06, Kevin Murphy [EMAIL PROTECTED] wrote:

 Well, its not really a search that would be way easier. :-) What
 I'm looking for is a query that will give me the complete list of
 items that are distinct, minus the last number after the last hyphen.

 animal-dog
 animal-cat
 animal-bird

 --
 Kevin Murphy
 Webmaster: Information and Marketing Services
 Western Nevada Community College
 www.wncc.edu
 775-445-3326


 On Aug 30, 2006, at 4:34 PM, Micah Stevens wrote:

 
  Select DISTINCT area from table like '$searchterms%';
 
  In SQL, you can use the 'LIKE' keyword along with the '%' and '_'
  wildcards.. '_' is one character, '%' is any number of chars.
 
  -Micah
 
 
  Kevin Murphy wrote:
  This might be really easy, but I'm just not sure how to write this
  query and my searching on google isn't finding me things, probably
  because I am searching for the wrong terms.
 
  I have a bunch of records where the area column is like:
 
  animal-dog-5
  animal-dog-3
  animal-cat-1
  animal-cat-22
  animal-bird-5
 
  What I want to do is run a distinct query on just the part
  previous to the number.
 
  animal-dog
  animal-cat
  animal-bird
 
  So in other words, something like this, but I am not sure if this
  is the right way to go:
 
  $query = SELECT DISTINCT area FROM table WHERE REGEXP
  'anynumberofletters dash anynumberofletters dash '
 
 
  Of course, I could be barking up the wrong tree with the REGEXP
  thing. Anyone care to point me in the right direction?
 
 
  --Kevin Murphy
  Webmaster: Information and Marketing Services
  Western Nevada Community College
  www.wncc.edu
  775-445-3326
 
 
 
 
  --Kevin Murphy
  Webmaster: Information and Marketing Services
  Western Nevada Community College
  www.wncc.edu
  775-445-3326
 
 
 
 










--
GMail Rocks!!!


Re: [PHP-DB] Direct Access to an Array Item?

2006-08-09 Thread J R

On 8/9/06, Peter Beckman [EMAIL PROTECTED] wrote:


I want to access a variable within a function-returned array without
setting the array to a variable first.  Example -- test for equal to
string
'foo' on the 4th element of a returned fetch row:

 if (($row = mysql_fetch_row($result))[3] == 'foo') {
 $user = $row;
 }

or

 $bar = explode('#', $str)[2];



i don't think it is possible to do such syntax. nor theres a work around on
to make it way you want it. (i'm not an expert. just IMHO)

I know I can do this in perl, but can it be done in PHP?  Obviously this is

pseudo code, it doesn't actually work, but I wonder if there is a way that
escapes me currently?

I know I can assign the result to a variable and then test the element; I
am addicted to trying to cut down the amount and complexity of code.  Even
if you disagree with my goal as good computing practices,



i agree, its not a good programming practice and its makes your code less
readable. :)

I simply want to

know if what I ask is possible, and if so, how. :-)

Beckman

---
Peter Beckman  Internet
Guy
[EMAIL PROTECTED]
http://www.purplecow.com/

---

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





--
GMail Rocks!!!


[PHP-DB] Direct Access to an Array Item?

2006-08-09 Thread J R

On 8/9/06, Peter Beckman [EMAIL PROTECTED] wrote:


I want to access a variable within a function-returned array without
setting the array to a variable first.  Example -- test for equal to
string
'foo' on the 4th element of a returned fetch row:

 if (($row = mysql_fetch_row($result))[3] == 'foo') {
 $user = $row;
 }

or

 $bar = explode('#', $str)[2];



i don't think it is possible to do such syntax. nor theres a work around on
to make it way you want it. (i'm not an expert. just IMHO)

I know I can do this in perl, but can it be done in PHP?  Obviously this is

pseudo code, it doesn't actually work, but I wonder if there is a way that
escapes me currently?

I know I can assign the result to a variable and then test the element; I
am addicted to trying to cut down the amount and complexity of code.  Even

if you disagree with my goal as good computing practices,



i agree, its not a good programming practice and its makes your code less
readable. :)

I simply want to

know if what I ask is possible, and if so, how. :-)

Beckman

---
Peter Beckman  Internet
Guy
[EMAIL PROTECTED]
http://www.purplecow.com/
---


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





--
GMail Rocks!!!


--
GMail Rocks!!!


Re: [PHP-DB] Uploading multiple files?

2006-07-04 Thread J R

got curious of evans question. is there a way whithout having multiple
input type=file ... form to upload multiple files. only one input
field but when browse is click and the file selection window poped, multiple
files can be selected at once and then uploaded.

thanks.

john

On 7/4/06, Bastien Koert [EMAIL PROTECTED] wrote:


http://www.sitepoint.com/article/php-gallery-system-minutes is a great
aticle with code on this...

bastien


From: Skip Evans [EMAIL PROTECTED]
To: PHP DB php-db@lists.php.net
Subject: [PHP-DB] Uploading multiple files?
Date: Mon, 03 Jul 2006 15:08:48 -0600

Hey all,

I have a client who uses a Java applet to allow site members upload
multiple files (photos) at a time, as many as 40 or 50 sometimes, to his
site.

He wants to get away from the applet and use a PHP solution that will fit
more seamlessly into his site, but it still must be able to upload
multiple
files.

Does anyone know of a way to construct a form such that multiple files
can
be highlighted in a single stroke, brought into say a textarea type
field,
and then uploaded?

I can't think of a way to do this, so anyone that can point me in the
right
direction would be most appreciated.

Thanks!
--
Skip Evans
Big Sky Penguin, LLC
61 W Broadway
Butte, Montana 59701
406-782-2240

--
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





--
GMail Rocks!!!


Re: [PHP-DB] Uploading multiple files?

2006-07-04 Thread J R

k thanks chris. guesse we need to wait for more browser to support it. for
now its good as it can't be done.

On 7/5/06, Chris [EMAIL PROTECTED] wrote:


J R wrote:
 got curious of evans question. is there a way whithout having multiple
 input type=file ... form to upload multiple files. only one input
 field but when browse is click and the file selection window poped,
 multiple
 files can be selected at once and then uploaded.

I was going to say no, but then I found this:


http://www.cs.tut.fi/~jkorpela/forms/file.html#multi

Note that there is nothing an author needs to do, and nothing he can do,
to make a browser allow the selection of several files per input field.
It depends on the browser whether that is possible.


Not sure which browsers do support this though.

--
Postgresql  php tutorials
http://www.designmagick.com/





--
GMail Rocks!!!


Re: [PHP-DB] Conditional updating...

2006-06-28 Thread J R

try this one.

just pass for $_value an array with your table fieldname as your key

   function constructUpdate( $_tbl_name, $_where, $_values )
   {
   $valstr = '';
   $firstval = false;
   if (is_array($_values)) {
   foreach( $_values as $key=$val ) {
   if ($val != '') {
   if( $firstval )
   $valstr.= ',';

   if (is_string($val)) {
   $valstr.=  $key = '$val';
   } else {
   $valstr.=  $key = $val;
   }
   $firstval = true;
   }
   }
   } else {
   $valstr= $_values;
   }
   $retStr = update $_tbl_name set $valstr;
   if( $_where )
   $retStr.=  where $_where;

   return $retStr;
   }


Re: [PHP-DB] Question in js about frameset rows

2006-06-21 Thread J R

appologies to the list. i think this should not be asked here. anyway i'll
answer.

IMHO, there is no easy way to do what you like. what i would suggest is use
document.write() or inclosing your frameset in a container div then
dynamically change it using innerHTML

hth

On 6/21/06, suad [EMAIL PROTECTED] wrote:


Hi,

I have this page:

html
head
titletitle1/title
/head
frameset cols=*,200px
  frameset id=frameset1 rows=10%,30%,10%,*
frame src=/page1.phtml name=name1 frameborder=0 scrolling=no
/
frame src=/page2.phtml name=name2 frameborder=0 /
frame src=/page3.phtml name=name3 frameborder=0 scrolling=no
/
frame src=/page4.phtml name=name4 frameborder=0 /
  /frameset
  frame src=/page5.phtml name=name5 frameborder=0 /
/frameset
/html

And this is the content of the page page1.phtml:

html
head
titlename1/title
/head
body
span onclick=alert(window.parent.frames[1].name);change size of
frame 2/span
/body
/html

How can I change (using js) the rows of the frameset to:
frameset rows=10%,10%,10%,*

Thanks
Suad

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





--
GMail Rocks!!!


Re: [PHP-DB] PHPSESSID how to append and access

2006-05-25 Thread J R

On 5/25/06, Girish Agarwal [EMAIL PROTECTED] wrote:


Hi All,
 I am using header(Location:
http://dv-medical/phpscripts/test.php;) function to hop from one Page to
Another in My Web Application
My Problem is I have been unable to get the exact syntax to append
the Session ID to the URL specified in the header so that it is available



you could do this:
header(Location: http://dv-medical/phpscripts/test.php?sid=.session_id())


   If I am not mistaken then with the header function the Session ID is

not automatically appended eventhough enable_trans_sid is set to true.If I
am wrong then please guide me as to how I can access the session id.
My php.ini file has session.name has PHPSESSID.

Thanks,
Girish

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





--
GMail Rocks!!!


Re: [PHP-DB] Reg Exp to change c:\dir\dir\pic.jpg to dir/pic.jpg - to upload image path

2005-02-10 Thread J R
now if you must have the local path of your file here's a rough code
to give you an idea using javascript, then just have it php control it
on the server side.

form action= method=post enctype=multipart/form-data name=form_upload
input type=file name=file_upload onChange=javascript:
document.forms[0].file_upload_path.value =
document.forms[0].file_upload.value
input type=text name=file_upload_path value=
/form

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



[suspicious - maybe spam] [PHP-DB] [suspicious - maybe spam] Re: [PHP-DB] Reg Exp to change c:\dir\dir\pic.jpg to dir/pic.jpg - to upload image path

2005-02-09 Thread J R
hi you don't have to bother your self of such things. html does it all
for you. All you have to do is manage the uploaded file which is put
as a temporary file on the server temporary folder. Here's some tip:

temporary file in your server: $_FILES[file][tmp_name] 
name of your file (the uploaded): $_FILES[file][name]

now use move_uploaded_file  function to where ever location you want
to put your file on your server.

 http://ph.php.net/manual/en/function.move-uploaded-file.php  


cheers!



On Wed, 09 Feb 2005 14:44:07 -0500, Bastien Koert [EMAIL PROTECTED] wrote:
 Whats the reason to keep the image path from the host pc?
 
 The server will dump the uploaded file into a temp area fro which you can
 either move it to a permanent dir or load it into a db. The only path that
 you really need to worry about the one on the server, which you can handle
 by
 
 1. leaving it fixed and coding it into your scripts
 2. make it somewhat variable (if you were storing images by username or
 something like that) which you can handle by storing in the db.
 
 Once the image is uploaded, there is no use for the user's path. If he
 changes OSs its gone and of no value...
 
 Bastien
 
 From: ioannes [EMAIL PROTECTED]
 To: php-db@lists.php.net
 Subject: [PHP-DB] Reg Exp to change c:\dir\dir\pic.jpg to dir/pic.jpg - to
 upload image path
 Date: Wed, 9 Feb 2005 19:14:14 -
 
 I am trying to upload images - in fact an image path - from a PC.
 
 I use the input  tag:
 
 INPUT NAME=addpic TYPE=file
 
 which nicely gives an input textfield and Browse button!  This gives me, in
 the input box, eg:
 
 c:\pics\subdir\pic1.jpg
 
 The relative path on the server is something like:
 
 subdir/pics1.jpg
 
 thus I need to transform the string:
 
 c:\subdir\pics\pics1.jpg
 
 into:
 
 pics/pics1.jpg
 
 
 I can use str_replace() to change \ into /.  I am looking for an
 expression from some clever person to get rid of c:\subdir\ given that I
 don't know the exact 'subdir' or name of the image.
 
 Regards,
 
 John
 
 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


-- 
GMail Rocks!!!

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



Re: [PHP-DB] NLP to SQL queries

2005-02-08 Thread J R
http://pear.php.net/manual/en/package.database.php

good luck

On Mon, 7 Feb 2005 17:09:22 +, Jonathan Trepczyk
[EMAIL PROTECTED] wrote:
 hiya guys, just trying to find the best way of translating natural
 language queries to sql queries to put in a website, i will be glad if
 you can help or point me towards the right direction
 
 Thanks for your help
 
 Jonathan
 
 --
 Jonathan Trepczyk
 
 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


-- 
GMail Rocks!!!

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