Re: [PHP-DB] Delicious style Tags table

2008-09-12 Thread Evert Lammerts
 Evert Lammerts-2 wrote:

 Your 'taggings' table is basically a link table to deal with a 'many
 to many' relationship - i guess you know:

 You have a table A and a table B that have a many-to-many
 relationship, which is stored in table L. What query fetches all rows
 in A that relate to all members of the set [B1, B2, ..., Bn]?


 Well I was planning on getting the tags back first because in theory table B
 could be C or D or whatever.  I handle that in code by processing all the
 records I get back from the query to find out what table that are in.

??? Don't understand...

 You can manage to do this without the joins, I think, by using a
 nested query and the HAVING keyword in your SQL. Selecting all ids of
 entries that apply to all tags from a linktable would go something
 like this:

 SELECT link.entry_id, COUNT(link.entry_id) AS amount_of_links FROM
 link WHERE link.tag_id IN (SELECT id FROM tag WHERE tag.name='soup' OR
 tag.name='vegetarian') GROUP BY link.entry_id HAVING amount_of_links
= 2


 You know this got me thinking and I came up with this

 SELECT `tags`.*, count(taggable_id) as count, `taggings`.* FROM `tags`
  JOIN `taggings` ON tags.id = taggings.tag_id WHERE (name IN ('vegetarian',
 'soup')) group by taggable_id

 Now that gives me ssomething I can work with 'count' should be the same
 value as the number of tags supplied (2), but I couldn't figure out how to
 add that into the where clause, of course I could use a subselect and just 1
 will be fine, something like

 pre
 SELECT * from
  (SELECT `tags`.name, count(taggable_id) as count, `taggings`.* FROM `tags`
  JOIN `taggings` ON tags.id = taggings.tag_id WHERE (name IN ('vegetarian',
 'soup')) group by taggable_id ) tbl1
 WHERE cnt = 2
 /pre

This is what the HAVING keyword does. I'm never happy about using it though.

I've sent your question on to an expert - It's bugging me :-)

Will hopefully be back with an answer soon!

Evert

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



Re: [PHP-DB] Delicious style Tags table

2008-09-11 Thread Evert Lammerts
Your 'taggings' table is basically a link table to deal with a 'many
to many' relationship - i guess you know:

You have a table A and a table B that have a many-to-many
relationship, which is stored in table L. What query fetches all rows
in A that relate to all members of the set [B1, B2, ..., Bn]?

The problem here is that one entry in B relates to x entries in A. If
you want to know which entries in A relate to y entries in B, you're
creating a matrix with y dimensions: this means you'll have to join
the link table on itself the same amount of times as the matrix has
dimensions, resulting in the same amount of virtual tables that your
RDBMS will put in memory - iow, not safe.

You can manage to do this without the joins, I think, by using a
nested query and the HAVING keyword in your SQL. Selecting all ids of
entries that apply to all tags from a linktable would go something
like this:

SELECT link.entry_id, COUNT(link.entry_id) AS amount_of_links FROM
link WHERE link.tag_id IN (SELECT id FROM tag WHERE tag.name='soup' OR
tag.name='vegetarian') GROUP BY link.entry_id HAVING amount_of_links
= 2

This is not an elegant solution and rather expensive! There can be
another one that I can't think of - i'd love to know it. I think your
best options are to either revise your design, or to consider whether
you really need a query like this - as far as i know they're not used
on flickr etc: these sites show tags for one entry or entries for one
tag.

Evert

On Thu, Sep 11, 2008 at 1:41 PM, Catharsis [EMAIL PROTECTED] wrote:

 So I am having difficulty thinking of how to make this select query.  I have
 two tables that mimic tags similar to flickr, delicious etc.  They are
 defined below



 CREATE TABLE IF NOT EXISTS `taggings` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `tag_id` int(11) NOT NULL,
  `taggable_id` int(11) NOT NULL,
  `taggable_type` varchar(255) collate utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `index_taggings_on_tag_id_and_taggable_id_and_taggable_type`
 (`tag_id`,`taggable_id`,`taggable_type`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

 CREATE TABLE IF NOT EXISTS `tags` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(255) collate utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `unique_name` (`name`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


 Just to explain the taggings table, tag_id points directly to the tag table,
 taggable_id is the id of the item you have tagged in another table.  The
 taggable_type is string reference to the table that the item you tagged sits
 in, so in the exaplme below it would be a table called 'recipes'


 So, say you have 2 items each with the same tag but one item as two tags.
 For instance a two soup Recipes could be tagged with 'soup' but only one of
 them is vegetarian.  So Recipe 1 has the tag 'soup' and recipe 2 has 'soup'
 and 'vegetarian'


 I want to be able to pass my SQL the word 'soup' and it return both records
 in taggings table which will point to both recipes.  However if I want just
 vegetarian soups then I only want it to return the one record.  I hope that
 is understandable


 What I have currently (below) is just a simple join.  Which obviously
 doesn't work.  I just cant think how to piece these two tables together to
 get the records I want.

 SELECT `tags`.*, `taggings`.* FROM `tags`
  JOIN `taggings` ON tags.id = taggings.tag_id WHERE (name IN ('vegetarian',
 'soup'))




 --
 View this message in context: 
 http://www.nabble.com/Delicious-style-Tags-table-tp19433010p19433010.html
 Sent from the Php - Database mailing list archive at Nabble.com.


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



Re: [PHP-DB] databases and XML

2008-09-09 Thread Evert Lammerts
XML handles hierarchical structuring of data, a relational database
system handles relational structuring of data. Imho, usage of any of
these methods depend on the requirements of the system to be built.
That being said, I'm not sure what the real need would be for, like
you say, a database only accessible through XML/XQuery (with which I
assume you mean storing XML and retrieving it through XQuery). I say
this because this is exactly what an XML file is: it stores the XML -
in a file on your HD - and many interfaces provide access to it
through XQuery - like javascript.

What would be very cool is to see a fast PHP module implementing
XQuery. As for as I know there is no such solution at this moment,
just a couple of PHP libraries - so a solution on a level too high to
be considered useful for production. On the other hand, development of
these standards is going very very fast...

Intersting subject though.

On Tue, Sep 9, 2008 at 5:51 PM, YVES SUCAET [EMAIL PROTECTED] wrote:
 Well, we're actually in the process of developing a DB that's only accessible
 through XML/XQuery. But before we add new features it would be good to get an
 idea of what the needs are in the field, sort of speak.

 So instead of artifically trying to map a DTD to an RDBMS scheme, our engine
 can accept any XML-content that you want to put into it. After that, it's
 simply a matter of firing XQuery statements to the engine to get the data you
 want.

 We're thinking about building a PHP driver in order to offer outside
 connectivity (right now GUI and engine are too tightly coupled).

 Ideas, considerations, thoughts, suggestions...?

 -- Original Message --
 Received: Tue, 09 Sep 2008 10:29:57 AM CDT
 From: Lester Caine [EMAIL PROTECTED]
 To: php-db@LISTS.PHP.NET
 Subject: Re: [PHP-DB] databases and XML

 Yves Sucaet wrote:
 Hi List,

 I was wondering what strategies people are using to handle large volumes of
 XML data:

 How do you store the data? e.g.: Text-files, databases (which one)...?
 How big are your datasets? e.g.: MB, GB, TB...?
 What do you use to query the data? e.g.: PHP w/ text-files, SQLServer with
 for xml clause...?

 Finally, what limitations do you experience currently when handling XML?

 Take a look at openstreetmap.org
 http://wiki.openstreetmap.org/index.php/Planet is several GB of XML data.
 The only way of handling it to use it IS via a database, and it has scripts to

 dump it to various databases.
 So what large volume are you thinking about?

 --
 Lester Caine - G8HFL
 -
 Contact - http://lsces.co.uk/lsces/wiki/?page=contact
 L.S.Caine Electronic Services - http://lsces.co.uk
 EnquirySolve - http://enquirysolve.com/
 Model Engineers Digital Workshop - http://medw.co.uk//
 Firebird - http://www.firebirdsql.org/index.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



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



Re: [PHP-DB] If( Query)

2008-09-08 Thread Evert Lammerts
You need to run mysql_real_escape_string() on all of your input
variables before using them:

function editproduct($item_id, $item_name, $item_desc, $item_price,
$item_pix, $item_man_id, $item_cat_id) {
$item_id = mysql_real_escape_string($item_id);
$item_name = mysql_real_escape_string($item_name);
$item_desc = mysql_real_escape_string($item_desc);
$item_price = mysql_real_escape_string($item_price);
$item_pix = !empty($item_pix) ? mysql_real_escape_string($item_pix) : 
null;
$item_man_id = mysql_real_escape_string($item_man_id);
$item_cat_id = mysql_real_escape_string($item_cat_id);
connect();
$sql = UPDATE items SET item_name='{item_name}',
item_desc='{item_desc}', item_price='{item_price}',  .
(!empty($item_pix) ? item_pix='{item_pix}',  : ) .
item_man_id='{item_man_id}', item_cat_id='{item_cat_id}' WHERE
item_id={$item_id};
mysql_query($sql) or die('Insert failed: ' . mysql_error());
}

It looks like you're getting the values for the parameters from a form
- you should have some sort of validity check on it after fetching the
values.

Evert

On Mon, Sep 8, 2008 at 5:11 PM, Chris Hale [EMAIL PROTECTED] wrote:
 Niel Archer wrote:

 Hi



 I have the following function:

 function
 add_item($item_name,$item_desc,$item_price,$item_man_id,$item_cat_id,$item_pix)
{
connect();
if($item_pix == )
{
$sql = INSERT INTO items
 (item_name,item_desc,item_price,item_man_id,item_cat_id) VALUES
 ('$item_name','$item_desc','$item_price','$item_man_id','$item_cat_id');
}
else {
$sql = INSERT INTO items
 (item_name,item_desc,item_price,item_pix,item_man_id,item_cat_id) VALUES
 ('$item_name','$item_desc','$item_price','$item_pix','$item_man_id','$item_cat_id');
}
mysql_query($sql);
return;
 }

 I am using the if statement because i want it so that if no picture is
 uploaded the entry is blank and the mysql database has a default entry of
 na.gif which is a picture coming soon picture.

 It works fine when i run in localy on MAMP, but if i run it on my web
 server it doesnt add the row.


 You should be checking the mysql_query call for success and output the
 error if it fails.  Something like:

   mysql_query($sql) or die('Insert failed: ' . mysql_error());

 You'll now why it's failing then.  Make sure you have error reporting
 enabled.



 Is this a compatability error? or is there a better way to write this?




 --
 Niel Archer





 Oh no i havnt =[ i thought i had but no i now get this error:

 Insert failed: You have an error in your SQL syntax; check the manual that
 corresponds to your MySQL server version for the right syntax to use near
 'Tactel', which is soft, breathable and quick drying and easy to care for.
 ' at line 1

 Which makes no sense.

 This is the function:

 function editproduct($item_id, $item_name, $item_desc, $item_price,
 $item_pix, $item_man_id, $item_cat_id)
   {
   connect();
   if($item_pix == )
   {
   $sql = UPDATE items SET item_name='$item_name',
 item_desc='$item_desc', item_price='$item_price',
 item_man_id='$item_man_id', item_cat_id='$item_cat_id' WHERE
 item_id=$item_id;
   }
   else
   {
   $sql = UPDATE items SET item_name='$item_name',
 item_desc='$item_desc', item_price='$item_price', item_pix='$item_pix',
 item_man_id='$item_man_id', item_cat_id='$item_cat_id' WHERE
 item_id=$item_id;
   }
   mysql_query($sql) or die('Insert failed: ' . mysql_error());
   return;
 }

 adn this is the process:

   $item_id = $_POST['item_id'];
   $item_name = $_POST['fname'];
   $item_desc = $_POST[fdesc];
   $item_price = $_POST['fprice'];
   $item_man_id = $_POST['fman'];
   $item_cat_id = $_POST['fcat'];
   $item_pix = $_FILES['pix']['name'];
   $dest = 'images/items/'.$_FILES['pix']['name'];
   $temp_file = $_FILES['pix']['tmp_name'];
   move_uploaded_file($temp_file,$dest);
   editproduct($item_id, $item_name, $item_desc, $item_price, $item_pix,
 $item_man_id, $item_cat_id);
   $message = 'Product Updated';
   header(Location:admin.php?message=$message);

 --
 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] If( Query)

2008-09-08 Thread Evert Lammerts
Do a print on the query:

 function editproduct($item_id, $item_name, $item_desc, $item_price,
 $item_pix, $item_man_id, $item_cat_id) {
$item_id = mysql_real_escape_string($item_id);
$item_name = mysql_real_escape_string($item_name);
$item_desc = mysql_real_escape_string($item_desc);
$item_price = mysql_real_escape_string($item_price);
$item_pix = !empty($item_pix) ? mysql_real_escape_string($item_pix)
 : null;
$item_man_id = mysql_real_escape_string($item_man_id);
$item_cat_id = mysql_real_escape_string($item_cat_id);
connect();
$sql = UPDATE items SET item_name='{item_name}',
 item_desc='{item_desc}', item_price='{item_price}',  .
 (!empty($item_pix) ? item_pix='{item_pix}',  : ) .
 item_man_id='{item_man_id}', item_cat_id='{item_cat_id}' WHERE
 item_id={$item_id};

  var_dump($sql);

mysql_query($sql) or die('Insert failed: ' . mysql_error());
 }

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



Re: [PHP-DB] If( Query)

2008-09-08 Thread Evert Lammerts
all of us do, it's subscribed to the list. i filter it out.

On Mon, Sep 8, 2008 at 7:06 PM, Chris Hale [EMAIL PROTECTED] wrote:
 Evert Lammerts wrote:

 My bad! Forgot the dollar signs This should work:
 function editproduct($item_id, $item_name, $item_desc, $item_price,
 $item_pix, $item_man_id, $item_cat_id) {
$item_id = mysql_real_escape_string($item_id);
$item_name = mysql_real_escape_string($item_name);
$item_desc = mysql_real_escape_string($item_desc);
$item_price = mysql_real_escape_string($item_price);
$item_pix = !empty($item_pix) ? mysql_real_escape_string($item_pix)
 : null;
$item_man_id = mysql_real_escape_string($item_man_id);
$item_cat_id = mysql_real_escape_string($item_cat_id);
connect();
$sql = UPDATE items SET item_name='{$item_name}',
 item_desc='{$item_desc}', item_price='{$item_price}',  .
 (!empty($item_pix) ? item_pix='{$item_pix}',  : ) .
 item_man_id='{$item_man_id}', item_cat_id='{$item_cat_id}' WHERE
 item_id={$item_id};
mysql_query($sql) or die('Insert failed: ' . mysql_error());
 }

 On Mon, Sep 8, 2008 at 6:07 PM, Chris Hale [EMAIL PROTECTED] wrote:


 Evert Lammerts wrote:


 Do a print on the query:




 function editproduct($item_id, $item_name, $item_desc, $item_price,
 $item_pix, $item_man_id, $item_cat_id) {
  $item_id = mysql_real_escape_string($item_id);
  $item_name = mysql_real_escape_string($item_name);
  $item_desc = mysql_real_escape_string($item_desc);
  $item_price = mysql_real_escape_string($item_price);
  $item_pix = !empty($item_pix) ?
 mysql_real_escape_string($item_pix)
 : null;
  $item_man_id = mysql_real_escape_string($item_man_id);
  $item_cat_id = mysql_real_escape_string($item_cat_id);
  connect();
  $sql = UPDATE items SET item_name='{item_name}',
 item_desc='{item_desc}', item_price='{item_price}',  .
 (!empty($item_pix) ? item_pix='{item_pix}',  : ) .
 item_man_id='{item_man_id}', item_cat_id='{item_cat_id}' WHERE
 item_id={$item_id};



  var_dump($sql);




  mysql_query($sql) or die('Insert failed: ' . mysql_error());
 }





 This is what i get:

 string(165) UPDATE items SET item_name='{item_name}',
 item_desc='{item_desc}', item_price='{item_price}',
 item_man_id='{item_man_id}', item_cat_id='{item_cat_id}' WHERE item_id=
 Insert failed: You have an error in your SQL syntax; check the manual
 that
 corresponds to your MySQL server version for the right syntax to use near
 ''
 at line 3







 Thanks, seems to be working now.

 Also i meant to ask, does every one else get a foreign email from someone
 saying something about google groups every time they send ina new email to
  this mailing list?


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



Re: [PHP-DB] Getting started with MDB2

2008-09-08 Thread Evert Lammerts
 * mysql_last_insert_id()

getAfterId()

http://pear.php.net/reference/LiveUser_Admin-0.3.3/LiveUser_Admin/LiveUser_Admin_Storage_MDB2.html#methodgetAfterId

 * mysql_real_escape_string()

escape()

http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Driver_Common.html#methodescape

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



Re: [PHP-DB] Getting started with MDB2

2008-09-08 Thread Evert Lammerts
Here are some other options for escaping:

http://pear.php.net/manual/en/package.database.mdb2.intro-quote.php

I think getAfterId will not work - seems to be part of LiveUser Admin.

Interesting stuff, definitely worth a look.

On Mon, Sep 8, 2008 at 7:14 PM, YVES SUCAET [EMAIL PROTECTED] wrote:
 Hi List,

 What are the equivalent MDB2 methods for:

 * mysql_last_insert_id()
 * mysql_real_escape_string()

 Much obliged,

 Yves



 --
 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] Getting started with MDB2

2008-09-08 Thread Evert Lammerts
Have a look at this:
http://wiki.pooteeweet.org/index.php?area=MDB2page=ExampleSview=diffto=2006-05-25%2010:27:49from=2006-03-22%2011:08:24

It loads the Extended module

On Mon, Sep 8, 2008 at 8:55 PM, YVES SUCAET [EMAIL PROTECTED] wrote:
 Interesting. I'm following the documentation at
 http://pear.php.net/manual/en/package.database.mdb2.intro-sequences.php

 Here's my code:

$sql = new SQL();
$sql-connect(DSN_METNET3_MY_EDIT);
$qry = insert into List(lstName, lstNotes, UserName) values ($name,
 $notes, $user);
$sql-query($qry);
return $sql-lastInsertID(List);

 I'm now getting the following error message: Call to undefined method
 SQL::lastInsertID()

 Any further clues?

 Yves

 -- Original Message --
 Received: Mon, 08 Sep 2008 01:29:42 PM CDT
 From: Evert Lammerts [EMAIL PROTECTED]
 To: YVES SUCAET [EMAIL PROTECTED]Cc: php-db@lists.php.net
 Subject: Re: [PHP-DB] Getting started with MDB2

 * mysql_last_insert_id()

 getAfterId()

 http://pear.php.net/reference/LiveUser_Admin-0.3.3/LiveUser_Admin/LiveUser_Admin_Storage_MDB2.html#methodgetAfterId

 * mysql_real_escape_string()

 escape()

 http://pear.php.net/package/MDB2/docs/latest/MDB2/MDB2_Driver_Common.html#methodescape

 --
 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] If( Query)

