[PHP-DB] Help with JOIN query

2008-03-06 Thread Graham Cossey
I can't see how to accomplish what I need so if anyone has any
suggestions they would be gratefully received...

I'm using mysql 4.0.20 by the way.

I have two tables :

TableA
record_id
product_ref

TableB
timestamp
record_id
action

I want to create a SELECT that joins these 2 tables where the JOIN to
TableB only returns the most recent entry by timestamp.

At present (using PHP) I do a SELECT on TableA then for each record
returned I perform a 2nd SELECT something like :

SELECT timestamp, action FROM TableB WHERE record_id = '$record_id'
ORDER BY timestamp DESC LIMIT 1

I now want to do it with one query to enable sorting the results by
'action' from TableB.

Any suggestions?

Hopefully I've made sense, if not I'll happily try and explain further
on request.

-- 
Graham

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



Re: [PHP-DB] Help with JOIN query

2008-03-06 Thread Graham Cossey
On Thu, Mar 6, 2008 at 6:54 PM, Krister Karlström
[EMAIL PROTECTED] wrote:
 Hi!


  Graham Cossey wrote:

   TableA
   record_id
   product_ref
  
   TableB
   timestamp
   record_id
   action
  
   I want to create a SELECT that joins these 2 tables where the JOIN to
   TableB only returns the most recent entry by timestamp.

  For instance, to select all columns:

  select * from TableA
  join TableB on TableA.record_id = TableB.record_id
  order by timestamp desc
  limit 1

  So you just join everything, then order by time in descening order and
  then just returning the first record = the newest record in the
  database. If you don't want all columns, then simply replace the star
  with the names of the columns you want.

  I hope that this is what you wanted the query to do.. :)

I was hoping to avoid joining everything as there can be many entries
in TableB for each record in TableA.

Also wouldn't your query only return one record? I need to return all
records from TableA with the latest action from TableB as well.

Graham



-- 
Graham

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



Re: [PHP-DB] Help with JOIN query

2008-03-06 Thread Graham Cossey
On Thu, Mar 6, 2008 at 9:54 PM, J. Hill [EMAIL PROTECTED] wrote:
 I may be a little confused: the desire is to return all the rows from
  TableA that match the record_id of a row in TableB that has the MAX
  timestamp?

  If so, why not something like:

  SELECT * FROM TableA a, TableB b WHERE a.record_id=b.record_id 
  timestamp=(SELECT MAX(timestamp) FROM TableB) ORDER BY action;

  I'm guessing I'm confused, that it's something more complicated you're
  looking for.


Thanks Krister and all for your help thus far.

Jeff, I'm after all rows from TableA then the latest action from
TableB for each selected record in TableA.

I'm starting to think maybe I should build an array of results using 2
queries then sort the array using PHP functionality, but I'd rather do
it in MySQL if it's possible.

Graham

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



Re: [PHP-DB] Help with JOIN query

2008-03-06 Thread Graham Cossey
On Thu, Mar 6, 2008 at 10:59 PM, Gary Wardell [EMAIL PROTECTED] wrote:
 Ahh, to bad, I started using it with 5.0.  I'm also a long time user of SQL 
 Server.

  Sorry if I caused confusion.

  Gary


