Re: [PHP] row pointer

2002-06-15 Thread Analysis Solutions

Zac:

 foreach($kywrd as $val) {
  $fndWrds .= wrd = '$val' OR ;
 }

FYI, a simpler way to do that...

$fndWrds = wrd IN (' . implode(',', $kywrd) . ');

That aside, w/o completely analyzing your entire set of code, it sounds 
like John is on the right track with putting a unique index on the wrd 
column.

Enjoy,

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

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




Re: [PHP] row pointer

2002-06-14 Thread Analysis Solutions

Hey Zac:

On Fri, Jun 14, 2002 at 08:59:02AM +0100, Zac Hillier wrote:
 
 I'm looking for a php function that will return the position of the pointer
 in a mysql recordset.

I don't think there is one.  You could use a counter variable as you're 
looping through each row to keep track of where you are.

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

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




RE: [PHP] row pointer

2002-06-14 Thread John Holmes

Keep track of it yourself as you loop through the data. Maybe if you
explained what you need overall then we could suggest a method...

---John Holmes...

 -Original Message-
 From: Zac Hillier [mailto:[EMAIL PROTECTED]]
 Sent: Friday, June 14, 2002 3:59 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] row pointer
 
 Hi
 
 I'm looking for a php function that will return the position of the
 pointer
 in a mysql recordset.
 
 I found mysql_data_seek, but this appears to only move the pointer, I
need
 to get the equivalent row number for the pointer position before
moving
 it,
 then return to the same position.
 
 Can anyone help?
 
 Thanks
 
 Zac
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



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




Re: [PHP] row pointer

2002-06-14 Thread Zac Hillier

John, Dan  All,

Thanks for your response, perhaps if I tell you more of the story then it'll
make more sense. I'm afraid I seem to have an ability for asking cryptic
questions.

Below is the code I'm using, it is meant to check for a list of between 10
and 50 words in a table then return the key of the words found, for the
words not in the table they should be added to the table.

It seems to work fine, but in a effort to make the code more efficient I
realised that at present I'm walking through a lot of the recordset for each
keyword. But that the majority of the recordset would be in the same order
as the keywords. So if I can add a little extra code that says if the next
record in the recordset is not the word I'm trying to find then walk through
the recordset, if you reach the end then start at the beginning and go
down-to the initial row. This should confirm that the word is not in the
recordset and so needs to be added, but leave the recordset in the correct
place to check the next word.

However to do this I thought initialy I would need to identify the row the
recordset was presently at. However now I understand I need to push the
recordset into an array then use this array to loop through finding the
key's and the words that need to be added. However saying it and coding it
seem to be two completely different things, can anyone help me getting
started? Hope this makes some sense? If you have any other comments on the
code to improve it or good coding practice I would appreciate your comments
as I'm still new to this.

Thanks

Zac

Code:

#--create select statement for getting keywords from table
$fndWrds = '';
foreach($kywrd as $val) {
 $fndWrds .= wrd = '$val' OR ;
}

#-- add test word to get a result regardless
$fndWrds .= wrd = 'test';

#-- get present keywords from db
$dbKy = mysql_query(SELECT ky, wrd FROM .$site_no.kywrdInd WHERE
$fndWrds;);

#--create kywrd index array for index to be used in update value list
$indx = array();

#--create update value lists to later add record into lookup table
$vlst = '';