2008-09-07 Thread Evert Lammerts
Is your table set up in the same way on your webserver? Maybe you
forgot to set the default value to na.gif in your item_pix column. If
not, can you send your table definition?

On Sat, Sep 6, 2008 at 9:02 PM, Chris Hale [EMAIL PROTECTED] wrote:
 I have the following function:

 function
 add_item($item_name,$item_desc,$item_price,$item_man_id,$item_cat_id,$item_pix)
   {
   connect();
   if($item_pix == )
   {
   $sql = INSERT INTO items
 (item_name,item_desc,item_price,item_man_id,item_cat_id) VALUES
 ('$item_name','$item_desc','$item_price','$item_man_id','$item_cat_id');
   }
   else {
   $sql = INSERT INTO items
 (item_name,item_desc,item_price,item_pix,item_man_id,item_cat_id) VALUES
 ('$item_name','$item_desc','$item_price','$item_pix','$item_man_id','$item_cat_id');
   }
   mysql_query($sql);
   return;
 }

 I am using the if statement because i want it so that if no picture is
 uploaded the entry is blank and the mysql database has a default entry of
 na.gif which is a picture coming soon picture.

 It works fine when i run in localy on MAMP, but if i run it on my web server
 it doesnt add the row.

 Is this a compatability error? or is there a better way to write this?

 Thanks

 --
 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] mysql auto_increment

2008-09-07 Thread Evert Lammerts
I guess this code was not copy pasted from your actual source? It
would generate mysql errors.

Anyway, I think I've an idea of what you want, so here's my two cents :

function edit_cat_radio($item_cat_id) {
connect();
$query = mysql_query(SELECT * FROM cat);
while ($row = mysql_fetch_assoc($query)) {
echo label for=\{$row['cat_name']}\{$row['cat_name']}input
type=\radio\ name=\fcat\ value=\{$row['cat_id']}\
id=\{$row['cat_id']}\  . ($item_cat_id == $row[cat_id] ?
checked=\checked\ : ) . /\n;
}
}



On Sun, Sep 7, 2008 at 11:16 PM, Chris Hale [EMAIL PROTECTED] wrote:
 I am writing a catologe application and i have a problem when it comes to
 the edit product part. I have a table with the catogories and a table with
 manufacturers.
 Each table has a id column and a name column. The id column is set up in the
 MySQL to auto_increment, which works fine normally, but i am writing this
 script:

 function edit_cat_radio($item_cat_id)
 {
   connect();
   $sql = SELECT * FROM cat DISTINGT ORDER BY cat_id;
   $result = mysql_query($sql);
   $k = 1;
   while ($row = mysql_fetch_assoc($result))
   {
   extract($row);
   echo 'label for=',$cat_name,'',$cat_name,'input type=radio
 name=fcat value=',$cat_id,' id=',$cat_id,'';
   if($k == $item_cat_id)
   {
   echo 'checked';
   }
   echo ' /';
   $k++;
   }
 return;   }

 This should (in theory) automatically check the radio button of the existing
 catogory. It would work fine; but what seems to mess it up is the
 auto_increment.

 If i delete a catogory/manufacturer from the id's remain the same. and end
 up like this:
 cat_id cat_name
 1 Bridlework
 2 Clippers
 3 Clothing
 4 Dressage Tests
 5 DVD/Video/Books
 9 Footwear

 but if the cat_id is 9 the /while /statement doesnt repeat 9 times so the
 counter never reaches 9.

 I don't know if you got all that, its hard to explain.

 I would appreciate any help on how to sort this out.

 Thanks

 --
 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] mysql auto_increment

2008-09-07 Thread Evert Lammerts
Pastebin is so much nicer when posting code. Find the code i've sent here:

http://pastebin.com/mc5d611a

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



Re: [PHP-DB] mysql auto_increment

2008-09-07 Thread Evert Lammerts
Little change - the label was not used in the right way:

http://pastebin.com/m2d98e677

On Sun, Sep 7, 2008 at 11:46 PM, Evert Lammerts
[EMAIL PROTECTED] wrote:
 I guess this code was not copy pasted from your actual source? It
 would generate mysql errors.

 Anyway, I think I've an idea of what you want, so here's my two cents :

 function edit_cat_radio($item_cat_id) {
connect();
$query = mysql_query(SELECT * FROM cat);
while ($row = mysql_fetch_assoc($query)) {
echo label 
 for=\{$row['cat_name']}\{$row['cat_name']}input
 type=\radio\ name=\fcat\ value=\{$row['cat_id']}\
 id=\{$row['cat_id']}\  . ($item_cat_id == $row[cat_id] ?
 checked=\checked\ : ) . /\n;
}
 }



 On Sun, Sep 7, 2008 at 11:16 PM, Chris Hale [EMAIL PROTECTED] wrote:
 I am writing a catologe application and i have a problem when it comes to
 the edit product part. I have a table with the catogories and a table with
 manufacturers.
 Each table has a id column and a name column. The id column is set up in the
 MySQL to auto_increment, which works fine normally, but i am writing this
 script:

 function edit_cat_radio($item_cat_id)
 {
   connect();
   $sql = SELECT * FROM cat DISTINGT ORDER BY cat_id;
   $result = mysql_query($sql);
   $k = 1;
   while ($row = mysql_fetch_assoc($result))
   {
   extract($row);
   echo 'label for=',$cat_name,'',$cat_name,'input type=radio
 name=fcat value=',$cat_id,' id=',$cat_id,'';
   if($k == $item_cat_id)
   {
   echo 'checked';
   }
   echo ' /';
   $k++;
   }
 return;   }

 This should (in theory) automatically check the radio button of the existing
 catogory. It would work fine; but what seems to mess it up is the
 auto_increment.

 If i delete a catogory/manufacturer from the id's remain the same. and end
 up like this:
 cat_id cat_name
 1 Bridlework
 2 Clippers
 3 Clothing
 4 Dressage Tests
 5 DVD/Video/Books
 9 Footwear

 but if the cat_id is 9 the /while /statement doesnt repeat 9 times so the
 counter never reaches 9.

 I don't know if you got all that, its hard to explain.

 I would appreciate any help on how to sort this out.

 Thanks

 --
 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] Import Excel sheet into SQL

2008-09-05 Thread Evert Lammerts
Save your excel file as CSV, and run the following command:

mysqlimport --fields-optionally-enclosed-by=
--fields-terminated-by=, --lines-terminated-by=\r\n
--user=YOUR_USERNAME --password YOUR_DATABASE YOUR_TABLE.csv

Make sure not to include the headers of your excel columns and to set
up your table beforehand. Don't forget to replace all necessary parts
in the command above.

If you're not on Windows you should probably use \n instead of \r\n
for the newline character.

On Fri, Sep 5, 2008 at 1:12 PM, Nasreen Laghari
[EMAIL PROTECTED] wrote:
 Hi Evert,

 I have attached it again.


 Regards,

 Nasreen

 - Original Message 
 From: Evert Lammerts [EMAIL PROTECTED]
 To: Nasreen Laghari [EMAIL PROTECTED]
 Sent: Friday, September 5, 2008 11:03:18 AM
 Subject: Re: [PHP-DB] Import Excel sheet into SQL

 Attachment didn't make it

 On Fri, Sep 5, 2008 at 12:00 PM, Nasreen Laghari
 [EMAIL PROTECTED] wrote:
 Hi,



 How can I import Excel sheet into MS-SQL. The data I have saved in excel
 sheet is in cells, snapshot is attached in this email.



 I am using sqlmyAdmin. and tried using import but getting error Invalid
 Count on line1







 Help required!!!





 Nasreen







 --
 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] Probleme with MySQL queries