You were getting my hopes up there Gary :-(


-- 
Graham

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



Re: [PHP-DB] Re: Help with JOIN query

2008-03-06 Thread Graham Cossey
On Fri, Mar 7, 2008 at 12:27 AM, Jonathan Crawford [EMAIL PROTECTED] wrote:
 I think this is what you mean. You just want the timestamp and action from B 
 in addition to something from A (I guessed product_ref), right?  The MAX() 
 function should take care of getting the latest timestamp.

  explicit join:

  SELECT MAX(TableB.timestamp), TableB.action, TableA.product_ref FROM TableB
  JOIN TableA ON TableA.record_id = TableB.record_id
  ORDER BY TableB.action

  or if you want to join your tables implicitly in your WHERE clause, similar 
 to what you had before, implicit join:

  SELECT MAX(TableB.timestamp), TableB.action, TableA.product_ref FROM TableB
  WHERE TableA.record_id = TableB.record_id
  ORDER BY TableB.action

  The problem with the implicit joins versus explicit joins is that you can't 
 ever do OUTER JOINs, where you want many from one table and one (or many) 
 from another table. For example if you want all sales reps and their sales, 
 even if they don't have any. Implicit (or explicit INNER) JOINs will not show 
 you all of the data.

  Jonathan Crawford
  [EMAIL PROTECTED]


Thank you for your input Jonathan but it's not quite what I need. I
need the latest action from TableB (if it exists) determined by the
record_id matching TableA and where there are more than one matching
record in TableB select the one with the latest timestamp.

As an over-simplified example of what I'm trying to achieve :

TableA
record_id   product_ref
1 product1
2 product2

TableB
timestamp  record_id  action
20080301 1start
20080302 1middle
20080301 2start
20080302 2middle
20080303 2end

What I need returned is :

1,product1,middle
2,product2,end

---
Graham

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



Re: [PHP-DB] date problems

2007-09-07 Thread Graham Cossey
This DID work, but I recently switched hosting companies...

Is the new server in a different country with a different date format
/ time zone?

Just a thought  ;-\

On 9/7/07, Instruct ICC [EMAIL PROTECTED] wrote:
 From: Instruct ICC [EMAIL PROTECTED]
 And while not trusting your indexing, rewrite short_date as:
 My short_date rewrite was also wrong.  So it looks like you will have to
 learn those offsets for this function if you do it on the PHP side.  But you
 could also do it on the MySQL side.

 _
 Get a FREE small business Web site and more from Microsoft(r) Office Live!
 http://clk.atdmt.com/MRT/go/aub0930003811mrt/direct/01/

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




-- 
Graham

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



Re: [PHP-DB] Re: RSS/XML

2005-12-18 Thread Graham Cossey
On 12/16/05, El Bekko [EMAIL PROTECTED] wrote:
 Henry Ortega wrote:
  I want to put a website's RSS feed on my website.
  For example,
  http://beccary.com/feed/
 
  I want to put all the titles of that blog page on my website.
  Is there an easy way to do this?
 
 Because they're all in a DB, yes, very easy :)

 Just build your RSS feed through PHP.

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

You could try this:

http://www.globalsyndication.com/rss-parser

It generates PHP that you can then include in your site.


--
Graham

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



Re: [PHP-DB] Google Style Search Results

2005-12-09 Thread Graham Cossey
On 12/9/05, Julien Bonastre [EMAIL PROTECTED] wrote:
snip
 http://aries.the-spectrum.org/webdev/wawd/forums/search.php?q=sufficient%2Blargest=postsb%5B%5D=*maxres=25ob=datetimeot=DESC

snip

 All I did was conjure up a regular expression that basically just matches 
 words :-) haha ironically..


 Here it is:

   $extract_result=;
   preg_match_all(/((?:[\w]+ ?){0,5})[\w 
 \.\,\-\;]((?:.join(|,$q_arr).))([\w]*)[\w \.\,\-\;]((?:[\w]+ 
 ?){0,5})/i,$row[content],$ext_matches,PREG_SET_ORDER);
   foreach($ext_matches as $ext_arr) {
 $extract_result .= $ext_arr[1]. B.$ext_arr[2]./B.$ext_arr[3]. 
 .$ext_arr[4]. ... ;
   }


 Are you familiar with regex?

snip

I'm not very familiar with regex at all and was wondering if you could
tell me how your regex would handle two matched search strings that
exist within a few words of each other in the text. For example A
larger server would be sufficient I think.

Also in the link you provided (reproduced below) the first matched
word is surrounded by 4 words and the second by 5 words, is there a
reason for this?

An example of a larger post can be found ... we were to add a
sufficient amount of text than we ...

Thank you.

--
Graham

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



Re: [PHP-DB] Google Style Search Results

