Eivind,

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 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 I would need to identify the row the recordset
was presently at. 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: "Eivind A. Sivertsen" <[EMAIL PROTECTED]>
To: "Zac Hillier" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Friday, June 14, 2002 9:58 AM
Subject: Re: mysql row position


> Zac,
> what is your indicator of which row it is?
> If you have aprimary key for each row, why don't  you just use that?
> You cant really determine the position of a row if you haven't determined
> the criteria that fixes the position, right?
> So, you just decide wether you will sort it alphabetically or according to
a
> row index, then go ahead and do it...
>
> If, on the other hand, you mean you want to return the position WITHIN the
> selection you have gotten, you could just push the records onto an array
one
> by one. Then the array index for each row gives away the position of the
row
> (-1, actually).
>
> Example:
> --------------------------------------------
> $rows = array();
> $query = "select * from blabla";
> $result = mysql_query($query) or die(mysql_error());
> while($row = mysql_fetch_array($result)){
>  array_push($rows, $row);
>  }
>
> // - now you have it all in an array variable in php - accessible like
this:
>
> foreach($rows as $idx => $row)
>  echo "$idx:".$row["field_1"]." - ".$row["field_2"]." -
> ".$row["etc"]."<BR>\n";
> ...
> --------------------------------------------
>
>
> I'm not sure wether I grasp what your question really is, but perhaps this
> helped some?
>
> Good luck,
>     Eivind <:-)
>
>
>
> ----- Original Message -----
> From: "Zac Hillier" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, June 14, 2002 9:58 AM
> Subject: mysql row position
>
>
> > 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
> >
> >
> > ---------------------------------------------------------------------
> > Before posting, please check:
> >    http://www.mysql.com/manual.php   (the manual)
> >    http://lists.mysql.com/           (the list archive)
> >
> > To request this thread, e-mail <[EMAIL PROTECTED]>
> > To unsubscribe, e-mail
> <[EMAIL PROTECTED]>
> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
<[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
>
>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to