2008-09-03 Thread Evert Lammerts
 $sql = 'SELECT * FROM table WHERE id='.$var.' ';
 $req = mysql_query($sql) or die('Erreur SQL
 !br'.$sql.'br'.mysql_error());
 while($data = mysql_fetch_assoc($req)) {
  echo $data['id'];
 }
 $sql2 = 'DELETE FROM table WHERE id='.$var.' ';
 $req2 = mysql_query($sql2) or die('Erreur SQL
 !br'.$sql2.'br'.mysql_error());

I'll ask the obvious: where and how is $var set, and did you echo your
$sql variable to try the query on your mysql server directly?

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



Re: [PHP-DB] Probleme with MySQL queries

2008-09-03 Thread Evert Lammerts
Did you actually echo the $sql?

I know it works right now, but try to take away the quotes around the
value in the query and see if something happens:

$sql = SELECT * FROM table WHERE id={$var};

If that doesn't work then var_dump($sql, $var) and write us the
result. Also let us know the data type of the ID column.

On Wed, Sep 3, 2008 at 11:21 AM, David DURIEUX [EMAIL PROTECTED] wrote:
 At the begining $var is $_GET['id'] and after I try directly $var = 10
 but no changes.

 On the server directly, I can only try with the values  :
 $sql = 'SELECT * FROM table WHERE id=10 '; and for this no problem.

 The problem is when I use a variable in query


 Best regards,

 David DURIEUX
 Tel : 04.74.04.81.34
 Port : 06.34.99.45.18
 Mail : [EMAIL PROTECTED]
 Site Web : http://www.siprossii.com/

 SIPROSSII
 847 route de Frans (Créacité)
 69400 Villefranche sur Saône



 Le Wed, 3 Sep 2008 11:13:11 +0200
 Evert Lammerts [EMAIL PROTECTED] a écrit:

 $sql = 'SELECT * FROM table WHERE id='.$var.' ';
 $req = mysql_query($sql) or die('Erreur SQL
 !br'.$sql.'br'.mysql_error());
 while($data = mysql_fetch_assoc($req)) {
  echo $data['id'];
 }
 $sql2 = 'DELETE FROM table WHERE id='.$var.' ';
 $req2 = mysql_query($sql2) or die('Erreur SQL
 !br'.$sql2.'br'.mysql_error());

I'll ask the obvious: where and how is $var set, and did you echo your
$sql variable to try the query on your mysql server directly?



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




Re: [PHP-DB] Probleme with MySQL queries

2008-09-03 Thread Evert Lammerts
If that doesn't work then var_dump($sql, $var) and write us the
result. Also let us know the data type of the ID column.

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



Re: [PHP-DB] Probleme with MySQL queries

2008-09-03 Thread Evert Lammerts
 string(40) SELECT * FROM table WHERE id=107 
 string(3) 107

And this query works when you run it on the database directly? Id 107 exists?

Assuming that that's both so we're running out of options.

After the select, can you do a print of mysql_error() and of mysql_num_rows()?

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



Re: [PHP-DB] Probleme with MySQL queries

2008-09-03 Thread Evert Lammerts
 In fact the first return 0 results

So the problem is in your select, and if your select works when you
manually insert the value for id (iow, without using $var), the
problem has something to do with $var.

Is the data type of the ID column INT? Try the following and let us
know the output:

$var=107;
$query = mysql_query(SELECT * FROM table WHERE id={$var};) or
die(mysql_error()); // make sure to use double quotes
var_dump(mysql_error(), mysql_num_rows());

$var=mysql_real_escape_string(107);
$query = mysql_query(SELECT * FROM table WHERE id={$var};) or
die(mysql_error()); // make sure to use double quotes
var_dump(mysql_error(), mysql_num_rows());

$query = mysql_query(SELECT * FROM table WHERE id=107;) or
die(mysql_error()); // make sure to use double quotes
var_dump(mysql_error(), mysql_num_rows());

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



Re: [PHP-DB] Probleme with MySQL queries

2008-09-03 Thread Evert Lammerts
My bad, it should have the query handle as a parameter of course:

$var=107;
$query = mysql_query(SELECT * FROM table WHERE id={$var};) or
die(mysql_error()); // make sure to use double quotes
var_dump(mysql_error(), mysql_num_rows($query));

$var=mysql_real_escape_string(107);
$query = mysql_query(SELECT * FROM table WHERE id={$var};) or
die(mysql_error()); // make sure to use double quotes
var_dump(mysql_error(), mysql_num_rows($query));

$query = mysql_query(SELECT * FROM table WHERE id=107;) or
die(mysql_error()); // make sure to use double quotes
var_dump(mysql_error(), mysql_num_rows($query));

On Wed, Sep 3, 2008 at 12:21 PM, David DURIEUX [EMAIL PROTECTED] wrote:
 Bonjour,



 Cordialement,

 David DURIEUX
 Tel : 04.74.04.81.34
 Port : 06.34.99.45.18
 Mail : [EMAIL PROTECTED]
 Site Web : http://www.siprossii.com/

 SIPROSSII
 847 route de Frans (Créacité)
 69400 Villefranche sur Saône

 ID is INT. It's ok before.

 I have errors :


 Warning: Wrong parameter count for mysql_num_rows()
 in /usr/home/sites/CL01/Web_data/hebergement/pages/sousdomaines.php
 on line 7 string(0)  NULL

 Warning: Wrong parameter count for mysql_num_rows()
 in /usr/home/sites/CL01/Web_data/hebergement/pages/sousdomaines.php
 on line 12 string(0)  NULL

 Warning: Wrong parameter count for mysql_num_rows()
 in /usr/home/sites/CL01/Web_data/hebergement/pages/sousdomaines.php
 on line 16 string(0)  NULL



 Le Wed, 3 Sep 2008 12:11:00 +0200
 Evert Lammerts [EMAIL PROTECTED] a écrit:

 In fact the first return 0 results

So the problem is in your select, and if your select works when you
manually insert the value for id (iow, without using $var), the
problem has something to do with $var.

Is the data type of the ID column INT? Try the following and let us
know the output:

$var=107;
$query = mysql_query(SELECT * FROM table WHERE id={$var};) or
die(mysql_error()); // make sure to use double quotes
var_dump(mysql_error(), mysql_num_rows());

$var=mysql_real_escape_string(107);
$query = mysql_query(SELECT * FROM table WHERE id={$var};) or
die(mysql_error()); // make sure to use double quotes
var_dump(mysql_error(), mysql_num_rows());

$query = mysql_query(SELECT * FROM table WHERE id=107;) or
die(mysql_error()); // make sure to use double quotes
var_dump(mysql_error(), mysql_num_rows());



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




Re: [PHP-DB] Probleme with MySQL queries

2008-09-03 Thread Evert Lammerts
What does var_dump($_GET) say?

On Wed, Sep 3, 2008 at 12:48 PM, David DURIEUX [EMAIL PROTECTED] wrote:
 Bonjour,

 The query works

 But when I wrote this :


 if (isset($_GET['deleteid'])){

$var=108;
$query = mysql_query(SELECT * FROM table WHERE id={$var};) or
die(select error:  . mysql_error());

if ($row = mysql_fetch_assoc($query))
var_dump ($row);

$query = mysql_query(DELETE FROM table WHERE id={$var}) or
die(delete error:  . mysql_error());


 }


 It not works and no return and no error .

 If I place the query you have sent me without the if it works but I
 must have a if for delete the ID

 It is very strange

 Cordialement,

 David DURIEUX
 Tel : 04.74.04.81.34
 Port : 06.34.99.45.18
 Mail : [EMAIL PROTECTED]
 Site Web : http://www.siprossii.com/

 SIPROSSII
 847 route de Frans (Créacité)
 69400 Villefranche sur Saône



 Le Wed, 3 Sep 2008 12:39:45 +0200
 Evert Lammerts [EMAIL PROTECTED] a écrit:

Fixed then?

On Wed, Sep 3, 2008 at 12:39 PM, David DURIEUX
[EMAIL PROTECTED] wrote:
 Bonjour,

 Yes I have the values

 array(5) { [id]=  string(3) 121 [domaine]=  string(1)
 1 [sous_domaine]=  string(8)  [repertoire]=
 string(0)  [redirection]=  string(1) 0 }


 Cordialement,

 David DURIEUX
 Tel : 04.74.04.81.34
 Port : 06.34.99.45.18
 Mail : [EMAIL PROTECTED]
 Site Web : http://www.siprossii.com/

 SIPROSSII
 847 route de Frans (Créacité)
 69400 Villefranche sur Saône



 Le Wed, 3 Sep 2008 12:36:43 +0200
 Evert Lammerts [EMAIL PROTECTED] a écrit:

I keep on making mistakes. $data should be $row in the var_dump - but
right now your DELETE has already deleted id 17 (the fact that it
prints NULL means the if condition was satisfied). So replace the
below code with a different $var value:

$var=107;
$query = mysql_query(SELECT * FROM table WHERE id={$var};) or
die(select error:  . mysql_error());

if ($row = mysql_fetch_assoc($query))
 var_dump ($row);

$query = mysql_query(DELETE FROM table WHERE id={$var}) or
die(delete error:  . mysql_error());

On Wed, Sep 3, 2008 at 12:33 PM, David DURIEUX
[EMAIL PROTECTED] wrote:
 Bonjour,

 I have :

 NULL



 Cordialement,

 David DURIEUX
 Tel : 04.74.04.81.34
 Port : 06.34.99.45.18
 Mail : [EMAIL PROTECTED]
 Site Web : http://www.siprossii.com/

 SIPROSSII
 847 route de Frans (Créacité)
 69400 Villefranche sur Saône



 Le Wed, 3 Sep 2008 12:29:44 +0200
 Evert Lammerts [EMAIL PROTECTED] a écrit:

Which means you do get results and your select works.

Now try:

$var=107;
$query = mysql_query(SELECT * FROM table WHERE id={$var};) or
die(mysql_error());

if ($row = mysql_fetch_assoc($query))
 var_dump ($data);

$query = mysql_query(DELETE FROM table WHERE id={$var}) or
die(mysql_error());

On Wed, Sep 3, 2008 at 12:25 PM, David DURIEUX
[EMAIL PROTECTED] wrote:
 Bonjour,

 string(0)  int(1)
 string(0)  int(1)
 string(0)  int(1)

 Cordialement,

 David DURIEUX
 Tel : 04.74.04.81.34
 Port : 06.34.99.45.18
 Mail : [EMAIL PROTECTED]
 Site Web : http://www.siprossii.com/

 SIPROSSII
 847 route de Frans (Créacité)
 69400 Villefranche sur Saône



 Le Wed, 03 Sep 2008 05:23:19 -0500
 Micah Gersten [EMAIL PROTECTED] a écrit:

You have to pass mysql_num_rows a $result variable from your
query.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



David DURIEUX wrote:
 Bonjour,



 Cordialement,

 David DURIEUX
 Tel : 04.74.04.81.34
 Port : 06.34.99.45.18
 Mail : [EMAIL PROTECTED]
 Site Web : http://www.siprossii.com/

 SIPROSSII
 847 route de Frans (Créacité)
 69400 Villefranche sur Saône

 ID is INT. It's ok before.

 I have errors :


 Warning: Wrong parameter count for mysql_num_rows()
 in 
 /usr/home/sites/CL01/Web_data/hebergement/pages/sousdomaines.php
 on line 7 string(0)  NULL

 Warning: Wrong parameter count for mysql_num_rows()
 in 
 /usr/home/sites/CL01/Web_data/hebergement/pages/sousdomaines.php
 on line 12 string(0)  NULL

 Warning: Wrong parameter count for mysql_num_rows()
 in 
 /usr/home/sites/CL01/Web_data/hebergement/pages/sousdomaines.php
 on line 16 string(0)  NULL



 Le Wed, 3 Sep 2008 12:11:00 +0200
 Evert Lammerts [EMAIL PROTECTED] a écrit:


 In fact the first return 0 results

 So the problem is in your select, and if your select works
 when you manually insert the value for id (iow, without using
 $var), the problem has something to do with $var.

 Is the data type of the ID column INT? Try the following and
 let us know the output:

 $var=107;
 $query = mysql_query(SELECT * FROM table WHERE id={$var};)
 or die(mysql_error()); // make sure to use double quotes
 var_dump(mysql_error(), mysql_num_rows());

 $var=mysql_real_escape_string(107);
 $query = mysql_query(SELECT * FROM table WHERE id={$var};)
 or die(mysql_error()); // make sure to use double quotes
 var_dump(mysql_error(), mysql_num_rows());

 $query = mysql_query(SELECT * FROM table WHERE id=107;) or
 die(mysql_error()); // make sure to use double quotes
 var_dump

Re: [PHP-DB] Probleme with MySQL queries

2008-09-03 Thread Evert Lammerts
 I have :

 array(2) { [module]=  string(12) sousdomaines [deleteid]=
 string(3) 134 }

 But the ID is not deleted in mysql.

That seems to be your var_dump($_GET), which means that either if
(isset($_GET['deleteid'])) evaluates to FALSE or your SELECT does not
return results. Let's check:

if (strlen($_GET[deleteid])) {
var_dump($_GET[deleteid]);
$var = mysql_real_escape_string($_GET[deleteid]);
$query = mysql_query(SELECT * FROM table WHERE id={$var};)
or die(select error:  . mysql_error());
var_dump(mysql_num_rows($query));
if ($row = mysql_fetch_assoc($query)) {
var_dump ($row);
mysql_query(DELETE FROM table WHERE id={$row['id']}) or
die(delete error:  . mysql_error());
}
}

 In must be away for 2 or 3 hours, I return after to continue this.
French lunch I'm guessing :-) I'm jealous! You guys know how to do
that, with your perfect cheese and sausage! I'll be away myself from
half past 2.

Try to keep your replies on the list - it's useful for others.

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



Re: [PHP-DB] Probleme with MySQL queries

2008-09-03 Thread Evert Lammerts
 string(3) 134 int(0)

This means you're trying to delete the entry with id=3, and that it
cannot find that in the database. Are you sure it exists? We tried the
queries separately and the SELECT had no problem... SELECT * FROM
table WHERE id=3;

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



Re: [PHP-DB] Probleme with MySQL queries

2008-09-03 Thread Evert Lammerts
 Humm with this query I have forgotten to tell you the ID is DELETED

You mean the record with id=134?

 Are you sur it is 3 ? it is 134 no?

You're right :-)

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



Re: [PHP-DB] Probleme with MySQL queries

2008-09-03 Thread Evert Lammerts
On Wed, Sep 3, 2008 at 7:41 PM, Dee Ayy [EMAIL PROTECTED] wrote:
 When using mysql_query, the SQL string to be executed should not end
 in a semicolon.

Ending a query with a semicolon should not be a problem - the string
is parsed by the mysql server, which handles it fine.

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



Re: [PHP-DB] Probleme with MySQL queries

2008-09-03 Thread Evert Lammerts
On Wed, Sep 3, 2008 at 7:58 PM, Evert Lammerts [EMAIL PROTECTED] wrote:
 On Wed, Sep 3, 2008 at 7:41 PM, Dee Ayy [EMAIL PROTECTED] wrote:
 When using mysql_query, the SQL string to be executed should not end
 in a semicolon.

 Ending a query with a semicolon should not be a problem - the string
 is parsed by the mysql server, which handles it fine.

The manual does mention it, I'm a little too quick with my replies. I
personally never had a problem with it though. Plus, it seemed to work
some mails ago.

David, did I understand well that your problem is solved?

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



Re: [PHP-DB] Probleme with MySQL queries

2008-09-03 Thread Evert Lammerts
But the DELETE is executed? If it is, and it's in the condition, like
in the above code:

if ($row = mysql_fetch_assoc($query)) {
    DELETE ...
}

something apparently is fetched

On Wed, Sep 3, 2008 at 8:49 PM, David DURIEUX [EMAIL PROTECTED] wrote:
 Bonjour,

 Yes I'm using this query and no row select

 Cordialement,

 David DURIEUX
 Tel : 04.74.04.81.34
 Port : 06.34.99.45.18
 Mail : [EMAIL PROTECTED]
 Site Web : http://www.siprossii.com/

 SIPROSSII
 847 route de Frans (Créacité)
 69400 Villefranche sur Saône



 Le Wed, 3 Sep 2008 20:43:25 +0200
 Evert Lammerts [EMAIL PROTECTED] a écrit:

Are you still using the code we talked about?

if ($row = mysql_fetch_assoc($query)) {
   var_dump ($row);
   mysql_query(DELETE FROM table WHERE id={$row['id']}) or
die(delete error:  . mysql_error());
}

if so, apparently it does fetch a row. Otherwise, can you send the
code you're using?

On Wed, Sep 3, 2008 at 8:35 PM, David DURIEUX
[EMAIL PROTECTED] wrote:
 Bonjour,

 I have always the problem, select = 0 rows and it delete it like if
 delete is before the select :/

 Cordialement,

 David DURIEUX
 Tel : 04.74.04.81.34
 Port : 06.34.99.45.18
 Mail : [EMAIL PROTECTED]
 Site Web : http://www.siprossii.com/

 SIPROSSII
 847 route de Frans (Créacité)
 69400 Villefranche sur Saône



 Le Wed, 3 Sep 2008 20:05:22 +0200
 Evert Lammerts [EMAIL PROTECTED] a écrit:

On Wed, Sep 3, 2008 at 7:58 PM, Evert Lammerts
[EMAIL PROTECTED] wrote:
 On Wed, Sep 3, 2008 at 7:41 PM, Dee Ayy [EMAIL PROTECTED] wrote:
 When using mysql_query, the SQL string to be executed should not
 end in a semicolon.

 Ending a query with a semicolon should not be a problem - the
 string is parsed by the mysql server, which handles it fine.

The manual does mention it, I'm a little too quick with my replies. I
personally never had a problem with it though. Plus, it seemed to
work some mails ago.

David, did I understand well that your problem is solved?



 --
 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] Probleme with MySQL queries

2008-09-03 Thread Evert Lammerts
This is weird. Can you send over the complete file?

On Wed, Sep 3, 2008 at 8:56 PM, David DURIEUX [EMAIL PROTECTED] wrote:
 Bonjour,

 Yes DELETE is executed and I have on my page :
 string(3) 140
 int(0)

 Cordialement,

 David DURIEUX
 Tel : 04.74.04.81.34
 Port : 06.34.99.45.18
 Mail : [EMAIL PROTECTED]
 Site Web : http://www.siprossii.com/

 SIPROSSII
 847 route de Frans (Créacité)
 69400 Villefranche sur Saône



 Le Wed, 3 Sep 2008 20:51:49 +0200
 Evert Lammerts [EMAIL PROTECTED] a écrit:

But the DELETE is executed? If it is, and it's in the condition, like
in the above code:

if ($row = mysql_fetch_assoc($query)) {
    DELETE ...
}

something apparently is fetched

On Wed, Sep 3, 2008 at 8:49 PM, David DURIEUX
[EMAIL PROTECTED] wrote:
 Bonjour,

 Yes I'm using this query and no row select

 Cordialement,

 David DURIEUX
 Tel : 04.74.04.81.34
 Port : 06.34.99.45.18
 Mail : [EMAIL PROTECTED]
 Site Web : http://www.siprossii.com/

 SIPROSSII
 847 route de Frans (Créacité)
 69400 Villefranche sur Saône



 Le Wed, 3 Sep 2008 20:43:25 +0200
 Evert Lammerts [EMAIL PROTECTED] a écrit:

Are you still using the code we talked about?

if ($row = mysql_fetch_assoc($query)) {
   var_dump ($row);
   mysql_query(DELETE FROM table WHERE id={$row['id']}) or
die(delete error:  . mysql_error());
}

if so, apparently it does fetch a row. Otherwise, can you send the
code you're using?

On Wed, Sep 3, 2008 at 8:35 PM, David DURIEUX
[EMAIL PROTECTED] wrote:
 Bonjour,

 I have always the problem, select = 0 rows and it delete it like if
 delete is before the select :/

 Cordialement,

 David DURIEUX
 Tel : 04.74.04.81.34
 Port : 06.34.99.45.18
 Mail : [EMAIL PROTECTED]
 Site Web : http://www.siprossii.com/

 SIPROSSII
 847 route de Frans (Créacité)
 69400 Villefranche sur Saône



 Le Wed, 3 Sep 2008 20:05:22 +0200
 Evert Lammerts [EMAIL PROTECTED] a écrit:

On Wed, Sep 3, 2008 at 7:58 PM, Evert Lammerts
[EMAIL PROTECTED] wrote:
 On Wed, Sep 3, 2008 at 7:41 PM, Dee Ayy [EMAIL PROTECTED]
 wrote:
 When using mysql_query, the SQL string to be executed should not
 end in a semicolon.

 Ending a query with a semicolon should not be a problem - the
 string is parsed by the mysql server, which handles it fine.

The manual does mention it, I'm a little too quick with my
replies. I personally never had a problem with it though. Plus, it
seemed to work some mails ago.

David, did I understand well that your problem is solved?



 --
 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] Probleme with MySQL queries

2008-09-03 Thread Evert Lammerts
 Your SELECT has a terminating semicolon.

I'm guessing Multiple statement execution is enabled by default...
http://dev.mysql.com/doc/refman/5.0/en/mysql-query.html

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



Re: [PHP-DB] Blank Page?

2008-09-03 Thread Evert Lammerts
Add the line:
error_reporting(E_ALL);
at the top of your functions page

On Wed, Sep 3, 2008 at 9:29 PM, Chris Hale [EMAIL PROTECTED] wrote:
 I have a functions page:
 function connect()
   {
   include(includes/Vars.php);
   mysql_connect($host, $user, $passwd) or die(Couldn't connect to
 database);
   mysql_select_db($db) or die(Couldn't select database);
 }
 function pagecontent()
   switch($_GET[page])
   {
   connect();
   case about :
   $sql = SELECT * FROM page WHERE name='about';
   $result = mysql_query($sql);
   $row = mysql_fetch_assoc($result);
   extract($row)
   echo h2{$title}/h2;\n
   echo  $content ;
   break;
   case contact :
   $sql = SELECT * FROM page WHERE name='contact';
   $result = mysql_query($sql);
   $row = mysql_fetch_assoc($result);
   extract($row)
   echo h2{$title}/h2;\n
   echo  $content ;
   break;
   default :
   $sql = SELECT * FROM page WHERE name='home';
   $result = mysql_query($sql,$cxn);
   $row = mysql_fetch_assoc($result);
   extract($row)
   echo h2{$title}/h2;\n
   echo  $content ;
   break;
   }
   return;
 }
 and when i include that in another document and try and run the functions:

 div id=column_right
   div class=content
   ?php pagecontent(); ?
   /div
 /div

 The page appears completely blank. Im new to this and i am struggling to get
 anything to work.

 --
 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] CMS-Blog system

2008-09-03 Thread Evert Lammerts
 1) having separate databases for each blog = fast
 (problem: what if I will need to do search in all of the blogs for some
 article?)

 2) having all blogs in one database - that might be 10 000 * 100 articles =
 too many rows, but easy to search and maintain, hmm?

The answers on your question depends on the architecture of your
software - if you really expect to have a big site, you'll have to
design the interfaces between the several components of your system,
both on hard- and software level.

Generally speaking I think it's easier to use one database per user -
it increases portability and scalability - you'll be able to
distribute your database servers easier.

 I am thinking of  having some file etc. cms-core.php in some base
 directory and every subdirectory (= users subdomains) would include this
 cms-core file with some individual settings. Is there better idea?

Use WordPress ;-)

Again, remember simple concepts of software engineering. Be careful to
implement a system that depends on one component to work - this
point'll easily become your single point of failure. I'm not just
joking about wordpress, why develop another system in the wild world
of open source CMS's? Take a look around - it'll save you loads of
development headaches.

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



Re: [PHP-DB] Adding br's

2008-09-01 Thread Evert Lammerts
$loopsize = mysql_num_rows();
$anagram = ;
for ($i = 0; $i  $loopsize; $i++) {
  $cell = mysql_result($anagram_result, $i, anagram);
  $anagram .= b . $cell{0} . /b . substr($cell, 1) . br /\n;
}

On Mon, Sep 1, 2008 at 2:09 AM, Ron Piggott [EMAIL PROTECTED] wrote:
 I have the following saved in one column of a mySQL table:

 Like
 Overcome
 Vested
 Embrace

 It is an anagram for the word Love

 I am querying the table to display the results.  I am needing help with
 the formatting part of this.

 I have this line of code:

 $anagram=mysql_result($anagram_result,$i,anagram);


 I need help adding br's so each word will be on a new line.  Within
 the table column each word is on a separate line.  It would also be
 really cool if the first letter was in bold (ie bX/b )

 echo stripslashes($anagram)

 Thanks,

 Ron


 --
 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] OCI8 , PHP and APACHE issue

2008-09-01 Thread Evert Lammerts
Can you send your and the output of phpinfo when run from the command
line and when run from the browser?

On Mon, Sep 1, 2008 at 6:35 AM, Jack van Zanen [EMAIL PROTECTED] wrote:
 Hi List,


 I have installed Oracle, PHP and apache on my windows machine and have the
 following issue

 If I run phpinfo() from the command line it shows OCI8 as enabled and I can
 connect to oracle databases.

 When I copy my php.ini to my windows directory (from my php directory) and
 start apache and than run phpinfo() from a php page in my browser it does
 not show me that OCI8 is enabled and also does not allow me to connect to
 databases. It does show it is using the right php.ini from my windows
 directory

 I'm sure this must be an environment setting somewhere but I  can't work
 this out.

 Anybody with some more experience in configuring this combo can shed some
 light on this??



 Brgds


 Jack


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



Re: [PHP-DB] OCI8 , PHP and APACHE issue

2008-09-01 Thread Evert Lammerts
I see that in both cases c:\PHP\php.ini is loaded. Are you sure that
after trying the command line you didn't cut - paste the file to
c:\windows? What do apache's and PHP's logs say?

On Mon, Sep 1, 2008 at 1:25 PM, Jack van Zanen [EMAIL PROTECTED] wrote:
 Attached is phpinfo() both from the command line and from apache on the same
 machine


 I have done the exact same setup on my laptop and it works fine from apache
 and cli.
 I even copied over the httpd.conf and the php.ini file from my laptop as all
 paths and versions were identical.

 Oracle 10.2.0.4 client
 apache 2.2
 php 5.2.6

 Thanks


 On 01/09/2008, Evert Lammerts [EMAIL PROTECTED] wrote:

 Can you send your and the output of phpinfo when run from the command
 line and when run from the browser?

 On Mon, Sep 1, 2008 at 6:35 AM, Jack van Zanen [EMAIL PROTECTED] wrote:
  Hi List,
 
 
  I have installed Oracle, PHP and apache on my windows machine and have
  the
  following issue
 
  If I run phpinfo() from the command line it shows OCI8 as enabled and I
  can
  connect to oracle databases.
 
  When I copy my php.ini to my windows directory (from my php directory)
  and
  start apache and than run phpinfo() from a php page in my browser it
  does
  not show me that OCI8 is enabled and also does not allow me to connect
  to
  databases. It does show it is using the right php.ini from my windows
  directory
 
  I'm sure this must be an environment setting somewhere but I  can't work
  this out.
 
  Anybody with some more experience in configuring this combo can shed
  some
  light on this??
 
 
 
  Brgds
 
 
  Jack
 



 --
 J.A. van Zanen

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



Re: [PHP-DB] OCI8 , PHP and APACHE issue

2008-09-01 Thread Evert Lammerts
No interesting entries in the logs?