2005-12-09 Thread Graham Cossey
On 12/9/05, Julien Bonastre [EMAIL PROTECTED] wrote:
 Yay, Questionnaire time

 I love this part of the game



 a) I'm not very familiar with regex at all and was wondering if you could
 tell me how your regex would handle two matched search strings that
 exist within a few words of each other in the text. For example A
 larger server would be sufficient I think.

 Answer: As I think I may have mentioned All I did was conjure up a regular
 expression 

 True, I didn't imply I wrote that regex in under 32 seconds...But I'm sure I
 was trying to come across with the fact that with improvement it could be
 much more powerful.

 Like this example:

 http://aries.the-spectrum.org/webdev/wawd/forums/search.php?q=were%2Baddst=postsb%5B%5D=*maxres=25ob=datetimeot=DESC


 Is that better??

 multiple words within the same piece of string..

 Again, much much much more work can be done, this was a very quick stub
 example to show the flexibility of regex..

 Now a new issue that has been presented is if you DO have multiple words
 close together it will only grab x amount of words to the before and after
 that central word, including perhaps another keyword.. as you can see on
 above link..


 Again, give me another 3 minutes in the code and I'm sure I'll work that one
 too..

 b)Also in the link you provided (reproduced below) the first matched
 word is surrounded by 4 words and the second by 5 words, is there a
 reason for this?

 Answer: Ooh this is my favourite :-) Yes, great reason why when you conduct
 a search such as this:
 http://aries.the-spectrum.org/webdev/wawd/forums/search.php?q=sufficient%2Blargest=postsb%5B%5D=*maxres=25ob=datetimeot=DESC

 You received the 4 word and 5 word output.. Why don't you head over to the
 link that is generated on that search result entry??

 Look around at the actual content of that forum entry and you will soon see
 that the first match occurs on a line that physically only has 9 words,
 therefore it can only really match what exists.

 Good point though, for a split second I actually thought to myself there
 might be something wrong, but as usual and until I'm proved wrong; I'm right
 again. PHP and REGEX have never failed me.

 I'm sure you all are well aware already of the saying that describes how
 there is no such thing as computer errors, only stupid humans.

 And that is precisely it, I have been and still am a stupid human, and I
 will usually sit there for quite a while reloading and running a regex in my
 head to ensure it runs and parses as it should.

 Simple ones like this don't take too much planning, but they can get hairy
 :-)




 Hopefully that answers your queries Graham..



 Kindest Regards to everybody!

 Julien Bonastre

snip

Thanks for that Julien, I really must find the time to look more into Regexs.

--
Graham

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



Re: [PHP-DB] Re: SQL Insert INTO question

2005-12-08 Thread Graham Cossey
snip
How about:

$review = $_POST['review'];
$sql = SELECT * FROM reviews WHERE review_id = '$id';
$res = mysql_query($sql) or die (Query failed:  . mysql_error());
if (mysql_num_rows($res)  0)
{
 $sql_upd = UPDATE reviews
   SET review_text = '$review'
 WHERE review_id = '$id' ;
 $res_upd = mysql_query($sql_upd) or die (Query failed:  . mysql_error());
 }else{
  $sql_ins = INSERT INTO reviews (review_id, review_text)
 VALUES('$id', '$review');
  $res_ins = mysql_query($sql_ins) or die (Query failed:  .
mysql_error());
}

--
Graham

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



Re: [PHP-DB] Suggestions please!

2005-11-22 Thread Graham Cossey
On 11/21/05, Micah Stevens [EMAIL PROTECTED] wrote:
 Sounds like a decision needs to be made. If statements were born for that.
 On Monday 21 November 2005 3:41 am, JeRRy wrote:
  Hi,
 
Okay I have a dj site, I have alogin script and cookies to handle the
  login.
 
Next I want to add some permissions for each dj account.  Maybe 3 to
  start with, 3 permissions.
 
A value or y or n will be set in each permission, with n being the
  default.
 
Now I need to know how to output the permission out with some add php
  code.
 
So let me explain:
 
Three permissions lets say are perm_1 , perm_2 , and perm_3
 
If user bob has a y in perm_2 I want to output the perm_2 permission.
  Which lets say is to delete a dj account.  So it needs to output some php
  code to work with the database.  Is IF statements relevent/safe for this or
  is there a better method?
 
So each user account on default will need to also check the values of the
  permission.  So I need a code that checks for a y value in each permission.
   If none is found than nothing is displayed or a message saying you have no
  special permissions currently.  But if one or more are met than those
  permissions are outputed to the relevant permission code.
 
If you need any further information please let me know.  All help mostly
  appreciated in advance.
 
J

You may want to consider values.

perm1 on = 1
perm2 on = 3
perm3 on = 5

therefore:
perm1 + perm2 = 4
perm1 + perm3 = 6

Might make some of the permission checking simpler?