foreach($kywrd as $key = $val) {
 $fnd = 0;
 While ($kyRw = mysql_fetch_array($dbKy)) {
  if($kyRw['wrd'] == $val) {
   $fnd = 1;
   $indx[$key] = $kyRw['ky'];
   break 1;
  }
 }
 #-- reset pointer of db array back to begining
 mysql_data_seek($dbKy, 0);

 #-- if not in db then add word to db then set index
 if($fnd == 0) {
  if(! mysql_query(INSERT INTO .$site_no.kywrdInd (wrd) values
('.$val.');)) echo 'Word not added';
  $indx[$key] = mysql_insert_id();
 }

 #-- check to see that each word has an index value
 if($indx[$key]) {
  #--create value list for update into lookup table
  $vlst .= ($compID, . $indx[$key] . , . $scr[$key] . ), ;
 } else {
  echo 'no index set for keyword, word = '.$val.' index = '.$key.'br';
 }


- Original Message -
From: John Holmes [EMAIL PROTECTED]
To: 'Zac Hillier' [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Friday, June 14, 2002 6:42 PM
Subject: RE: [PHP] row pointer


 Keep track of it yourself as you loop through the data. Maybe if you
 explained what you need overall then we could suggest a method...

 ---John Holmes...

  -Original Message-
  From: Zac Hillier [mailto:[EMAIL PROTECTED]]
  Sent: Friday, June 14, 2002 3:59 AM
  To: [EMAIL PROTECTED]
  Subject: [PHP] row pointer
 
  Hi
 
  I'm looking for a php function that will return the position of the
  pointer
  in a mysql recordset.
 
  I found mysql_data_seek, but this appears to only move the pointer, I
 need
  to get the equivalent row number for the pointer position before
 moving
  it,
  then return to the same position.
 
  Can anyone help?
 
  Thanks
 
  Zac
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php



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





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




Re: [PHP] row pointer

2002-06-14 Thread 1LT John W. Holmes

So you just want to insert a bunch of words into the table if they aren't
there already? Why not make the column unique and just insert them. Ignore
the warnings about duplicates...

---John Holmes...

- Original Message -
From: Zac Hillier [EMAIL PROTECTED]
To: [EMAIL PROTECTED]; Analysis  Solutions
[EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Friday, June 14, 2002 5:54 PM
Subject: Re: [PHP] row pointer


 John, Dan  All,

 Thanks for your response, perhaps if I tell you more of the story then
it'll
 make more sense. I'm afraid I seem to have an ability for asking cryptic
 questions.

 Below is the code I'm using, it is meant to check for a list of between 10
 and 50 words in a table then return the key of the words found, for the
 words not in the table they should be added to the table.

 It seems to work fine, but in a effort to make the code more efficient I
 realised that at present I'm walking through a lot of the recordset for
each
 keyword. But that the majority of the recordset would be in the same order
 as the keywords. So if I can add a little extra code that says if the next
 record in the recordset is not the word I'm trying to find then walk
through
 the recordset, if you reach the end then start at the beginning and go
 down-to the initial row. This should confirm that the word is not in the
 recordset and so needs to be added, but leave the recordset in the correct
 place to check the next word.

 However to do this I thought initialy I would need to identify the row the
 recordset was presently at. However now I understand I need to push the
 recordset into an array then use this array to loop through finding the
 key's and the words that need to be added. However saying it and coding it
 seem to be two completely different things, can anyone help me getting
 started? Hope this makes some sense? If you have any other comments on the
 code to improve it or good coding practice I would appreciate your
comments
 as I'm still new to this.

 Thanks

 Zac

 Code:

 #--create select statement for getting keywords from table
 $fndWrds = '';
 foreach($kywrd as $val) {
  $fndWrds .= wrd = '$val' OR ;
 }

 #-- add test word to get a result regardless
 $fndWrds .= wrd = 'test';

 #-- get present keywords from db
 $dbKy = mysql_query(SELECT ky, wrd FROM .$site_no.kywrdInd WHERE
 $fndWrds;);

 #--create kywrd index array for index to be used in update value list
 $indx = array();

 #--create update value lists to later add record into lookup table
 $vlst = '';

 foreach($kywrd as $key = $val) {
  $fnd = 0;
  While ($kyRw = mysql_fetch_array($dbKy)) {
   if($kyRw['wrd'] == $val) {
$fnd = 1;
$indx[$key] = $kyRw['ky'];
break 1;
   }
  }
  #-- reset pointer of db array back to begining
  mysql_data_seek($dbKy, 0);

  #-- if not in db then add word to db then set index
  if($fnd == 0) {
   if(! mysql_query(INSERT INTO .$site_no.kywrdInd (wrd) values
 ('.$val.');)) echo 'Word not added';
   $indx[$key] = mysql_insert_id();
  }

  #-- check to see that each word has an index value
  if($indx[$key]) {
   #--create value list for update into lookup table
   $vlst .= ($compID, . $indx[$key] . , . $scr[$key] . ), ;
  } else {
   echo 'no index set for keyword, word = '.$val.' index = '.$key.'br';
  }


 - Original Message -
 From: John Holmes [EMAIL PROTECTED]
 To: 'Zac Hillier' [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Friday, June 14, 2002 6:42 PM
 Subject: RE: [PHP] row pointer


  Keep track of it yourself as you loop through the data. Maybe if you
  explained what you need overall then we could suggest a method...
 
  ---John Holmes...
 
   -Original Message-
   From: Zac Hillier [mailto:[EMAIL PROTECTED]]
   Sent: Friday, June 14, 2002 3:59 AM
   To: [EMAIL PROTECTED]
   Subject: [PHP] row pointer
  
   Hi
  
   I'm looking for a php function that will return the position of the
   pointer
   in a mysql recordset.
  
   I found mysql_data_seek, but this appears to only move the pointer, I
  need
   to get the equivalent row number for the pointer position before
  moving
   it,
   then return to the same position.
  
   Can anyone help?
  
   Thanks
  
   Zac
  
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 



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