On Mon, Sep 1, 2008 at 2:27 PM, Jack van Zanen [EMAIL PROTECTED] wrote:
 I have the phpinidir directive set in apache so it loads the exact same
 php.ini as the cli

 Jack

 2008/9/1 Evert Lammerts [EMAIL PROTECTED]

 I see that in both cases c:\PHP\php.ini is loaded. Are you sure that
 after trying the command line you didn't cut - paste the file to
 c:\windows? What do apache's and PHP's logs say?

 On Mon, Sep 1, 2008 at 1:25 PM, Jack van Zanen [EMAIL PROTECTED] wrote:
  Attached is phpinfo() both from the command line and from apache on the
  same
  machine
 
 
  I have done the exact same setup on my laptop and it works fine from
  apache
  and cli.
  I even copied over the httpd.conf and the php.ini file from my laptop as
  all
  paths and versions were identical.
 
  Oracle 10.2.0.4 client
  apache 2.2
  php 5.2.6
 
  Thanks
 
 
  On 01/09/2008, Evert Lammerts [EMAIL PROTECTED] wrote:
 
  Can you send your and the output of phpinfo when run from the command
  line and when run from the browser?
 
  On Mon, Sep 1, 2008 at 6:35 AM, Jack van Zanen [EMAIL PROTECTED]
  wrote:
   Hi List,
  
  
   I have installed Oracle, PHP and apache on my windows machine and
   have
   the
   following issue
  
   If I run phpinfo() from the command line it shows OCI8 as enabled and
   I
   can
   connect to oracle databases.
  
   When I copy my php.ini to my windows directory (from my php
   directory)
   and
   start apache and than run phpinfo() from a php page in my browser it
   does
   not show me that OCI8 is enabled and also does not allow me to
   connect
   to
   databases. It does show it is using the right php.ini from my windows
   directory
  
   I'm sure this must be an environment setting somewhere but I  can't
   work
   this out.
  
   Anybody with some more experience in configuring this combo can shed
   some
   light on this??
  
  
  
   Brgds
  
  
   Jack
  
 
 
 
  --
  J.A. van Zanen



 --
 J.A. van Zanen


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



Re: [PHP-DB] OCI8 , PHP and APACHE issue

2008-09-01 Thread Evert Lammerts
It's usually easy as that. Good to hear you got it to work.

On Mon, Sep 1, 2008 at 2:59 PM, Jack van Zanen [EMAIL PROTECTED] wrote:
 Funny you should mention that.

 Could not load the extension.

 I tried putting c:\php\ext  as extension_dir but that resulted in apache 
 being unable to start at all.

 Than I remembered that on this particular machine we were running as a 
 different user and not local system. When I changed that it worked ok

 I really need to understand more about windows I guess

 Jack

 -Original Message-
 From: Evert Lammerts [mailto:[EMAIL PROTECTED]
 Sent: Monday, September 01, 2008 10:32 PM
 To: Jack van Zanen
 Cc: php-db@lists.php.net
 Subject: Re: [PHP-DB] OCI8 , PHP and APACHE issue

 No interesting entries in the logs?

 On Mon, Sep 1, 2008 at 2:27 PM, Jack van Zanen [EMAIL PROTECTED] wrote:
 I have the phpinidir directive set in apache so it loads the exact same
 php.ini as the cli

 Jack

 2008/9/1 Evert Lammerts [EMAIL PROTECTED]

 I see that in both cases c:\PHP\php.ini is loaded. Are you sure that
 after trying the command line you didn't cut - paste the file to
 c:\windows? What do apache's and PHP's logs say?

 On Mon, Sep 1, 2008 at 1:25 PM, Jack van Zanen [EMAIL PROTECTED] wrote:
  Attached is phpinfo() both from the command line and from apache on the
  same
  machine
 
 
  I have done the exact same setup on my laptop and it works fine from
  apache
  and cli.
  I even copied over the httpd.conf and the php.ini file from my laptop as
  all
  paths and versions were identical.
 
  Oracle 10.2.0.4 client
  apache 2.2
  php 5.2.6
 
  Thanks
 
 
  On 01/09/2008, Evert Lammerts [EMAIL PROTECTED] wrote:
 
  Can you send your and the output of phpinfo when run from the command
  line and when run from the browser?
 
  On Mon, Sep 1, 2008 at 6:35 AM, Jack van Zanen [EMAIL PROTECTED]
  wrote:
   Hi List,
  
  
   I have installed Oracle, PHP and apache on my windows machine and
   have
   the
   following issue
  
   If I run phpinfo() from the command line it shows OCI8 as enabled and
   I
   can
   connect to oracle databases.
  
   When I copy my php.ini to my windows directory (from my php
   directory)
   and
   start apache and than run phpinfo() from a php page in my browser it
   does
   not show me that OCI8 is enabled and also does not allow me to
   connect
   to
   databases. It does show it is using the right php.ini from my windows
   directory
  
   I'm sure this must be an environment setting somewhere but I  can't
   work
   this out.
  
   Anybody with some more experience in configuring this combo can shed
   some
   light on this??
  
  
  
   Brgds
  
  
   Jack
  
 
 
 
  --
  J.A. van Zanen



 --
 J.A. van Zanen




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



Re: [PHP-DB] Problem after moving servers

2008-08-31 Thread Evert Lammerts
 $list-render( $db, $start, COUNT );

Send the code of this function and tell me the value of COUNT.

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



Re: [PHP-DB] Problem after moving servers

2008-08-31 Thread Evert Lammerts
Can you send over the function ProfileList::render? And you should
make sure that whenever the render() function of one of ProfileList's
subclasses is called, the value of $count is 30... It seems the most
likely source of your problem to me. To check the value of $count you
can do and echo $count; or var_dump($count); in the
ProfileList::render() function.

Make sure to always include the list in your replies. This way people
can reuse solutions from the archives.

Evert

On Sun, Aug 31, 2008 at 11:21 AM, Gav [EMAIL PROTECTED] wrote:
 Hi All,

 I moved a site across from one server to another, and now there is one thing
 no longer working properly that worked fine on the other. It may turn out to
 be a PHP4 to PHP5 problem, dont know as I cant access now what the other
 server had.

 Certain pages on the website were able to render a list of 30 items, since
 the move it now only renders the first item only.

 I'm sure you want some code, but before I give that can we determine if I'm
 on the right list - the function does pull items from a database so it is
 sort of related, though I'm not sure it is  a db problem.

 In the php output page we have

 $list-render( $db, $start, COUNT );

 Not sure if that is a clue or not, anyway let me know if you me to post all
 the related classes and functions.

 Cheers

 Gav...


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



Re: [PHP-DB] Problem after moving servers

2008-08-31 Thread Evert Lammerts
The code you've sent seems to be fine, and if I check your website it
does everything it should do in terms of filtering - if I select
Tayside as a region I get a development company with the region set to
Tayside. It seems to me that this means the problem is not in one of
the subclasses of ProfileList, so not a compatibility issue on that
level ($this-query works fine).

 while( $row = $db-getrow() )
seems to stop after one loop. This is either because there are no more
results - the query is limited to 1, so $count=1 - or because
$db-getRow generates an error.

 COUNT and $count look like they have different roles to me, COUNT is the 
 amount of
 designers to be listed per page, $count is the number of designers to be 
 listed altogether,
 so 150 designers would give me 5 pages of 30 designers.

In ProfileList::render the query is appended with LIMIT $start,
$count, and the results of the query all seem to be rendered. This
probably means that $count and COUNT should have the same value - 30 -
and that the render function is initially called with the global
variable COUNT as parameter.

To check what goes wrong you first need to set error_reporting to
E_ALL in php.ini and restart your webserver, or add the line
error_reporting(E_ALL); at the beginning of you code. After that you
need to print the query from ProfileList::render. Can you adjust the
function and add var_dump($q); after the line $q = $q. LIMIT $start,
$count ;?

Evert

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



Re: [PHP-DB] Problem after moving servers

2008-08-31 Thread Evert Lammerts
You don't need to print the query anymore - I already did that. You
need to change your code because right now it is open for SQL
injection attacks: I added some SQL to the url and generated an SQL
error (http://www.iwdp.co.uk/list.php?region=1start=30,2). When you
retrieve start, e.g. $_GET['start'], do a check to make sure the value
is an integer.

The good news is that the query looks fine:
SELECT d.id AS id FROM designers d, designer_regions dr WHERE
dr.region_id=1 AND dr.designer_id=d.id AND d.view=1 ORDER BY d.id ASC
LIMIT 0, 30;

Can you run this query directly on the database and see what the result is?

Also check if you get an error after setting error_reporting to E_ALL.

On Sun, Aug 31, 2008 at 1:16 PM, Evert Lammerts
[EMAIL PROTECTED] wrote:
 The code you've sent seems to be fine, and if I check your website it
 does everything it should do in terms of filtering - if I select
 Tayside as a region I get a development company with the region set to
 Tayside. It seems to me that this means the problem is not in one of
 the subclasses of ProfileList, so not a compatibility issue on that
 level ($this-query works fine).

 while( $row = $db-getrow() )
 seems to stop after one loop. This is either because there are no more
 results - the query is limited to 1, so $count=1 - or because
 $db-getRow generates an error.

 COUNT and $count look like they have different roles to me, COUNT is the 
 amount of
 designers to be listed per page, $count is the number of designers to be 
 listed altogether,
 so 150 designers would give me 5 pages of 30 designers.

 In ProfileList::render the query is appended with LIMIT $start,
 $count, and the results of the query all seem to be rendered. This
 probably means that $count and COUNT should have the same value - 30 -
 and that the render function is initially called with the global
 variable COUNT as parameter.

 To check what goes wrong you first need to set error_reporting to
 E_ALL in php.ini and restart your webserver, or add the line
 error_reporting(E_ALL); at the beginning of you code. After that you
 need to print the query from ProfileList::render. Can you adjust the
 function and add var_dump($q); after the line $q = $q. LIMIT $start,
 $count ;?

 Evert


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



Re: [PHP-DB] Problem after moving servers

2008-08-31 Thread Evert Lammerts
In PHP5 register_globals defaults to off. You can either switch it
back on through your php.ini and restart your webserver, or change all
PHP_SELF references to $_SERVER['PHP_SELF']. See if that fixes your
problem.

I hope you understood the SQL injection problem I pointed out. Anybody
can drop your database, so do fix it!

On 8/31/08, Gav [EMAIL PROTECTED] wrote:
 On Sun, Aug 31, 2008 at 9:27 PM, Evert Lammerts
 [EMAIL PROTECTED]wrote:

 You don't need to print the query anymore - I already did that. You
 need to change your code because right now it is open for SQL
 injection attacks: I added some SQL to the url and generated an SQL
 error (http://www.iwdp.co.uk/list.php?region=1start=30,2). When you
 retrieve start, e.g. $_GET['start'], do a check to make sure the value
 is an integer.

 The good news is that the query looks fine:
 SELECT d.id AS id FROM designers d, designer_regions dr WHERE
 dr.region_id=1 AND dr.designer_id=d.id AND d.view=1 ORDER BY d.id ASC
 LIMIT 0, 30;

 Can you run this query directly on the database and see what the result
 is?


 *SQL query:* SELECT d.id AS id FROM designers d, designer_regions dr WHERE
 dr.region_id=1 AND dr.designer_id=d.id AND d.view=1 ORDER BY d.id ASC LIMIT
 0, 30;
 *Rows:* 30  id  2  4  5  11  43  63  86  99  117  119  158  165  233  272
 290  305  328  335  363  396  414  425  430  436  459  489  490  518  536
 554



 Also check if you get an error after setting error_reporting to E_ALL.


  Yup, I left it up there at http://www.iwdp.co.uk/list.php

 The PHP_SELF being referred to as undefined is in the included file
 generic.php  :-

 class DropNav
 {
 var $items =array();
 var $head;
 var $body;

 // CONSTRUCTOR
 function DropNav()
 {
 }

 // PUBLIC
 function renderHead()
 {
 $this-buildHTML();
 print $this-head;
 }

 // PUBLIC
 function renderBody()
 {
 $this-buildHTML();
 print $this-body;
 }

 // PUBLIC
 function addItem( $url, $desc )
 {
 $this-items[] = array( url = $url, desc=$desc );
 }

 // PRIVATE
 function buildHTML()
 {
 global $PHP_SELF;
 $this-body = form action=\$PHP_SELF\\n;
 $this-body .= \tpselect name=\newLocation\
 onchange=\jumpPage(this.form.newLocation)\\n;
 foreach ( $this-items as $item )
 {
 $this-body .=\t\toption value=\.$item[url].\;
 $this-body .= $item[desc];
 $this-body .=/option\n;
 }

 $this-body .= \t/select/p\n/form\n;

 $this-head = script type=\text/javascript\\n;
 $this-head .= !--
 function jumpPage( newLoc )
 {
 newPage = newLoc.options[newLoc.selectedIndex].value;
 if ( newPage != \\ )
 {
 window.location.href=newPage;
 }
 } // --\n;
 $this-head .= /script\n\n;
 }
 }

 Thanks

 Gav...



 On Sun, Aug 31, 2008 at 1:16 PM, Evert Lammerts
 [EMAIL PROTECTED] wrote:
  The code you've sent seems to be fine, and if I check your website it
  does everything it should do in terms of filtering - if I select
  Tayside as a region I get a development company with the region set to
  Tayside. It seems to me that this means the problem is not in one of
  the subclasses of ProfileList, so not a compatibility issue on that
  level ($this-query works fine).
 
  while( $row = $db-getrow() )
  seems to stop after one loop. This is either because there are no more
  results - the query is limited to 1, so $count=1 - or because
  $db-getRow generates an error.
 
  COUNT and $count look like they have different roles to me, COUNT is
  the
 amount of
  designers to be listed per page, $count is the number of designers to
  be
 listed altogether,
  so 150 designers would give me 5 pages of 30 designers.
 
  In ProfileList::render the query is appended with LIMIT $start,
  $count, and the results of the query all seem to be rendered. This
  probably means that $count and COUNT should have the same value - 30 -
  and that the render function is initially called with the global
  variable COUNT as parameter.
 
  To check what goes wrong you first need to set error_reporting to
  E_ALL in php.ini and restart your webserver, or add the line
  error_reporting(E_ALL); at the beginning of you code. After that you
  need to print the query from ProfileList::render. Can you adjust the
  function and add var_dump($q); after the line $q = $q. LIMIT $start,
  $count ;?
 
  Evert
 




 --
 Gav...

 [LinkedIn : http://www.linkedin.com/in/ipv6guru]

 www.16degrees.com.au | www.iwdp.co.uk | www.minitutorials.com

 (Sponsorship slots available on above three sites!)


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



Re: [PHP-DB] Problem after moving servers

2008-08-31 Thread Evert Lammerts
I'm pretty sure I found the problem - I should've spotted it earlier.

The function ProfileList::render gets a reference to the $db object by
its parameter $db. While you loop over your results, you pass the
reference on to $this-des-load. I'm guessing that the definition of
$this-des-load is something like function load($id, $db);, in which
case it's not getting a reference to the $db object but an actual copy
in PHP4. Since PHP 5 there is a new object model that makes sure that
any variable that holds an object is actually just a handle to the
object - so whenever you pass it to a function you use it as a
reference instead of a copy.

To make it clear:

class test {
  var $a = 1;
  function aa() {
$this-a++;
  }
}

$c = new test();
$d = $c;
$c-aa();
$d-aa();
var_dump ($c);

results in:
object(test)#1 (1) { [a]=  int(3) }

This means you should first change the function definitions to not use
references for objects, so take away the  at every $db parameter.

Second you need to create a new $db object for your $this-des-load
function before the while loop in ProfileList::render. I think the
safest option is to do something like $db2 = new Db(...). You can also
use the keyword clone to clone an object, but i'm not sure what this
does with your internal DB handle you could try and see what
happens. Just add $db2 = clone $db; right before the while loop. Call
$this-des-load with $db2 instead of $db.

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



Re: [PHP-DB] mySQL SELECT query

2008-08-29 Thread Evert Lammerts
In the SQL standard this would be

AND NOT ministry_directory.listing_approved=0 AND NOT
ministry_directory.listing_approved=4

MySQL supports (and there are probably more RDBs that do):

AND ministry_directory.listing_approved!=0 AND
ministry_directory.listing_approved!=4

On Fri, Aug 29, 2008 at 7:09 PM, Ron Piggott [EMAIL PROTECTED] wrote:
 Is there a way to make this part of a SELECT query more concise?

 AND ministry_directory.listing_approved NOT LIKE '0' AND
 ministry_directory.listing_approved NOT LIKE '4'

 I know of the

 IN ( 10, 12 )

 command.  Is there something similar available for NOT LIKE?

 Ron


 --
 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] Problem with updating MySQL table

2008-08-27 Thread Evert Lammerts
Your index.php looks very strange:

 ?PHP

 form method=post action=purlprocess.php
 
 /form

 ?

I'm guessing you're echoing this? I never echo from my scripts so I
don't know if this is new functionality, but in my days you echoed
either by ?=...;? or by ? echo ...; ?.

Anyway, since you're using the $_POST variable, did you check if it
contains any values? You can do this with var_dump($_POST); Let us
know what the results are.

Another tip:

 $FName= $_POST['txtFName'];
 etc

is terrible practice - if anybody writes an SQL command into one of
your textfields it WILL be executed; this is called SQL injection. A
less terrible scenario, but still one that messes up your page, is if
somebody uses quotes. So always use mysql_real_escape_string() on your
post variables before using them in a query.

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



Re: [PHP-DB] Problem with updating MySQL table

2008-08-27 Thread Evert Lammerts
Everybody seems to agree on escaping :-) And I'm learning! HEREDOC,
nifty indeed!

How about your $_POST variable, is there anything in there?

On Wed, Aug 27, 2008 at 6:38 PM, Jason Pruim [EMAIL PROTECTED] wrote:

 On Aug 27, 2008, at 12:24 PM, Evert Lammerts wrote:

 Your index.php looks very strange:

 ?PHP

 form method=post action=purlprocess.php
 
 /form

 ?

 I'm guessing you're echoing this? I never echo from my scripts so I
 don't know if this is new functionality, but in my days you echoed
 either by ?=...;? or by ? echo ...; ?.

 It is a index.php page using the HEREDOC syntax... so basically:
 echo HTML Pany HTML code goes here
 HTML;

 pretty nifty I feel.



 Anyway, since you're using the $_POST variable, did you check if it
 contains any values? You can do this with var_dump($_POST); Let us
 know what the results are.

 Another tip:

 $FName= $_POST['txtFName'];
 etc

 is terrible practice - if anybody writes an SQL command into one of
 your textfields it WILL be executed; this is called SQL injection. A
 less terrible scenario, but still one that messes up your page, is if
 somebody uses quotes. So always use mysql_real_escape_string() on your
 post variables before using them in a query.

 mysql_real_escape_string() won't help with my mysqlI connection though :)

 I will be wrapping the whole thing in a prepared statement before going to
 production with this. At this point this is simply a proof of concept for
 the boss.
 --

 Jason Pruim
 Raoset Inc.
 Technology Manager
 MQC Specialist
 11287 James St
 Holland, MI 49424
 www.raoset.com
 [EMAIL PROTECTED]






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



Re: [PHP-DB] Sqlite 3 pdo update query problem

2008-08-20 Thread Evert Lammerts
 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID='.$prodid.';

Try to unquote $prodid:

$sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

Evert

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



Re: [PHP-DB] Sqlite 3 pdo update query problem

2008-08-20 Thread Evert Lammerts
can you put
error_reporting(E_ALL);

somewhere above the query and check if there's some output?

On Wed, Aug 20, 2008 at 11:02 AM, Amy Gibbs [EMAIL PROTECTED] wrote:
 still not working,


 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=
 14;

 $statement= $sesdb-query($query);
 $result=$statement-fetchAll();

 foreach ($result as $product) {
 $prodname=$product[0];
 $prodqty = $product[1];
 $prodid=$product[2];

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 $sesdb-exec($sql);

 }

 On 20 Aug 2008, at 09:59, Evert Lammerts wrote:

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID='.$prodid.';

 Try to unquote $prodid:

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 Evert

 --
 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] Sqlite 3 pdo update query problem

2008-08-20 Thread Evert Lammerts
Sorry, I'm out of options. Hopefully somebody on the list has a little
more experience with PDO.

On Wed, Aug 20, 2008 at 12:26 PM, Amy Gibbs [EMAIL PROTECTED] wrote:
 It's still not working :(
 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=
 14;
 $statement= $sesdb-query($query);
 $result=$statement-fetchAll();
 $statement=null;
 foreach ($result as $product) {
 $prodname=$product[0];
 $prodqty = $product[1];
 $prodid=$product[2];

 $sql = UPDATE ZITEM SET ZQUANTITY=0 WHERE ZPRODUCTID={$prodid};
 $sesdb-exec($sql);

 On 20 Aug 2008, at 11:10, Evert Lammerts wrote:

 A little time on google told me that if you want to do a write after a
 read (or the other way around) you need to free up the query resource
 - apparently they hold read / write locks.

 so, free up $statement before doing a write:

 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=
 14;

 $statement= $sesdb-query($query);
 $result=$statement-fetchAll();

 $statement=null;

 foreach ($result as $product) {
 $prodname=$product[0];
 $prodqty = $product[1];
 $prodid=$product[2];


 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID='{$prodid}';

 $sesdb-exec($sql);

 }


 On Wed, Aug 20, 2008 at 11:49 AM, Amy Gibbs [EMAIL PROTECTED]
 wrote:

 No errors reported, but it's not updating the db,

 error_reporting(E_ALL);

 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];


 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 $sesdb-exec($sql);

 }

 On 20 Aug 2008, at 10:11, Evert Lammerts wrote:

 can you put

 error_reporting(E_ALL);

 somewhere above the query and check if there's some output?

 On Wed, Aug 20, 2008 at 11:02 AM, Amy Gibbs [EMAIL PROTECTED]

 wrote:

 still not working,


 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 $sesdb-exec($sql);

 }

 On 20 Aug 2008, at 09:59, Evert Lammerts wrote:

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID='.$prodid.';

 Try to unquote $prodid:

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 Evert

 --

 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






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