Just a thought.

--
Graham

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



Re: [PHP-DB] Pagination

2004-12-16 Thread Graham Cossey
Try heading over to www.phpfreaks.com, they have a couple of
tutorials/examples on how to achieve this.

HTH
Graham.


On Thu, 16 Dec 2004 14:38:29 -0800, David Ziggy Lubowa
[EMAIL PROTECTED] wrote:
 
 
 Hey guys,
 
  I am working on an internal db and i have a script[below] which does some
 searching for me, now i am no expert in php but atleast i can always read up,
 i want to add some kind of pagination because just incase i search for
 somethign in particular i dont want it to display 100 entries on my form, how
 can i incorperate a pagination script in the script below,
 
[snip]

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



Re: [PHP-DB] 5 hours later - sql error.

2004-12-03 Thread Graham Cossey
One observation:

 print_r($query_rsCS);
 if(!empty($aWHERE));
  ^ Remove semi-colon ?

 $query_rsCS .= ' WHERE '.implode(' AND ',$aWHERE);
 print_r($aWHERE);

HTH

Graham

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



RE: [PHP-DB] error:attempt to write a readonly database

2004-10-28 Thread Graham Cossey
[snip]
 hi
 i am getting the following error when i try to run my
 php program..i want to know wht is this error in
 general

 Warning: sqlite_query(): attempt to write a readonly
 database in /home/saravall/.HTML/inv.php on line 26
 error:attempt to write a readonly database

[snip]

Looks like you are connecting to the database with a userid that has only
read authority.

I don't use sqlite so can't help with the specifics, but I would check that
first.

HTH
Graham

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



RE: [PHP-DB] Implementing search in a database driven website

2004-10-27 Thread Graham Cossey
I found this PDF 'quick reference' quite useful as I am just starting to
learn how to use regular expressions.

http://www.erudil.com/pdf/preqr.pdf

HTH
Graham

 -Original Message-
 From: Vinayakam Murugan [mailto:[EMAIL PROTECTED]
 Sent: 27 October 2004 04:11
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP-DB] Implementing search in a database driven website


 Thanks, Robby. This worked. However I wasn't able to get any
 documentation on the siU parameters used in the command as in

  $string= preg_replace('style[^]*.*/style'siU,'',$string);

 Any pointers.



 --
 Warm Regards
 
 Vinayak

 --
 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] Logging Into A MySQL (Web) Database

2004-10-22 Thread Graham Cossey
Probably an off-list posting.

That's the problem of just using 'Reply' instead of 'Reply to All' on this
list. Other lists I subscribe to always only ever have the list email
address when replying, which in my opinion is a better way of doing things.

[snip]

 Ok, who is Alex?

 If you are following to a thread, you should stay in it. You started a
 new thread and can't assume that we know where your train of thought is
 coming from.

 -Robby

[snip]


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



RE: [PHP-DB] how many databases should I create

2004-10-18 Thread Graham Cossey
Just to add my 2p/2c..

I use multiple databases as I find this better suits my needs. It is easier
to 'plug-in' various components to a client's application if each component
is contained in an individual database.

For example if your application was to be offered to clients as modules,
then dropping in the relevant database would probably be simpler than
adding/removing tables from one big database.

Also I find it helps me to keep individual client data separate rather than
lump it all together and add extra keys to the tables to differentiate
between clients.

This is of course MY preference for MY application, just airing my
thoughts

Graham

 -Original Message-
 From: Norland, Martin [mailto:[EMAIL PROTECTED]
 Sent: 18 October 2004 22:12
 To: [EMAIL PROTECTED]
 Subject: RE: [PHP-DB] how many databases should I create


 You're talking two different users here - in my instance, I was talking
 application users, not database users.  Yes - realistically - you can
 use just the one database and have the user permissions for it, it's
 just a case of making sure you track everything right and don't access
 the database through the wrong connection - not much different from
 making sure you access the right database.

 Realistically - a previous comment hits the nail on the head.  All a
 different database is, in essence, is a different folder - a different
 place where you can store the same stuff.  It's all about how you want
 to deal with things, how you visualize them and best interact with them.
 Any database should have sufficient user privs to handle these things,
 postgresql - mysql - or other.  It's all about who the users who can
 actually access the database are, and how the application will need to
 map its users to databaes users.

 Come to think, however - I don't know that you can assign privledges
 per-table in mysql.  So, if your 'user levels' aren't strictly
 hierarchical - you probably need to break things up (e.g. if payroll
 shouldn't be able to access inventory).


 - Martin Norland, Database / Web Developer, International Outreach x3257
 The opinion(s) contained within this email do not necessarily represent
 those of St. Jude Children's Research Hospital.


 -Original Message-
 From: Antoine [mailto:[EMAIL PROTECTED]
 Sent: Monday, October 18, 2004 4:02 PM
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP-DB] how many databases should I create
 .. chop ..
 shouldn't a good rdbms take care of that though (with reasonable
 security measures)? can't you get fine grained user privs, at least
 with a proper db? postgres? Cheers Antoine

 --
 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] Question: Putting separate form elements into an array

2004-10-17 Thread Graham Cossey
Stuart, what does your echo($query) line output?

I would hazard a guess that your quotes are wrong and you are not getting
what you expect.

What is LUID?

I believe you will need to execute an INSERT query within each for($i=0;
$icount($l_skill); $i++) loop or increment  add $LUID within each
iteration, if this is the unique record ID for each record to be inserted.

Graham

[snip]

 This is how I am trying to get them into the database:

 $queries = array();
 for($i=0; $icount($l_skill); $i++)
 {
 $queries[] = (' . $l_skill[$i] . ',  .
 $l_sky[$i] . ,  . $l_slu[$i] . );
 }

 if(count($queries) == 0)
 {
 # Nothing passed
 # exit
 }

 $query = INSERT INTO LurkProfiles_Skicerts
 (ProfileID, SkilCerts, NumYear, Lused)
 VALUES ($LUID . implode(, , $queries);

 //Above line is where I am having the problem.  There
 is something between LUID and the implode statement.
 LUID is not passing into the insert generating a sql
 error.


 $result = mysql_query($query);
 echo $query;


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



RE: [PHP-DB] Question: Putting separate form elements into an array

2004-10-17 Thread Graham Cossey
Stuart, now I'm confused.

You seem to be posting slightly different versions of problems relating to
the same script(s) on 2 lists.

What is the current situation? Iterating through the 3 arrays or inserting
into MySQL?

Graham

 -Original Message-
 From: Stuart Felenstein [mailto:[EMAIL PROTECTED]
 Sent: 17 October 2004 16:14
 To: Stuart Felenstein; Graham Cossey; [EMAIL PROTECTED]
 Subject: RE: [PHP-DB] Question: Putting separate form elements into an
 array


 Changed my direction somewhat but keep getting a parse
 error and although I know where it is , I can't seem
 to figure out what I need to do to make it syntax
 correct:

[snip]

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



RE: [PHP-DB] Question: Putting separate form elements into an array

2004-10-16 Thread Graham Cossey

  Have you tried naming your form elements such as
  skill[], sky[] and slu[] ?
  (You could also use skill[1], skill[2], skill[3]
  etc... within your form.)

 Yes that makes sense.

Good.

This of course means you can build your form within a for loop (or similar).
So to place 10 skill text boxes in your form:
?php
for ($x=0; $x10; $x++)
{
  echo INPUT TYPE=\TEXT\ NAME=\skill[]\br/;
  // Add other form elements

  // ** OR **

  echo INPUT TYPE=\TEXT\ NAME=\skill[?=$x?]\br/;
  // Add other form elements
}
?

  You can just as easily store the arrays in your
  $_SESSION if the processing
  is to be done later.

 These are session , but put them into an array ?

$_SESSION['skills'] = $_POST['skill']; // Store the skill array
$_SESSION['skys'] = $_POST['sky']; // Store the sky array
$_SESSION['slus'] = $_POST['slu']; // Store the slu array


  Note: Some form element types only pass a value if
  ticked/checked/selected.

 The sky and slu are Dropdown Menu selects, so better
 with slu[1] or slu[x]?

Dropdown menus are fine (I believe) so you can simply use [] for your form
elements.


  This will present problems if naming your form
  elements with [], instead use
  [x], [y] etc to keep all relevant form elements
  together in the same array
  indexes. (Am I making sense?, No?, time for bed
  then...)
 

 Sort of , I need to process.  Have a good night !

Don't forget to use print_r() and echo to see what your PHP script is
receiving from the form, it will help understand how to code your script. It
took me a while to get to grips with how form arrays work. (Let's hope I
haven't c0cked up here or that last statement will come back to haunt me !!)

Now I'm off ...  ZZZzzz

Graham

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



RE: [PHP-DB] mysql error and resource ID:

2004-10-14 Thread Graham Cossey

See PHP manual  Chapter 6. Types  Strings

for an explanation of single  double quotes.

From the doc:

If the string is enclosed in double-quotes (), PHP understands more escape
sequences for special characters

But the most important feature of double-quoted strings is the fact that
variable names will be expanded.

In your case it would be ' within .

$query = INSERT INTO MainTable (RecordID,UserID,.)
values(null,null,'$f1a','$f2a',...);

Graham.

 -Original Message-
 From: Stuart Felenstein [mailto:[EMAIL PROTECTED]
 Sent: 14 October 2004 15:43
 To: [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Subject: RE: [PHP-DB] mysql error and resource ID:


 Quote as in string or quote as in 'string' ?
 Those two confuse me.

 Stuart
 --- [EMAIL PROTECTED] wrote:

  If any of the variables used to insert data are
  strings ($f1a, $f2a,
  etc...), you'll need to have quotes around them.
 
  dave
 
 
 
 
 
 
  Stuart Felenstein [EMAIL PROTECTED]
 
  10/14/2004 08:26 AM
 
 
 
 
 
  To:
  Graham Cossey [EMAIL PROTECTED],
  [EMAIL PROTECTED]
  cc:
 
 
 
 
 
  Subject:
  RE: [PHP-DB] mysql error and resource ID:
 
 
 
  Not much luck here on placing the
  mysql_error($link);
  I know the server and database is reachable. So I
  imagine the error is happening in the query.  I've
  moved the $link around with no luck.
 
  Stuart
 
  Revised code below:
  --- Graham Cossey [EMAIL PROTECTED] wrote:
 
  ?php
 
  function begin()
  {
  mysql_query(BEGIN);
  }
  function commit()
  {
  mysql_query(COMMIT);
  }
  function rollback()
  {
  mysql_query(ROLLBACK);
  }
  mysql_connect(myserver,myusername, mypassword)
  or die(mysql_error());
 
  mysql_select_db(mydatabase) or die(mysql_error());
 
  $query = INSERT INTO MainTable
  (RecordID,UserID,.)
  values
 
 (null,null,$f1a,$f2a,$f2c,$f2d,$f2e,$f2g,$f5b,$f3m,$f3n,$f3e,$f3f,
 $f3g,$f3h,$f3i,$f3j,
  $f3k,$f3l);
  begin(); // transaction begins
  $result = @mysql_query($query, $link);
 
  if(!$result)
  {
  rollback(); // transaction rolls back
  echo You rolled back .mysql_error($link);
  exit;
  }
  else
  {
  commit(); // transaction is committed
  echo your insertion was successful;
  }
  ?
 
  --
  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 Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] DB will INSERT wont UPDATE..error in code?

2004-10-12 Thread Graham Cossey
I'm no 'expert' (opening myself up for much criticism here) but try the
following:

(I'm assuming you are setting $fid somewhere)

 if (empty($form_status))
 {
$staff = $_POST[staff];
$ttlpst = $_POST[ttlpst];
$mnthpst = $_POST[mnthpst];
$ttlicon = $_POST[ttlicon];
$mnthicon = $_POST[mnthicon];

$exists = SELECT * FROM badges WHERE fid = $fid;
$result = mysql_query($exists) or die(Query1 failed: .mysql_error());
if (mysql_num_rows($result) == 0)
{
  $sql = INSERT INTO badges
 (fid,staff,ttlpst,mnthpst,ttlicon,mnthicon)
  VALUES ('$fid','$staff','$ttlpst','$mnthpst','$ttlicon','$mnthicon');
  echo Insert query = $sql;
  mysql_query($sql) or die(Query2 failed: .mysql_error());
  $form_status = span class=\msgUpdated\Description
Inserted!/spanbr\n;
}
else
{
  $sql = UPDATE badges
  SET staff = '$staff'
  ttlpst ='$ttlpst'
  mnthpst = '$mnthpst'
  ttlicon = '$ttlicon'
  mnthicon = '$mnthicon'
  WHERE fid = $fid;
  echo Update query = $sql;
  mysql_query($sql) or die(Query3 failed: .mysql_error());
  $form_status = span class=\msgUpdated\Description
Updated!/spanbr\n;
}
 }

The echos will at least show the SQL being executed which could give a clue
to the problem.

You could even just set the $sql within the if...else... and use the same
mysql_query($sql) for both instances:

if (condition1)
{
$sql = query statement 1;
}else{
$sql = query statement 2;
}
mysql_query($sql);

HTH

Graham

 -Original Message-
 From: Matthew Kiehne [mailto:[EMAIL PROTECTED]
 Sent: 12 October 2004 21:09
 To: [EMAIL PROTECTED]
 Subject: [PHP-DB] DB will INSERT wont UPDATE..error in code?


 forgive the poor structure of my code, im pretty new at this and havent
 figured out exactly what it should be formed like to look its best, anyway
 whenever i run this code it works on inserting new information into the
 database, however when i want to update the SQL query returns an
 output like
 this 'SQL statement = UPDATE badges
 (staff,ttlpst,mnthpst,ttlicon,mnthicon)
 VALUES ('1','1','1','/ribbons','/ribbons') WHERE fid=2' but when i try to
 pull the information from the database it hasnt updated, can
 someone help me
 out with this...im not sure why it wouldnt update even though the
 statement
 looks correct.

[snip]

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



RE: [PHP-DB] Dynamic pull down menus with PHP/Mysql

2004-10-05 Thread Graham Cossey

Remember that PHP is server-side, so if you want PHP to do anything you'll
have to send a request back to the server (reload the page).

To handle things client side will require the likes of javascript, exactly
how is beyond me I'm afraid but I'm sure you could do something like load
all values in 2nd drop-down initially and then get javascript to limit the
available values dependant on the selection in the first drop-down.

Have you tried sites like:

http://www.javascript.com
http://www.webreference.com/js/
http://www.hotscripts.com/JavaScript/
Chained selects: http://www.hotscripts.com/Detailed/36563.html

HTH

Graham
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: 05 October 2004 15:05
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Dynamic pull down menus with PHP/Mysql


To the group:

This may be a more javascript related topic, but it's also php/mysql.
Apologies in advance if this is too far off topic.

I'm trying to pull data from MySQL using PHP to sort the results into a form
with a pull down menu. That works fine; I can do that.

But I have a second pull down menu whose items need to display based on the
item chosen from the first pull down menu.

I can do two lists seperately, but I need the second pull down menu to be a
result of the first, and I can't figure a way to do it in PHP without
reloading the page, which I don't really want to do.

Is this a javascript-dependent function, in that a js will have to make the
call to the database via some sort of scripted php/mysql request? I really
like to avoid javascript if possible, but I'm unsure there's an alternative.

Goolge et al. have some answers, but have done more to befuddle than
clarify.

As always, any help is greatly appreciated.

--V

--
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] accessing two databases within one script

2004-10-05 Thread Graham Cossey

I have several databases running on the same MySQL server and one
application needs to run queries over two DBs at the same time. All I do is
specify one connect (to the primary DB) and then specify the secondary DB
within my queries. This seems to work fine, but not sure if it's discouraged
for any reason.

DB1 contains table product.
DB2 contains table customer.

$link = mysql_connect(DB1);
$sql = SELECT c.custname, p.prodname FROM DB2.customer as c JOIN product as
p ON c.prodid=p.prodid

(This is NOT real code :) )

HTH

Graham
-Original Message-
From: Gary Rachel [mailto:[EMAIL PROTECTED]
Sent: 05 October 2004 03:31
To: [EMAIL PROTECTED]
Subject: [PHP-DB] accessing two databases within one script


I have a page where I need to access two different databases in mysql.
After accessing the first database I used  mysql_close($connection);
and then code to access the other database.  The first database access
works fine, the second gives me the following error message:

*Warning*: mysql_query(): Can't connect to local MySQL server through
socket '/tmp/mysql.sock'

I've tried not using the mysql_close statement.  But that option doesn't
select the new database, it seems to stay connected to the previous one,
despite my specifying a new database to access.  Can I not access two
databases within the same script?

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