Re: [PHP-DB] Sqlite 3 pdo update query problem

2008-08-20 Thread Evert Lammerts
What happens if you try the UPDATE before a SELECT?

$sesdb = new PDO('sqlite:file.sqlite3');
var_dump($sesdb-exec(UPDATE ZITEM SET ZQUANTITY=0 WHERE ZPRODUCTID=1));

On Wed, Aug 20, 2008 at 12:42 PM, Evert Lammerts
[EMAIL PROTECTED] wrote:
 Sorry, I'm out of options. Hopefully somebody on the list has a little
 more experience with PDO.

 On Wed, Aug 20, 2008 at 12:26 PM, Amy Gibbs [EMAIL PROTECTED] wrote:
 It's still not working :(
 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=
 14;
 $statement= $sesdb-query($query);
 $result=$statement-fetchAll();
 $statement=null;
 foreach ($result as $product) {
 $prodname=$product[0];
 $prodqty = $product[1];
 $prodid=$product[2];

 $sql = UPDATE ZITEM SET ZQUANTITY=0 WHERE ZPRODUCTID={$prodid};
 $sesdb-exec($sql);

 On 20 Aug 2008, at 11:10, Evert Lammerts wrote:

 A little time on google told me that if you want to do a write after a
 read (or the other way around) you need to free up the query resource
 - apparently they hold read / write locks.

 so, free up $statement before doing a write:

 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=
 14;

 $statement= $sesdb-query($query);
 $result=$statement-fetchAll();

 $statement=null;

 foreach ($result as $product) {
 $prodname=$product[0];
 $prodqty = $product[1];
 $prodid=$product[2];


 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID='{$prodid}';

 $sesdb-exec($sql);

 }


 On Wed, Aug 20, 2008 at 11:49 AM, Amy Gibbs [EMAIL PROTECTED]
 wrote:

 No errors reported, but it's not updating the db,

 error_reporting(E_ALL);

 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];


 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 $sesdb-exec($sql);

 }

 On 20 Aug 2008, at 10:11, Evert Lammerts wrote:

 can you put

 error_reporting(E_ALL);

 somewhere above the query and check if there's some output?

 On Wed, Aug 20, 2008 at 11:02 AM, Amy Gibbs [EMAIL PROTECTED]

 wrote:

 still not working,


 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 $sesdb-exec($sql);

 }

 On 20 Aug 2008, at 09:59, Evert Lammerts wrote:

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID='.$prodid.';

 Try to unquote $prodid:

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 Evert

 --

 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







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



Re: [PHP-DB] Sqlite 3 pdo update query problem

2008-08-20 Thread Evert Lammerts
Alright, getting somewhere.

Try this:

$sesdb = new PDO('sqlite:wtc.sqlite3');
if ($sesdb-exec(UPDATE ZITEM SET ZQUANTITY=0 WHERE
ZPRODUCTID='bli-343') === false) {
echo $sesdb-errorInfo();
}

Don't forget the quotes around the product id (it's a string so you
need them after all)


On Wed, Aug 20, 2008 at 12:50 PM, Amy Gibbs [EMAIL PROTECTED] wrote:
 It still doesn't run the update, but the var_dump displays
 bool(false) bool(false)
 $sesdb = new PDO('sqlite:wtc.sqlite3');
 $sql = UPDATE ZITEM SET ZQUANTITY=0 WHERE ZPRODUCTID=bli-343;
 var_dump($sesdb-exec(UPDATE ZITEM SET ZQUANTITY=0 WHERE
 ZPRODUCTID=bli-343));
 $sesdb-exec($sql);
 var_dump($sesdb-exec(UPDATE ZITEM SET ZQUANTITY=0 WHERE
 ZPRODUCTID=bli-343));
 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=
 14;


 On 20 Aug 2008, at 11:45, Evert Lammerts wrote:

 What happens if you try the UPDATE before a SELECT?

 $sesdb = new PDO('sqlite:file.sqlite3');
 var_dump($sesdb-exec(UPDATE ZITEM SET ZQUANTITY=0 WHERE ZPRODUCTID=1));

 On Wed, Aug 20, 2008 at 12:42 PM, Evert Lammerts
 [EMAIL PROTECTED] wrote:

 Sorry, I'm out of options. Hopefully somebody on the list has a little

 more experience with PDO.

 On Wed, Aug 20, 2008 at 12:26 PM, Amy Gibbs [EMAIL PROTECTED]
 wrote:

 It's still not working :(

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 $statement=null;

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];

 $sql = UPDATE ZITEM SET ZQUANTITY=0 WHERE ZPRODUCTID={$prodid};

 $sesdb-exec($sql);

 On 20 Aug 2008, at 11:10, Evert Lammerts wrote:

 A little time on google told me that if you want to do a write after a

 read (or the other way around) you need to free up the query resource

 - apparently they hold read / write locks.

 so, free up $statement before doing a write:

 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 $statement=null;

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];


 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID='{$prodid}';

 $sesdb-exec($sql);

 }


 On Wed, Aug 20, 2008 at 11:49 AM, Amy Gibbs [EMAIL PROTECTED]

 wrote:

 No errors reported, but it's not updating the db,

 error_reporting(E_ALL);

 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];


 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 $sesdb-exec($sql);

 }

 On 20 Aug 2008, at 10:11, Evert Lammerts wrote:

 can you put

 error_reporting(E_ALL);

 somewhere above the query and check if there's some output?

 On Wed, Aug 20, 2008 at 11:02 AM, Amy Gibbs [EMAIL PROTECTED]

 wrote:

 still not working,


 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 $sesdb-exec($sql);

 }

 On 20 Aug 2008, at 09:59, Evert Lammerts wrote:

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID='.$prodid.';

 Try to unquote $prodid:

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 Evert

 --

 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









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



Re: [PHP-DB] Sqlite 3 pdo update query problem

2008-08-20 Thread Evert Lammerts
It seems you've figured it out. I think you only need to chmod the DB
directory and you're good to go.

On Wed, Aug 20, 2008 at 1:04 PM, Amy Gibbs [EMAIL PROTECTED] wrote:
 OK, I found one problem, the database file was not writeable, I added this
 code to find the error:
 $sesdb-setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 However, I now get the following error:
 Warning: PDO::exec() [function.PDO-exec]: SQLSTATE[HY000]: General error: 14
 unable to open database file
 in/home/amy2203/public_html/willowtreecrafts/seweblink/seinvaudit.php on lin
 Sorry to have such a basic problem!
 On 20 Aug 2008, at 11:45, Evert Lammerts wrote:

 What happens if you try the UPDATE before a SELECT?

 $sesdb = new PDO('sqlite:file.sqlite3');
 var_dump($sesdb-exec(UPDATE ZITEM SET ZQUANTITY=0 WHERE ZPRODUCTID=1));

 On Wed, Aug 20, 2008 at 12:42 PM, Evert Lammerts
 [EMAIL PROTECTED] wrote:

 Sorry, I'm out of options. Hopefully somebody on the list has a little

 more experience with PDO.

 On Wed, Aug 20, 2008 at 12:26 PM, Amy Gibbs [EMAIL PROTECTED]
 wrote:

 It's still not working :(

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 $statement=null;

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];

 $sql = UPDATE ZITEM SET ZQUANTITY=0 WHERE ZPRODUCTID={$prodid};

 $sesdb-exec($sql);

 On 20 Aug 2008, at 11:10, Evert Lammerts wrote:

 A little time on google told me that if you want to do a write after a

 read (or the other way around) you need to free up the query resource

 - apparently they hold read / write locks.

 so, free up $statement before doing a write:

 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 $statement=null;

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];


 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID='{$prodid}';

 $sesdb-exec($sql);

 }


 On Wed, Aug 20, 2008 at 11:49 AM, Amy Gibbs [EMAIL PROTECTED]

 wrote:

 No errors reported, but it's not updating the db,

 error_reporting(E_ALL);

 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];


 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 $sesdb-exec($sql);

 }

 On 20 Aug 2008, at 10:11, Evert Lammerts wrote:

 can you put

 error_reporting(E_ALL);

 somewhere above the query and check if there's some output?

 On Wed, Aug 20, 2008 at 11:02 AM, Amy Gibbs [EMAIL PROTECTED]

 wrote:

 still not working,


 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 $sesdb-exec($sql);

 }

 On 20 Aug 2008, at 09:59, Evert Lammerts wrote:

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID='.$prodid.';

 Try to unquote $prodid:

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 Evert

 --

 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







 --
 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] Sqlite 3 pdo update query problem

2008-08-20 Thread Evert Lammerts
Can you post the code you're using when you get the timeout?

I guess you already tried to do a select only and an update only to
check if it works?

On Wed, Aug 20, 2008 at 1:11 PM, Amy Gibbs [EMAIL PROTECTED] wrote:
 OK, I found one problem, the database file was not writeable, I added this
 code to find the error:
 $sesdb-setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 then I got the following error:
 Warning: PDO::exec() [function.PDO-exec]: SQLSTATE[HY000]: General error: 14
 unable to open database file
 in/home/amy2203/public_html/willowtreecrafts/seweblink/seinvaudit.php on lin
 which was a permissions error on the folder,
 now i'm timing out and getting nothing,
 Sorry to have such a basic problem!
 On 20 Aug 2008, at 11:45, Evert Lammerts wrote:

 What happens if you try the UPDATE before a SELECT?

 $sesdb = new PDO('sqlite:file.sqlite3');
 var_dump($sesdb-exec(UPDATE ZITEM SET ZQUANTITY=0 WHERE ZPRODUCTID=1));

 On Wed, Aug 20, 2008 at 12:42 PM, Evert Lammerts
 [EMAIL PROTECTED] wrote:

 Sorry, I'm out of options. Hopefully somebody on the list has a little

 more experience with PDO.

 On Wed, Aug 20, 2008 at 12:26 PM, Amy Gibbs [EMAIL PROTECTED]
 wrote:

 It's still not working :(

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 $statement=null;

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];

 $sql = UPDATE ZITEM SET ZQUANTITY=0 WHERE ZPRODUCTID={$prodid};

 $sesdb-exec($sql);

 On 20 Aug 2008, at 11:10, Evert Lammerts wrote:

 A little time on google told me that if you want to do a write after a

 read (or the other way around) you need to free up the query resource

 - apparently they hold read / write locks.

 so, free up $statement before doing a write:

 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 $statement=null;

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];


 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID='{$prodid}';

 $sesdb-exec($sql);

 }


 On Wed, Aug 20, 2008 at 11:49 AM, Amy Gibbs [EMAIL PROTECTED]

 wrote:

 No errors reported, but it's not updating the db,

 error_reporting(E_ALL);

 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];


 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 $sesdb-exec($sql);

 }

 On 20 Aug 2008, at 10:11, Evert Lammerts wrote:

 can you put

 error_reporting(E_ALL);

 somewhere above the query and check if there's some output?

 On Wed, Aug 20, 2008 at 11:02 AM, Amy Gibbs [EMAIL PROTECTED]

 wrote:

 still not working,


 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 $sesdb-exec($sql);

 }

 On 20 Aug 2008, at 09:59, Evert Lammerts wrote:

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID='.$prodid.';

 Try to unquote $prodid:

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 Evert

 --

 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







 --
 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] Sqlite 3 pdo update query problem

2008-08-20 Thread Evert Lammerts
Forget my last mail. Good to hear it's solved.

On Wed, Aug 20, 2008 at 1:20 PM, Evert Lammerts
[EMAIL PROTECTED] wrote:
 Can you post the code you're using when you get the timeout?

 I guess you already tried to do a select only and an update only to
 check if it works?

 On Wed, Aug 20, 2008 at 1:11 PM, Amy Gibbs [EMAIL PROTECTED] wrote:
 OK, I found one problem, the database file was not writeable, I added this
 code to find the error:
 $sesdb-setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 then I got the following error:
 Warning: PDO::exec() [function.PDO-exec]: SQLSTATE[HY000]: General error: 14
 unable to open database file
 in/home/amy2203/public_html/willowtreecrafts/seweblink/seinvaudit.php on lin
 which was a permissions error on the folder,
 now i'm timing out and getting nothing,
 Sorry to have such a basic problem!
 On 20 Aug 2008, at 11:45, Evert Lammerts wrote:

 What happens if you try the UPDATE before a SELECT?

 $sesdb = new PDO('sqlite:file.sqlite3');
 var_dump($sesdb-exec(UPDATE ZITEM SET ZQUANTITY=0 WHERE ZPRODUCTID=1));

 On Wed, Aug 20, 2008 at 12:42 PM, Evert Lammerts
 [EMAIL PROTECTED] wrote:

 Sorry, I'm out of options. Hopefully somebody on the list has a little

 more experience with PDO.

 On Wed, Aug 20, 2008 at 12:26 PM, Amy Gibbs [EMAIL PROTECTED]
 wrote:

 It's still not working :(

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 $statement=null;

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];

 $sql = UPDATE ZITEM SET ZQUANTITY=0 WHERE ZPRODUCTID={$prodid};

 $sesdb-exec($sql);

 On 20 Aug 2008, at 11:10, Evert Lammerts wrote:

 A little time on google told me that if you want to do a write after a

 read (or the other way around) you need to free up the query resource

 - apparently they hold read / write locks.

 so, free up $statement before doing a write:

 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 $statement=null;

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];


 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID='{$prodid}';

 $sesdb-exec($sql);

 }


 On Wed, Aug 20, 2008 at 11:49 AM, Amy Gibbs [EMAIL PROTECTED]

 wrote:

 No errors reported, but it's not updating the db,

 error_reporting(E_ALL);

 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];


 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 $sesdb-exec($sql);

 }

 On 20 Aug 2008, at 10:11, Evert Lammerts wrote:

 can you put

 error_reporting(E_ALL);

 somewhere above the query and check if there's some output?

 On Wed, Aug 20, 2008 at 11:02 AM, Amy Gibbs [EMAIL PROTECTED]

 wrote:

 still not working,


 $sesdb = new PDO('sqlite:file.sqlite3');

 $query=SELECT ZNAME, ZQUANTITY, ZPRODUCTID FROM ZITEM WHERE ZCategory !=

 14;

 $statement= $sesdb-query($query);

 $result=$statement-fetchAll();

 foreach ($result as $product) {

 $prodname=$product[0];

 $prodqty = $product[1];

 $prodid=$product[2];

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 $sesdb-exec($sql);

 }

 On 20 Aug 2008, at 09:59, Evert Lammerts wrote:

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID='.$prodid.';

 Try to unquote $prodid:

 $sql = UPDATE ZITEM SET ZQUANTITY='0' WHERE ZPRODUCTID={$prodid};

 Evert

 --

 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







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

2008-08-15 Thread Evert Lammerts
You can set a save handler for the session and save the session to the
database (http://php.net/session_set_save_handler). But it will be
hard for server 2 to find out which data belongs to a user that just
came from server 1 - you can't rely on a session id found in the url
or in a cookie since... well, that's obvious. However, there might be
some secure standard for this that I'm not aware of (plus a million
semi secure hacks to think of).

I think I'd rather solve it on a different level and ensure HA by load
balancing the two apache nodes. Check linuxvirtualserver.org and
linux-ha.org - and google gives you tons of articles telling you how
to set it up.

On Fri, Aug 15, 2008 at 8:39 AM, Ron [EMAIL PROTECTED] wrote:
 Hi,

 I'm not sure if this is the correct mailing list.

 anyway, i have multiple apache servers, my pages are on php, i'm using DNS
 SRV, so that at least it's up even when one goes down.

 my prob is, user are logging in on my site and i am using their username as
 a session variable to manage things on their portal, but sometimes when they
 they login on server 1, because of dns srv, they sometimes browse server 2
 while they are logged in on server 1. so when they are on server 2 the
 session variables are lost already.

 both apache are talking to a single mysql cluster, if  i save my session on
 the db, would it prevent the session variable to get lost when a user 1
 brose from server 1 o server 2 or vice versa?

 thank you

 regards,
 ron

 --
 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] mathematical discrepancies

2008-08-14 Thread Evert Lammerts
Check http://php.net/manual/en/language.types.float.php

Quote:

Warning
Floating point precision

It is typical that simple decimal fractions like 0.1 or 0.7 cannot be
converted into their internal binary counterparts without a small loss
of precision. This can lead to confusing results: for example,
floor((0.1+0.7)*10) will usually return 7 instead of the expected 8,
since the internal representation will be something like 7.9.

This is due to the fact that it is impossible to express some
fractions in decimal notation with a finite number of digits. For
instance, 1/3 in decimal form becomes 0.3.

So never trust floating number results to the last digit, and never
compare floating point numbers for equality. If higher precision is
necessary, the arbitrary precision math functions and gmp functions
are available.


On Thu, Aug 14, 2008 at 2:55 PM, Andrew Martin [EMAIL PROTECTED] wrote:
 Hello,

 Can anybody shed any light on this behaviour please?

 PHP Version 5.2.5 on XP


 $a = 1754.00 ;
 $b = 1754.03 ;
 $diff = abs($b) - abs($a);

 echo $diffbr/; //output: 0.03

 $a = 1754.00 ;
 $b = 1754.09 ;
 $diff = abs($b) - abs($a);

 echo $diffbr/; //output :0.08999

 $a = 1754.01 ;
 $b = 1754.02 ;
 $diff = abs($b) - abs($a);

 echo $diff; //output: 0.00


 Is this expected behaviour? Can anybody reproduce this?

 Many thanks,


 Andy

 --
 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] RE: [PHP] If Column Exists

2008-08-13 Thread Evert Lammerts
SHOW COLUMNS FROM tablename;

Also check http://dev.mysql.com/doc/refman/5.0/en/

On Wed, Aug 13, 2008 at 3:02 PM, Simcha [EMAIL PROTECTED] wrote:
 You can try 'select `testcol` from `table`' and then check if you got a
 mysql_error().



 -Original Message-
 From: Robin Vickery [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, August 13, 2008 10:33 AM
 To: php List
 Subject: Re: [PHP] If Column Exists

 2008/8/12 VamVan [EMAIL PROTECTED]:
 Hello,

 I am working on data migration for one mysql db to another using PHP. How
 do
 I check if a particular table has a particular column. If not alter...

 Thanks


 Use the information_schema:

 SELECT COUNT(*) AS column_exists FROM information_schema.COLUMNS WHERE
 TABLE_SCHEMA='db_name' AND TABLE_NAME='table_name' AND
 COLUMN_NAME='column_name';

 -robin

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

 No virus found in this incoming message.
 Checked by AVG - http://www.avg.com
 Version: 8.0.138 / Virus Database: 270.6.2/1609 - Release Date: 13/08/2008
 06:43


 --
 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] mysql_connect(): Lost connection to MySQL server during query

2008-08-12 Thread Evert Lammerts
http://dev.mysql.com/doc/refman/5.0/en/gone-away.html should get you
started. Good luck!

On Tue, Aug 12, 2008 at 8:27 AM, Manoj Singh [EMAIL PROTECTED] wrote:
 Hello all,
 I am getting this error when connecting to the database through
 mysql_connect function.

 Error: mysql_connect() [a
 href='function.mysql-connect'function.mysql-connect/a]: Lost connection
 to MySQL server during query

 I am getting this error when the db server has the high load.

 Please help me out to fix this error.

 Best Regards,
 Manoj Kumar SIngh


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



Re: [PHP-DB] I want to remove the last comma

2008-08-12 Thread Evert Lammerts
JSON does the trick for you (www.json.org), and PHP's glob() gets rid
of your readdir() overhead (you'll need PHP 5.2 or later for this):

$path = /path/to/images/;
$images = glob($path . {*.jpg,*.gif,*.png}, GLOB_BRACE);
for ($i = 0; $i  sizeof($images); $i++)
$images[$i] = array($images[$i], $path . $images[$i]);
$js_output = var tinyMCEImageList =  . json_encode($images) . ;;

I'd also save myself the overhead of repeating the same path $i times
in my array, and instead just create a JS object:

$path = /path/to/images/;
$js_output = var tinyMCEImageList =  . json_encode(array(path =
$path, images = glob($path . {*.jpg,*.gif,*.png}, GLOB_BRACE))) .
;;

You can append the path client side after he page is parsed.

Apart from that, echo-ing javascript in your php code is never really
a good idea when it comes to louse coupling of your web applications.
If that's no consideration for you - party on.

Again, this is not a PHP-DB question, you should subscribe to the
PHP-GENERAL (or-whatever-it's-called) list.


On Tue, Aug 12, 2008 at 9:27 PM, A. Joseph [EMAIL PROTECTED] wrote:
 This the script
 $dir = images;
 $d = opendir($dir);
 $out = 
 var tinyMCEImageList = new Array(\n;
 while(false != ($entry = readdir($d))) {
if(preg_match(/(.jpg|.gif|.png)$/, $entry) != false) {
$out .= ['{$entry}', '{$dir}/{$entry}'],\n;
}

 }
 $out .= );\n;

 This the out put

 var tinyMCEImageList = new Array(
 ['1_h_1.gif', 'images/1_h_1.gif'],
 ['1_h_2.gif', 'images/1_h_2.gif'],
 ['rss_2.jpg', 'images/rss_2.jpg'],
 ['spacer.gif', 'images/spacer.gif'],  #  I want to remove this comma
 );

 if the last element (['spacer.gif', 'images/spacer.gif'],) contain comma,
 javascript will return error, so i want to remove it.


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



Re: [PHP-DB] $_SESSION issues - possible security hole?

2008-08-10 Thread Evert Lammerts
If it changes the value of $_SESSION['rights'], then how come
if ($_SESSION['rights'] != super)
on line 14 doesn't exit()? Or does that happen when you hit refresh
the second time? Or does the user it changes to also have 'super'
rights?

Why use extract()? Try commenting it out... apart from it being
overhead in this case, it seems like a bad idea importing variable
names into the symbol table for the global scope. It works since
you're skipping the $type parameter and so EXTR_OVERWRITE is used, but
this also doesn't seem anything to trust.

Debugging PHP with XDebug usually helps me in cases like this. If you
can, install it to your test server and do a trace.

On Sun, Aug 10, 2008 at 7:34 PM, Darron Butler [EMAIL PROTECTED] wrote:
 I have built an application where users have to log in (the user data is
 stored in MySQL). I have 3 levels of rights for users; 1-normal rights,
 2-admin rights, and 3-super user rights. When a user logs in, I set the
 $_SESSION['rights'] variable accordingly so I can reference it thru out the
 site. I have around a dozen pages where the login session information and
 the user rights piece work just fine. However, I'm creating an
 administration page where admins have some functionality but super users
 have all functionality and I've run into issues. I was using the session
 rights variable in a number of different IF statements to display and during
 a simple test I hit the refresh button on my browser and found that when I
 did so it CHANGED my session rights to those of a different user!?!? I have
 looked thru my code until I'm blue in the face and have even boiled the code
 down to the simpest display possible, yet when I hit refresh, it still
 changes the user and rights info (note all the other pages work fine).

 I have been able to determine that there must be something in my USERS query
 that is causing the issue. I changed the query to get data from a completely
 different table and show it in a select list and hitting refresh does NOT
 change the user or the user rights! So.does this mean querying the very
 table that lists users information (with data like rights and user in
 it) somehow can change the $_SESSION variables?? That appears to be what's
 going on, but I thought you had to explicitly assign the $_SESSION variables
 before they could be changed. Help!!! I have included my code and the
 database table structure below:

 ?php

 /***

Program is only available to admins and super users. This page
allows for the adding/editing of user accounts and priveledges
as well as allowing for application messages, application
lockdown/shutdown, and standard parts administration.

 /

 include (php_header.inc);

 if ($_SESSION['rights'] != super)

{

header(location: landing.php);
exit ();

}

 /**  ADMINISTER USERS */

 $query1 = select * from USERS order by user;
 $result1 = mysql_query($query1) or die (Couldn't select all users -
 super);

 include (html_header.inc);

 echo 

p{$_SESSION['user']}, {$_SESSION['rights']}/p\n
pform action='edit_user.php' method='post'Choose a user to edit:
 select name='user'\n;

 while ($row = mysql_fetch_array($result1, MYSQL_ASSOC))

{

extract($row);

echo 

option value='$user'$fname $lname - $user\n;

}

 echo 

/select input type='submit' value='Edit User'/form/p\n
/body\n
/html;

 ?

 and here is the included file:

 ?php

 /

 This is the standard header for every page and should be
 included after the PHP opening tag on each page. This program
 ensures that all pages can only be accessed by users that are
 legitimately logged on. This program also allows for
 administratively disabling the application by super users. After
 disabling, only superusers can make changes.

 /

 session_start();

 include (special_characters.inc);

 /** AUTHORIZATION CHECK */

 if ($_SESSION['auth'] != yes)

 {

 header (location: index.php);
 exit();

 }

 if ($_SESSION['rights'] != super)

 {

 $query = select * from APP_STATUS;
 $result = mysql_query($query) or die (Couldn't select APP_STATUS);
 $app = mysql_fetch_array ($result,MYSQL_ASSOC);

 if ($app['app_status'] == 2)

 {

 $msg = $app['app_message'];
 die($msg);

 }

 }

 ?

 my database table for the users looks like this:

 Field Type
 user varchar(20) PRIMARY KEY
 pwd varchar(255)
 fname varchar(20)
 lname varchar(20)
 email varchar(40)
 rights varchar(20)
 level varchar(20)
 credentials text
 admin varchar(20)


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



Re: [PHP-DB] $_SESSION issues - possible security hole?

2008-08-10 Thread Evert Lammerts
 Why use extract()? Try commenting it out... apart from it being

If you use 'register globals' there's a good chance that a variable
$rights exists because it's a key in your $_SESSION array (don't shoot
me if I'm wrong, I've never worked with 'register globals'). By using
extract() without the $type parameter (so with EXTR_OVERWRITE set),
the $type variable is overwritten.

So do try commenting it out.

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



Re: [PHP-DB] Formatting output with json_encode

2008-07-14 Thread Evert Lammerts
Check out http://www.json.org/ for JSON structures.

In javascript an Array object is a special implementation of the
Object object (like all objects other than Object) - an Array object
can only have numerical indices, an Object object can have textual
indices too. If you json_encode a php array with textual indices it
translates to {...} - a javascript Object object. If you json_encode a
php array with numerical indices it translates to [...] - a javascript
Array object.

It seems to me that what you're using is mysql_fetch_array
(http://nl3.php.net/manual/en/function.mysql-fetch-array.php) with
either no result_type parameter set, or result_type set to MYSQL_BOTH.
If you want a javascript Array object, use either
mysql_fetch_array($result, MYSQL_NUM) or mysql_fetch_row($result). If
you want a javascript Object object, use either
mysql_fetch_array($result, MYSQL_ASSOC) or mysql_fecth_assoc($result).

Evert

On Mon, Jul 14, 2008 at 8:21 AM, Ron Piggott [EMAIL PROTECTED] wrote:
 I am using json_encode to output the results of a mySQL query which is
 part of a jquery  ajax.

 $result = json_encode($array);
 echo $result;

 The output on my screen is:

 {0:John 14:27,verse_reference:John 14:27}

 How do I format json_encode output?  I would like

 John 14:27

 to be what is displayed.

 Ron


 --
 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] Apache crashes every time I call mysqli_fetch_assoc()

2008-07-10 Thread Evert Lammerts
Check out your system's logs / event viewer. If apache crashes (how do
you notice?) there should be some indication of the reason.

Evert

On Thu, Jul 10, 2008 at 2:24 AM, Chris [EMAIL PROTECTED] wrote:
 Bonger O wrote:
 Hi,

 I have set up an environment on my Vista laptop comprising of Apache 2.2,
 MySQL Server 5.1 and Php 5.2.5.

 I'm using a simple php program that I found in a PHP/SQL book. The PHP
 program queries a MySQL table and traverses the results array of the query
 and should display on screen. However, there seems to be a problem with my
 environment and as every time I run the program I get the error *Apache
 HTTP server stopped working and was closed*.

 Below is the code I am using, but I have managed to narrow the problem down
 to *$row = mysqli_fetch_assoc($result);*
 For some reason this is causing the crash. Would there be any reason that
 this function cant be found perhaps? I really have no clue!!!

 If the function doesn't exist php gives that error, not a random crash.

 Does the query work outside of php (type it in to the mysql console
 directly) ?

 Does it happen for a particular record? ie it gets up to record #5
 before it crashes. What's in record #5?

 How many records are returned by the query? Maybe you're selecting too
 much data and the srever is killing it because it's taking too much
 memory (random guess :P).

 Do you have another environment you can try it in?
 What happens there when you:
 - use the same database
 - use a different database

 --
 Postgresql  php tutorials
 http://www.designmagick.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] One field or a new table?

2008-06-21 Thread Evert Lammerts
mysql.com says:

Foreign key enforcement offers several benefits to database developers:
*  Assuming proper design of the relationships, foreign key
constraints make it more difficult for a programmer to introduce an
inconsistency into the database.
*  Centralized checking of constraints by the database server
makes it unnecessary to perform these checks on the application side.
This eliminates the possibility that different applications may not
all check the constraints in the same way.
*  Using cascading updates and deletes can simplify the
application code.
*  Properly designed foreign key rules aid in documenting
relationships between tables.

Do keep in mind that these benefits come at the cost of additional
overhead for the database server to perform the necessary checks.
Additional checking by the server affects performance, which for some
applications may be sufficiently undesirable as to be avoided if
possible. (Some major commercial applications have coded the foreign
key logic at the application level for this reason.)

(http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-foreign-keys.html)

Obviously. Regardless, whenever a many to many relationship exists, a
link table is the solution, with or without foreign keys. I don't know
what the overhead of using foreign keys is, but that's something you
can test. ON UPDATE and ON DELETE do make things a lot easier.

Evert


On Fri, Jun 20, 2008 at 2:41 PM, J. Hill [EMAIL PROTECTED] wrote:
 In a number of cases I have used link tables like you are suggesting here,
 but I am curious if using foreign key constraints, in the situation
 described, is the best solution?

 I am not an expert (so this is a real question), but I remember some years
 ago a database programmer (I believe he worked for MySQL) advising against
 the use of foreign key constraints when possible, due to the overhead when
 updating. I know avoiding them requires careful programming/scripting, but
 his argument seems logical to me.

 If he was wrong, I'd sure like to know, because that would make my
 development work much easier.

 Jeff.


 Evert Lammerts wrote:

 Whenever you can say:

 X has zero or more Y and Y has zero or more X you're talking about
 a Many to Many relationship between X and Y, and you need a link
 table with foreign key constraints.

 Example:

 Table X:
 id name
 1   A
 2   B
 3   C

 Table Y:
 id name
 1   K
 2   L
 3   M

 Linktable:
 X_id Y_id
 1  1
 1  2
 2  3
 2  1
 3  1
 3  2
 3  3

 The link table is the only table that needs to be updated when a
 relationship between an entry of X and an entry of Y starts to exist
 (in your example, a user from X collects an item from Y).

 It is wise to use foreign keys when using linktables - but you can
 only do this when using INNODB. Check
 http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html

 Evert

 On Fri, Jun 20, 2008 at 8:38 AM, Hussein Jafferjee
 [EMAIL PROTECTED] wrote:


 Hey Guys,



 I have been developing for a while and never found the best solution yet.
 The question is lets say a game has 10 collectibles you can earn, to keep
 track of the number of collectibles each user has, do you have one field in
 the users table with all the numbers separated via a divider, or do you make
 a new table called collectibles and have each one as a field?



 These are high traffic sites (100,000+ people) and so I was initially
 thinking the solution of creating a separate table is best because the main
 users row is loaded on every page, and on top of that you would need to use
 explode on the field.



 Currently I am having a separate table, but I was wondering if people have
 better solutions.



 Hussein J.







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



Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-20 Thread Evert Lammerts
I should've checked the assumption.

A little strange though for a scripting language. I'd say, since
default behaviour of mysql_* functions is to assume the last opened
link when a parameter is not passed, and since default behaviour is to
evaluate null, false and 0 the same, mysql_* functions should issue a
warning when a not valid link is passed but still use the last opened
link (in that logic, null should also generate a warning though). I'm
guessing the reason is that mysql_connect returns false when it fails,
but i can't see a reason why an undefined variable cannot be used.

All that and I don't remember what it was for.

On Fri, Jun 20, 2008 at 1:57 AM, Chris [EMAIL PROTECTED] wrote:

 [new code]
 if (!mysql_connect($a, $b, $c)) return;

 if (!mysql_select_db($dbname)) return;

 $res = mysql_query(SELECT * FROM manual;, $link);
 [/new code]


 Isn't going to work because $link is not defined and definitely not a
 resource like mysql_query expects.

 OR, optionally, to surpress the warnings:

 [new code]
 if (!mysql_connect($a, $b, $c)) return;

 $link = null;

 if (!mysql_select_db($dbname)) return;

 $res = mysql_query(SELECT * FROM manual;, $link);
 [/new code]

 Isn't going to work because mysql_query needs a resource to connect to.
 You've defined $link as null.

 $ cat test.php
 ?php
 $user = 'my_db_user';
 $pass = 'my_pass';
 $host = 'localhost';
 $db = 'my_db';

 error_reporting(E_ALL);
 ini_set('display_errors', true);

 if (!mysql_connect($host, $user, $pass)) {
die(unable to connect);
 }

 if (!mysql_select_db($db)) {
die(unable to choose db);
 }

 $link = null;
 $res = mysql_query('select version() as version', $link);
 while ($row = mysql_fetch_assoc($res)) {
print_r($row);
 }


 $ php test.php

 Warning: mysql_query(): supplied argument is not a valid MySQL-Link
 resource in /path/to/test.php on line 19

 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL
 result resource in /path/to/test.php on line 20


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


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



Re: [PHP-DB] One field or a new table?

2008-06-20 Thread Evert Lammerts
Whenever you can say:

X has zero or more Y and Y has zero or more X you're talking about
a Many to Many relationship between X and Y, and you need a link
table with foreign key constraints.

Example:

Table X:
id name
1   A
2   B
3   C

Table Y:
id name
1   K
2   L
3   M

Linktable:
X_id Y_id
1  1
1  2
2  3
2  1
3  1
3  2
3  3

The link table is the only table that needs to be updated when a
relationship between an entry of X and an entry of Y starts to exist
(in your example, a user from X collects an item from Y).

It is wise to use foreign keys when using linktables - but you can
only do this when using INNODB. Check
http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html

Evert

On Fri, Jun 20, 2008 at 8:38 AM, Hussein Jafferjee
[EMAIL PROTECTED] wrote:
 Hey Guys,



 I have been developing for a while and never found the best solution yet.
 The question is lets say a game has 10 collectibles you can earn, to keep
 track of the number of collectibles each user has, do you have one field in
 the users table with all the numbers separated via a divider, or do you make
 a new table called collectibles and have each one as a field?



 These are high traffic sites (100,000+ people) and so I was initially
 thinking the solution of creating a separate table is best because the main
 users row is loaded on every page, and on top of that you would need to use
 explode on the field.



 Currently I am having a separate table, but I was wondering if people have
 better solutions.



 Hussein J.



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



Re: [PHP-DB] PHP-MySQL connection for particular module

2008-06-18 Thread Evert Lammerts
Pastebin works lots better when you're posting code: www.pastebin.com

I don't see your database.php included in both of these modules. Where
do you include it?

EVert

On Wed, Jun 18, 2008 at 9:38 PM, bateivan [EMAIL PROTECTED] wrote:

 Hello,

 To answer these qwestions:
 1. I am using include in my code.
 2. About the $link = mysql_connect('localhost', 'root', 'testing');
 variable. I can just include this line before mysql_query function and it
 works even without entering into mysql_query the $link variable. (Like the
 connection is waking up).
 3.My php.ini register_globals is off as suggested for new versions of PHP
 but include file should work instead according to the manual.
 4. I am posting some of my code to compare. Module carmade.php works v.s.
 login.php which does not. Also, I am posting my database.php which is
 establishing the connection and is included in every page through
 layout.php-common.php-database.php.

 carmade.php:
 ?php
 include $_SERVER['DOCUMENT_ROOT'].
'/layout.php';

 // Quick Login session check
 login_check();

 switch($_REQUEST['req']){
   // Insert Case
   case create_carmade:
 myheader(Добавяне на автомобилни марки в списъка);

 // Double check form posted values are there
 // before performing INSERT query
 if(!$_POST['car_descr']){
 echo 'p align=centerЛипсва информациятя от формата!/p'.
 'p align=centerМоля, използвайте бутона'.
 'Назад и въведете данните отново!/p';
  footer();
 exit();
 }

 // Insert Query
 $sql = mysql_query(INSERT INTO carmade
 (car_descr)
 VALUES('{$_POST['car_descr']}'));

 // Insert query results
 if(!$sql){
 echo Грешка при въвеждане на данните:.mysql_error();
 } else {

 echo 'p align=centerМарката '.$_POST['car_descr'].
 'е въведенаbr/с номер:'.mysql_insert_id();
 echo 'br / /admin/carmade.php?req=new_carmade Искате ли да'.
'въведете друга марка? ';
 }
   break;

   // Create car made form case
   case new_carmade:
  myheader(Въвеждане на нова автомобилна марка);
  include $_SERVER['DOCUMENT_ROOT'].
  '/html/forms/carmade_insert.html';
  footer();
   break;

   default:
  myheader(Администриране на списъка с автомобилните марки);
  include $_SERVER['DOCUMENT_ROOT'].
  '/html/carmade_admin.html';
  footer();
   break;

 }
 ?

 login.php:
 ?php
 include $_SERVER['DOCUMENT_ROOT'].
'/layout.php';


 switch($_REQUEST['req']){

 case validate:

   $validate = mysql_query(SELECT * FROM members
   WHERE username = '{$_POST['username']}'
   AND password = md5('{$_POST['password']}')
   );

   $num_rows = mysql_num_rows($validate);

   if($num_rows == 1){
  while($row = mysql_fetch_assoc($validate)){
 $_SESSION['login'] = true;
 $_SESSION['userid'] = $row['member_id'];
 $_SESSION['first_name'] = $row['first_name'];
 $_SESSION['last_name']  = $row['last_name'];
 $_SESSION['email_address'] = $row['email_address'];

 if($row['admin_access'] == 1){
$_SESSION['admin_access'] = true;
 }
 $login_time = mysql_query(UPDATE members
   SET last_login=now()
   WHERE id='{$row['id']}');
   }
   header(Location: /loggedin.php);
   } else {
  myheader(Входът в административната зона е неуспешен!);
  echo 'p align=centerВходът в страницата не е успешен!/p';
  echo 'p align=centerПроверете потребителското си '.
   'име и паролата си и опитайте пак или се '.
   'обадете на администратора./p';
  footer();
   }
 break;

 default:
   myheader(Вход!);
  include $_SERVER['DOCUMENT_ROOT'].
  '/html/forms/login_form.html';
   footer();
 break;
 }
 ?

 database.php:
 ?php
 $link = mysql_pconnect('localhost','root','testing');
 $set = mysql_query('SET NAMES CP1251');
 $set = mysql_query('SET_COLLATION=CP1251_GENERAL_CI');
 mysql_select_db('samek_db', $link) or die(mysql_error());

 ?

 common.php:
 ?php

 // Include Meta Content Class
 include $_SERVER['DOCUMENT_ROOT'].'/classes/clsMetaContent.php';

 // Include Email Class
 include $_SERVER['DOCUMENT_ROOT'].'/classes/clsEmail.php';

 // Include Database Connection File
 include $_SERVER['DOCUMENT_ROOT'].'/includes/database.php';

 // Include Session File
 include $_SERVER['DOCUMENT_ROOT'].'/includes/session.php';

 ?

 Thank you for your help


 You're very welcome, I understand that you need a solution which allows you
 to keep using the connection this way.

 I doubt that your php.ini is the cause so I'll suggest the following:

 Try executing your MySQL queries by passing the $link variable to the
 function as the connection resource:

 mysql_query(SELECT..., $link);

 Something that also might cause it is that 

Re: [PHP-DB] Select query with Forein key Relation

2008-04-23 Thread Evert Lammerts

SELECT *
FROM gig
LEFT JOIN genre ON gig.genreId = genre.genreId
LEFT JOIN venue ON gig.venueID = venue.vid
WHERE gig.gigid = $gigdetail

I'd replace the dash with [table].[columnames]. Also, you're using four 
different naming conventions in your columns - gigid, genreId, venueID 
and vid. If I were you I'd go for one of them and apply this to all.


Evert

Nasreen Laghari wrote:

Hi,
 
I have a table which contains 2 foreign key relation columns. I'm trying to get all columns from main table as well as all column from those 2 foreign key relation tables. 
 
The query i'm using is :
 
select * from gig where gig.gigid = $gigDetail LEFT JOIN genre ON gig.genreId=genre.genreId LEFT JOIN venue ON gig.venueID = venue.vid ORDER BY gig.gigid; 
 
is this query OK? 
 
I know  how to get value from gig table colums but how could i get value of columns from venue table?
 
Regards
 
Nasreen
 
 
 




Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
  



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



Re: [PHP-DB] Select query with Forein key Relation

2008-04-23 Thread Evert Lammerts
It'd be consistent to use uniform naming conventions for your columns. 
E.g., an ID column is called 'id' in every table, and if you use two 
words in a column name, to separate them either by an underscore or by a 
capital letter for the second word.


In PHP a dot is an append operator - to reference a member of a certain 
namespace you use '-'. In this case you don't need it though. To get a 
column 'vname' from the table 'venue' you use:


while ($row = mysql_fetch_assoc($result)) {
   $sub = $row[venue.vname];
}

Remember that in this case, $sub will always only hold the value of the 
last result - or of the only result if there is only one result row.


Nasreen Laghari wrote:

Hi Evert,
 
What to you mean by this If I were you I'd go for one of them and 
apply this to all.

also to get the value of columns do i need to do following in php
 
/while ($row = mysql_fetch_array($result))

  {/
/$sub= $row[venue].[vname];/
/}/
 
Regards
 

 
- Original Message 

From: Evert Lammerts [EMAIL PROTECTED]
To: Nasreen Laghari [EMAIL PROTECTED]
Cc: php-db@lists.php.net
Sent: Wednesday, April 23, 2008 11:48:39 AM
Subject: Re: [PHP-DB] Select query with Forein key Relation

SELECT *
FROM gig
LEFT JOIN genre ON gig.genreId = genre.genreId
LEFT JOIN venue ON gig.venueID = venue.vid
WHERE gig.gigid = $gigdetail

I'd replace the dash with [table].[columnames]. Also, you're using four
different naming conventions in your columns - gigid, genreId, venueID
and vid. If I were you I'd go for one of them and apply this to all.

Evert

Nasreen Laghari wrote:
 Hi,
 
 I have a table which contains 2 foreign key relation columns. I'm 
trying to get all columns from main table as well as all column from 
those 2 foreign key relation tables.
 
 The query i'm using is :
 
 select * from gig where gig.gigid = $gigDetail LEFT JOIN genre ON 
gig.genreId=genre.genreId LEFT JOIN venue ON gig.venueID = venue.vid 
ORDER BY gig.gigid;
 
 is this query OK?
 
 I know  how to get value from gig table colums but how could i get 
value of columns from venue table?
 
 Regards
 
 Nasreen
 
 
 




 Be a better friend, newshound, and know-it-all with Yahoo! Mobile. 
Try it now.



  


 Be a better friend, newshound, and
 know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
 





Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try 
it now. 
http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ%20



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



Re: [PHP-DB] Date calculation from MySql table

2008-04-12 Thread Evert Lammerts

Something like this should work.

$today = mktime(0, 0, 0, date(m), date(d), date(Y));
$tomorrow = mktime(0, 0, 0, date(m), date(d) + 1, date(Y));
$sql = SELECT COUNT(*) FROM table WHERE regdate BETWEEN {$today} AND 
{$tomorrow};


$thismonth = mktime(0, 0, 0, date(m), 1, date(Y));
$nextmonth = mktime(0, 0, 0, date(m) + 1, 1, date(Y));
$sql = SELECT COUNT(*) FROM table WHERE regdate BETWEEN {$thismonth} 
AND {$nextmonth};


$thisyear = mktime(0, 0, 0, 1, 1, date(Y));
$nextyear = mktime(0, 0, 0, 1, 1, date(Y) + 1);
$sql = SELECT COUNT(*) FROM table WHERE regdate BETWEEN {$thisyear} AND 
{$nextyear};


HOWEVER, consider to use the mysql date functions instead of a unix 
timestamp.


A. Joseph wrote:

I want to calculate the registed users today
Also total users this week
Total users this month
Total users this year

The Mysql table has a row of INT(11) with time() value inserted.

I did something like this
$today = strtotime(+1 day)
Then $sql = SELECT COUNT(*) FROM table WHERE dateReg = $today;

Same with year/months also, only I use strtotime(+1 week) for a week,
strtotime(+1 month) for a month,

Can someone help me with this calculation?

On 4/7/08, Bruno Lustosa [EMAIL PROTECTED] wrote:
  

On Mon, Apr 7, 2008 at 2:42 PM, Dee Ayy [EMAIL PROTECTED] wrote:


 I was thinking of using output buffering and then making 1 call to
 utf8_encode, but I think a better question is, how do I stop using
 utf8_encode completely?
  

If all components are using utf-8, you should have no problems with
charsets at all. By all components, I mean:
- Script files in utf-8;
- Database in utf-8;
- Database connection using utf-8;
- Content-type header set to utf-8.
With all these, you're free of charset hell, and can enjoy the beauty
of utf-8 completely without problems.



 The rendered view I see in Firefox 2.0.0.12 is a question mark ?
 where the French character should have appeared.  If I use
 utf8_encode, the character appears as it should.
  

Question mark means the character is not utf-8. Check where it comes
from. Might be the database or the way you are connecting to it. I
don't know much about mysql, I use postgresql. With it, you just have
to call pg_set_client_encoding() to make the connection in utf-8 mode,
and create database with encoding='unicode' to set up a database
using utf-8.



 Luckily I'm on PHP 4.3.10, so I can't see what mb_check_encoding would
 report -- if that would even help normally.
  

Shouls upgrade to PHP 5. PHP 4 is way out of date, is not getting
updates anymore, and will not even get security bugfixes after august
8th. It's been almost 4 years since PHP 5 was released.

http://www.php.net/archive/2007.php

Check the PHP 4 end of life announcement.

--
Bruno Lustosa [EMAIL PROTECTED]
ZCE - Zend Certified Engineer - PHP!
http://www.lustosa.net/

--
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] mysql_num_rows, resource id #

2008-03-27 Thread Evert Lammerts

Richard Dunne wrote:
In my code below, I am trying to verify that the query is selecting data from both rows of my answers table.  I have run the query on my MySQL CLI and getting answers from both rows, but running this script I get $rows = 0.  I can't figure out why its not returning 2 for the number of rows.  It is not giving me any error msgs such as cannot connect.  


Also can tell me where I can find documentation on resource id #, such as 
resource(5)?
?PHP
DEFINE (host,localhost);
DEFINE (user,root);
DEFINE (password,pasword);
DEFINE (database,questions);

$connection=mysql_connect(host,user,password) or die ('Could not connect' . 
mysql_error() );

$dbConnect=mysql_select_db('questions',$connection);
if (!$dbConnect) {die ('Could not connect to database' . mysql_error() );}

$result = mysql_query(Select answer from answers where 
studentID='A123456789') or die(mysql_error());
$rows = mysql_num_rows($result);
echo $rows;


?

Still no luck then. Try selecting the DB without the connection parameter:

$dbConnect=mysql_select_db('questions');

And don't forget to set error_reporting(E_ALL) above your code.

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



Re: [PHP-DB] numeric string to single digit array

2008-03-26 Thread Evert Lammerts



I ran this

$query =Select answer from answers where studentID ='A123456789';
$result = mysql_query($query,$connection);
$resultArray = str_split($result,1);
$count = count($resultArray);
  


Where's the fetch?

|$result = mysql_query(SELECT answer FROM answers WHERE studentID = 
'A123456789';);

$count = 0;
while ($row = mysql_fetch_assoc($result)) {
   $count++;
}

|Of course you should count in the query if the result itself is not used:

|$result = mysql_query(SELECT COUNT(answer) AS nr_of_results FROM 
answers WHERE studentID = 'A123456789';);

$row = mysql_fetch_assoc($result);
$count = $row['||nr_of_results||'];||
|
Evert

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



Re: [PHP-DB] numeric string to single digit array

2008-03-26 Thread Evert Lammerts



PHP is telling me that the resource I am using for mysql_fetch_assoc is invalid:

$query =Select answer from answers where studentID ='A123456789';
$result = mysql_query($query,$connection);
$count=0;
while($row = mysql_fetch_assoc($result));
{
$count++;
}
echo $count;
  


Are you sure your database connection has been made?

$connection = mysql_connect('localhost', 'mysql_user', 'mysql_password') 
or die(mysql_error());

etc..

If the connection is made alright, try:

$query =Select answer from answers where studentID ='A123456789';
$result = mysql_query($query,$connection) or die(mysql_error());
$count=0;
while($row = mysql_fetch_assoc($result));
{
$count++;
}
echo $count;





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



Re: [PHP-DB] numeric string to single digit array

2008-03-26 Thread Evert Lammerts



This is my code.  The only error is at line 15 as I stated above.

1 ?PHP
2 DEFINE (host,localhost);
3 DEFINE (user,root);
4 DEFINE (password,password);
5 DEFINE (database,questions);
6
7 $connection=mysql_connect(host,user,password) or die ('Could not connect' 
.mysql_error() );
8
9 $dbConnect=mysql_select_db('questions',$connection);
10 if (!$dbConnect) {die ('Could not connect to database' . mysql_error() );}
11
12 $query =Select answer from answers where studentID ='A123456789';
13 $result = mysql_query($query,$connection);
14 $count=0;
15 while($row = mysql_fetch_assoc($result));
16 {
17 $count++;
18 }
19 echo $count;
20 ?

  


Turn line 13 into
$result = mysql_query($query) or die(mysql_error());
, so leave out the connection parameter and append the die() function, 
and see what error that produces.


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



Re: [PHP-DB] numeric string to single digit array

2008-03-26 Thread Evert Lammerts




OK. Tried that and count comes back as 1.  
  


So your query returns only one record. Try

$query =Select answer from answers;



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



Re: [PHP-DB] numeric string to single digit array

2008-03-26 Thread Evert Lammerts


Tried that as well and got the same result. 
I tried Select count(answer) as total from answers where studentID='A123456789';
from the CLI and got total = 2 as a result.  
  


So, we got rid of the Invalid Resource error and we know that the 
student id you use occurs in both rows in your table and that your query 
works fine.


Did you get rid of the semicolon @ line 15 while($row = 
mysql_fetch_assoc($result));, as Jason suggested? Also, an:

error_reporting(E_ALL);
at the top of your code might help in backtracing.

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



Re: [PHP-DB] Not updating certain fields in same row

2008-03-25 Thread Evert Lammerts

I might be way off here. Php.net tells me that:

[quote]

mysql_real_escape_string — Escapes special characters in a string for 
use in a SQL statement


string **mysql_real_escape_string** ( string $unescaped_string [, 
resource $link_identifier ] )


[/quote]

and you use

[quote]

mysqli_real_escape_string($chpwpostlink, $_POST['txtLoginName']);

[/quote]

I can't imagine that $_POST['txtLoginName'] is a resource identifier 
(which is the actual connection to your database).


Also, this condition:

[quote]

if (!isset($_POST['txtLoginName']) || empty($_POST['txtLoginName']))

[/quote]

is true if and only if no form element by the name txtLoginName existed 
on the previous page - and on top of that, empty() does the same as 
isset() and apart from that also checks whether, if the variable has 
been set, it has a value (0, , NULL or FALSE) that evaluates to FALSE.


I don't understand why you'd want to fill the username with a tab 
either: \t.


Maybe you can post your full code?

Evert


Daniel Brown wrote:

On Tue, Mar 25, 2008 at 1:14 PM, Jason Pruim [EMAIL PROTECTED] wrote:
  

 the actual query I'm using is this:

$chpwsql = UPDATE current SET customerName='$customerName',
 loginName='$loginName', loginPassword='$PW', email='$email',
 adminLevel='$adminLevel' WHERE Record='$Record1';

 What it is doing now is if I don't set a a field I am replacing the
 content of it with a tab, which isn't what I want. Basically what I'm
 looking for is if loginPassword hasn't changed... don't clear the
 contents of it. if it has changed, then update loginPassword



Okay, since you won't only want to rely on isset() here (in case
someone accidentally hits a key into the field), try this:

// NOTE: This assumes prior sanity checks and cleansing
// of variables, and is written like so to avoid breaking
// of the query due to mail client-enforced line breaks.
$chpwsql  = UPDATE current SET ;
$chpwsql .= customerName='.$customername.',;
$chpwsql .= loginName='.$loginName.',;
if(preg_match('/^[a-z0-9]{5,16}$/i',$PW)) {
// If it's between 5-16 case-insensitive alphanumeric
// characters, it's all good. If you want to allow symbols,
// simply modify the regexp accordingly.
$chpwsql .= loginPassword='.$PW.',;
}
$chpwsql .= email='.$email.',;
$chpwsql .= adminLevel='.$adminLevel',;
$chpwsql .=  WHERE Record='.$Record1.';
$chpwsql .=  LIMIT 1;

  



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



Re: [PHP-DB] Not updating certain fields in same row

2008-03-25 Thread Evert Lammerts

Correction:

Also, this condition:

[quote]

if (!isset($_POST['txtLoginName']) || empty($_POST['txtLoginName']))

[/quote]

is true if and only if no form element by the name txtLoginName 
existed on the previous page - and on top of that, empty() does the 
same as isset() and apart from that also checks whether, if the 
variable has been set, it has a value (0, , NULL or FALSE) that 
evaluates to FALSE.


This condition is of course also true when the form element has existed 
but has no value.


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



Re: [PHP-DB] Retreving X, Y, Z from the Geometry column in oracle 10g

2008-02-20 Thread Evert Lammerts
You'll need an oracle - oci8 expert for this. A little googling told me 
that in order to use user defined data types (and i guess enhanced build 
in data types as GEOMETRY too) you will need oci8 functions 
(http://bugs.php.net/bug.php?id=39887), specifically the function 
bind_array_by_name() 
(http://usphp.com/manual/en/function.oci-bind-array-by-name.php).


In general, and I bet you do, keep the oci8 function overview close 
(http://usphp.com/manual/en/ref.oci8.php).


Evert

Hebat-Allah Farag wrote:

Dear all ,
I am stick since 2 days at the same point, I am using 10g, PHP my problem
now is how to fecth the X, Y , z coordinates from the geometry column to
view it on my web page, i don't understand the (SDO_ORDINATES), what is its
type  how i can deal with it. my simple code is:
$conn=oci_connect('User','pass','//localhost/x')
$sqlCol=SELECT c.GEOMETRY.SDO_ORDINATES from SSS c WHERE c.CODE = '80A' ;
$resultCol=oci_parse($conn,$sqlCol);
$excuteResCol=oci_execute($resultCol);
$resultRecordsCol=oci_fetch_array($resultCol);

I got an error on the last line as (ORA-00932: inconsistent datatypes:
expected CHAR got ARRAY )
i don't know how to deal with this resultset.

If anyone could help please replay.

Thanks for your help

  


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



Re: [PHP-DB] Efficient way to access MS SQL server

2008-02-01 Thread Evert Lammerts
There's a limit of 30 characters for column names, but only if you 
connect to your mssql server from windows (more info on 
http://hu2.php.net/mssql).


The native SQL driver for PHP has a problem with a limit on the number 
of characters in a string, so can't use that.

I'm not sure what Charly means by this though...

Evert

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



Re: [PHP-DB] Formatting in Text Area

2008-02-01 Thread Evert Lammerts

VanBuskirk, Patricia wrote:

I have a customer description text area field on my form which feeds through 
php to FMP,

What's FMP? Is that what links this email to the db-list?

 and spits out a confirmation page and email.  The issue I am having is this ... as 
the customer types, the text wraps.  Many put their own hard returns and spaces in to 
organize their description.  It seems I can't get it to do both the wrap and show the 
actual formatting entered.  If I format the field as physical wrap, the lines run off 
the page on the confirmation/printout.  If I format it as virtual, then the hard 
returns, etc get lost.  I have also tried using PRE on the confirmation page 
and email and that doesn't work either.
  
Line wrapping in a text area is a property of the text area, not of the 
text, as opposite to line breaks and hard returns. This is why you won't 
find line break characters at the place the text used to wrap in the 
text area.


What you can do of course is to add a div (or whatever container you 
feel like) of the same width / height as the text area to the 
confirmation page and replace \l\r with br 's.


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



Re: [PHP-DB] A little SQL help

2008-01-31 Thread Evert Lammerts

Not completely sure what type of result you expect, but here's one that makes 
sense to me.

SELECT tour.record_id, tour.event_start_date, tour.event_end_date, 
tour.event_name, angler_results.result
FROM tour
LEFT JOIN angler_results
ON angler_results.tour_id = tour.record_id
AND angler_results.angler_id = 1

I've taken out the CASE - I personally never worked with that and I'd probably put a 
default value of 'N/A' in the column angler_results.result. The DISTINCT has to go 
too, I'm guessing that the relation tour.record_id -  angler_results.tour_id is 1 
- *. The LEFT join CAN stay (as far as I know OUTER is only necessary when using 
ODBC or for maintaining compatibility with it, and then I'm still not sure what it 
does), if you want to have all rows in tour regardless of the join condition with 
NULL values for angler_results.result where tour.record_id is not in 
angler_results.tour_id. To leave out the NULL values use an INNER JOIN instead.

Evert


Bastien Koert wrote:

Hi All,
 
Got myself stuck in a little sql here and can't seem to work out what I am doing wrong
 
SELECT 
  DISTINCT (tour.record_id), tour.event_start_date, tour.event_end_date, tour.event_name,CASE WHEN result is NULLTHEN 'N/A'ELSE angler_results.resultEND CASE 
FROM 
  tourLEFT OUTER JOIN angler_results 
ON angler_results.tour_id = tour.record_idWHERE angler_results.angler_id =1
 
where the table TOUR is as above in the primary part of the select and table ANGLER_RESULTS is (record_id, tour_id, angler_id, result)
 
 
Any ideas?
 
Bastien
 
 
 
_



  


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



[PHP-DB] [Fwd: Kesalahan posting: Don Komo]

2008-01-31 Thread Evert Lammerts
Is anybody else getting similar emails after sending an email to the 
php-db list? I don't understand any of this 2006 google group with 5 
members.


 Original Message 
Subject:Kesalahan posting: Don Komo
Date:   Thu, 31 Jan 2008 09:17:40 +
From:   [EMAIL PROTECTED]
To: [EMAIL PROTECTED]



 Anda tidak memiliki izin untuk memposting ke grup donkomo. Anda mungkin 
harus bergabung ke grup agar dibolehkan memposting atau grup ini mungkin tidak
dapat terbuka untuk memposting. 

Kunjungi http://groups.google.com/group/donkomo/about?hl=id untuk bergabung atau 
mempelajari lebih lanjut tentang siapa yang dibolehkan memposting ke grup. 


Bantuan untuk menggunakan Google Groups juga tersedia di:
http://groups.google.com/support?hl=id

---BeginMessage---


Not completely sure what type of result you expect, but here's one that makes 
sense to me.

SELECT tour.record_id, tour.event_start_date, tour.event_end_date, 
tour.event_name, angler_results.result
FROM tour
LEFT JOIN angler_results
ON angler_results.tour_id = tour.record_id
AND angler_results.angler_id = 1

I've taken out the CASE - I personally never worked with that and I'd probably put a 
default value of 'N/A' in the column angler_results.result. The DISTINCT has to go 
too, I'm guessing that the relation tour.record_id -  angler_results.tour_id is 1 
- *. The LEFT join CAN stay (as far as I know OUTER is only necessary when using 
ODBC or for maintaining compatibility with it, and then I'm still not sure what it 
does), if you want to have all rows in tour regardless of the join condition with 
NULL values for angler_results.result where tour.record_id is not in 
angler_results.tour_id. To leave out the NULL values use an INNER JOIN instead.

Evert


Bastien Koert wrote:

Hi All,
 
Got myself stuck in a little sql here and can't seem to work out what I am doing wrong
 
SELECT 
  DISTINCT (tour.record_id), tour.event_start_date, tour.event_end_date, tour.event_name,CASE WHEN result is NULLTHEN 'N/A'ELSE angler_results.resultEND CASE 
FROM 
  tourLEFT OUTER JOIN angler_results 
ON angler_results.tour_id = tour.record_idWHERE angler_results.angler_id =1
 
where the table TOUR is as above in the primary part of the select and table ANGLER_RESULTS is (record_id, tour_id, angler_id, result)
 
 
Any ideas?
 
Bastien
 
 
 
_



  


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



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

[PHP-DB] Don komo

2008-01-31 Thread Evert Lammerts
A quick google shows I'm not the first to ask this question... Lets take 
the address of the list? (I cc'ed owner)


OWNER: Please take [EMAIL PROTECTED] from the php-db list. It's a 
google group email address that doesn't accept anonymous emails (if I've 
decrypted the indonesian well) and automatically replies to every email 
sent.


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



Re: [PHP-DB] Webservices with PHP

2008-01-09 Thread Evert Lammerts
SOAP stands for Simple Object Access Protocol and is, as its name 
implies, a protocol for accessing objects or in other words, a standard 
that defines how a possibly remote object can be communicated with. 
XML-RPC, with RPC standing for Remote Procedure Call, is a protocol to 
call remote procedures using XML. REST stands for REpresentational State 
Transfer and is an HTTP alternative to Web Service standards, based on 
the idea that the extra layer of these standards is obsolete because the 
HTTP protocol is able to handle similar purposes. Wikipedia.org has 
loads of info.


You say you want to implement a Service Oriented Architecture. The 
reasons you have to do this define what type of standard(s) you should 
use, if any at all. Remember that if you only need to access your 
services through browser based clients (e.g. a website) that there is 
very little use in implementing any of the above mentioned standards and 
protocols. If you need your services to be accessible by a variety of 
clients you do need to explore web service standards (and stop reading on).


A little more specific in the direction of services in PHP accessed by 
browser based clients (assuming you need that), without using web 
service standards. In general most web developers need a lightweight 
protocol to access services, methods and functions through JavaScript. 
For this I use the JavaScript Object Notation (JSON, check json.org).


As a very simple example a service that appends an exclamation mark to 
all parameters you send and alerts them on success. I assume you use 
JavaScript, the json.org JavaScript library and created an 
XmlHttpRequest instance by the name of xhr (check w3schools.com if you 
need help initializing one or use a third party library such as Prototype):


CLIENT SIDE:

//index.html
script
function callBack() {
   var response = JSON.parse(xhr.responseText);
   for (x in response)
  alert(x + ' = ' + response[x]);
}

var params = {i: 'need', to: 'use', services:'now'};
var parsed = JSON.stringify(params);
xhr.onreadystatechange = function() {
   if (xhr.readyState == 4)
   callBack();
};
xhr.open (GET, service.php?params= + params, true);
xhr.send (null);
/script

SERVER SIDE:

//service.php
?php
   require_once(myservice.php);
   if (!empty($_REQUEST['params']))
  echo 
json_encode(MyService::do_call(json_decode($_REQUEST['params'])));

?

//myservice.php
?php
class MyService {
   function doCall($params) {
  foreach ($params as $key = $value)
 $params [$key] .= '!';
  return $params;
   }
}
?



$P$ $T$ wrote:

Hi,
Sorry this may not be related to php-db list. I do not have much
knowledge about webservices but would like to know, which is better
way of implementing webservices with PHP-MySQL

XML-RPC, SOAP, or REST

And why? What are the parameters that we should be looking for before
deciding on mechanism?

Thanks,
Pravin

  


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



Re: [PHP-DB] Beginners Problem

2008-01-08 Thread Evert Lammerts

Hi Ben,

Number of things wrong with your code, look below.


$select_sql = sprintf(SELECT `username` FROM `users` WHERE `username` =
'$user' AND `password` = '$pass', mysql_real_escape_string($user),
mysql_real_escape_string($pass));
  
In the string you are printing using sprintf you need to use a 
conversion specification (see http://uk2.php.net/sprintf), in your case 
%s. It will look like this:


sprintf(SELECT `username` FROM `users` WHERE `username`='%s' AND `password` = 
'%s', mysql_real_escape_string($user),
mysql_real_escape_string($pass))


if($select_sql_two)
As Peter points out, mysql_query (http://uk2.php.net/mysql_query) will 
always return a resource if and only if the query syntax was correct, 
even if the actual result set is empty. Knowing that anything that is 
not = 0, null or false will return true, the above condition will 
always be true (which is why the login works). So instead, use one of 
the mysql_fetch functions, e.g.


if ($row = mysql_fetch_array($select_sql_two))

Couple of other tips. Put your php functionality for login in a 
function, with username and password as parameters (function 
login($user, $pass)). This way you can reuse it, and it makes your code 
a lot easier to handle. Also, instead of printing an HTML redirect I'd 
recommend doing the redirect in the HTTP header (http://uk.php.net/header).


if (!empty($_POST['username'])  !empty($_POST['password'])) 
login($_POST['username'], $_POST['password']);

else header(|'location: members.php'|);

Do remember that in order to use the header function you cannot output 
anything else before the function is called, like it says in the manual.


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



Re: [PHP-DB] rtrim a string with MySQL's function

2007-12-05 Thread Evert Lammerts
You can use regular expressions in mysql to check for the right format, 
but (as far as i know) you can not return any matches: SELECT * FROM 
table WHERE column REGEX '[0-9]+';, which returns all records where 
column has a digit in its value.


In PHP however, you can easily get the matches:
$var = preg_match('/(\d+)/', $string, $matches);
You can find the first occurring digits of your string in $matches[1].

If your $string is of this form: string = [0-9]*[a-zA-Z]*|string, so 
digits and alpha characters are mixed, I guess you'll need to do 
something like implode $matches[1..n] if you're using the regex above.


Shelley Shyan wrote:

Hi all,

It's really frustrating, I got a problem to trim a string using MySQL's 
function.

The fact is that I want to rtrim a number from a string, that is:
if the string is   abc2321413412, I want the function to return 2321413412;
  c123, 
123;
  456789,   
   456789;

Is there a faster way to manage that?

The faster, the better. :)

Thank you for your consideration and waiting for your answer. :)

Regards,
Shelley

  


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



RE: [PHP-DB] Interactive Order Form

2007-11-09 Thread Evert Lammerts
I've never worked with FileMaker before, but a quick Google
(http://www.filemaker.com/support/technologies/php.html) tells me you need
to get a copy of the FileMaker API for PHP, if you're not using Windows that
is. If you are using Windows you can use ODBC
(http://www.filemaker.com/help/15-Using%20ODBC.html).

If your database is only interfaced by a website I'd recommend using a
database system that is supported by PHP (MySQL would be a good option).
There might of course be other options out there that I'm not aware of.

Good luck,
Evert

-Original Message-
From: VanBuskirk, Patricia [mailto:[EMAIL PROTECTED] 
Sent: vrijdag 9 november 2007 18:01
To: php-db@lists.php.net
Subject: [PHP-DB] Interactive Order Form

Happy Friday All!

We presently have an order form online (using php5) that feeds into a
FileMaker 9 database.  What we are trying to do is:

If someone clicks on cell phone (checkbox), a new box of fields shows
under it requiring additional info that feeds into a new table in the
database (one order number to many cell phones).  Once they fill in that
data (action:add/chg/delete, user name, cell number, userid, etc), there
should be a button for more lines that they can click that will give
them another line to enter info on.  Once that info is entered and they
are done, those fields of info go to the other table, while the original
form info goes to the orders table.

I am at the point in programming php where I know something CAN be done
... but HOW to do it can be the puzzler!  Any assistance or examples
would be greatly appreciated.  I can send the form and processing page
to anyone offlist if requested.

Thanks!

Trish

-- 
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] tree processing

2007-10-30 Thread Evert Lammerts
Hello all,

In my MySQL database, with which I communicate through the mysqli extension,
I have two tables that each store a tree.

My first problem. The first tree is based on the nested set model, with a
primary key on the id (INT(10)) column, an index on the left and right
(INT(10)) columns and a VARCHAR (250) column to represent a name. This table
holds almost 14 thousand records. If I execute my single query (buffered, I
work with a custom template system that only allows output after all other
processing is done) to fetch the complete tree, it takes around 40 seconds
to execute. This query is a standard query to fetch a tree and the depth per
node. Is there any way I could optimize this?

My second, bigger problem. The other table holds a binary tree in which
every node holds the id of its parent. All relevant fields are indexed. This
table holds now almost 11 thousand records. The functionality that creates
the problem is the fetching of a big tree, and the looking for the optimal
insertion point for a node (I try to keep the tree symmetric according to a
simple recursive  algorithm - I follow the path with the least children per
node, e.g. topnode (lft (1000), rgt (800)) - Rightnode (lft (300),
rgt(500)) - Leftnode ... etc). For the biggest tree this functionality can
take very long to execute. So I thought that instead of using a recursive
algorithm, I use binary operations - it is a binary tree after all.

My solution for fetching the tree looks like this: for every node you save
it's path as a binary number represented as an integer in the database, eg
11 = left left = 3, 10 = left right = 2, 1001110 = left right right left
left left right = 78, etc. To get all children of a certain node you do a
logical and on the parent's path and all other paths - SELECT * FROM tree
WHERE TRUE = path  {$parent_path}. However, this solution requires the
tree's longest path to be no more then 64 (MySQL's BIGINT is 8 bytes). This
is not enough for us.

I'm desperately looking for suggestions, and I guess I'm not the first one
to have problems with processing big amounts of data in tree structures. Do
you guys have any suggestions?

Thanks,
Evert Lammerts