473,395 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

selext next id in table?

I have 2 tables. 1 is supposed to contain the id of the 'next' item to be
viewed. from the other table, which has the data and also an id column.

my problem ishow do I make a set of statements that UPDATEs the id (we'll
call it pid) with the next row of the table, advancing it like a cursor,
wrapping back to the beginning of the db?
the DB is a version 4 database with MyISAM tables.

I don't even know if it can be done outside of a tablescan+PHP.
I have some broken code like this:
$q1=mysql_query("SELECT pid FROM idx", $link2);
if ($row1=mysql_fetch_assoc($q1)) {
$a=array();
$q2=mysql_query("SELECT pid FROM cpg133_pictures", $link2);
while ($row2=mysql_fetch_assoc($q2)) {
$a[]=$row2['pid'];
}
$i=array_search($row1['pid'], $a); //search for idx's pid in sea of
coppermine's pids
$n=$a[$i];
$i++; //next picture. sorry. tried random. doesn't work. get same pix
every time.
$i%=count($a);
mysql_query("UPDATE idx SET pid=$a[$i]", $link2) or
die("ERRUV2:".mysql_error());
....
}

Can this be done with queries?
Apr 23 '06 #1
2 1372

"Jim Michaels" <NO***************@yahoo.com> wrote in message
news:Gc********************@comcast.com...
I have 2 tables. 1 is supposed to contain the id of the 'next' item to be
viewed. from the other table, which has the data and also an id column.

my problem ishow do I make a set of statements that UPDATEs the id (we'll
call it pid) with the next row of the table, advancing it like a cursor,
wrapping back to the beginning of the db?
the DB is a version 4 database with MyISAM tables.

I don't even know if it can be done outside of a tablescan+PHP.
I have some broken code like this:
$q1=mysql_query("SELECT pid FROM idx", $link2);
if ($row1=mysql_fetch_assoc($q1)) {
$a=array();
$q2=mysql_query("SELECT pid FROM cpg133_pictures", $link2);
while ($row2=mysql_fetch_assoc($q2)) {
$a[]=$row2['pid'];
}
$i=array_search($row1['pid'], $a); //search for idx's pid in sea of
coppermine's pids
$n=$a[$i];
$i++; //next picture. sorry. tried random. doesn't work. get same pix
every time.
$i%=count($a);
mysql_query("UPDATE idx SET pid=$a[$i]", $link2) or
die("ERRUV2:".mysql_error());
...
}

Can this be done with queries?


oops. wrong newsgroup. but if you think you can help, I'm open to
suggestions.
Apr 23 '06 #2
Jim Michaels wrote:
oops. wrong newsgroup. but if you think you can help, I'm open to
suggestions.


Enable logging on MySQL, and see what queries are actually passed to
the DB? That will give you a clue where things are going wrong.
Apr 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Belee | last post by:
I have the following code and it is not passing through the Next statement: Private Function IsItemAlreadyAdded() As Boolean Dim drMyRow As DataRow With Me For Each drMyRow In...
5
by: itsupport1 | last post by:
Hi, I am importing some records from one table to another table, and due to Constraints in the destination table, it Throws an Exception and Skip the Whole Rest of records. So I did implement...
5
by: robecflo | last post by:
Hi Forum, i have a problem, hope somebody can give me ideas. I'm developing with windows forms and vb.net, and oracle as a database. At this moment i have a table called amortizaciones, this table...
1
by: Tony Dunn | last post by:
I have inherited another developer's database (Access 2003) and with it a problem I'm struggling with. The problem is this. I have a parent-child form pair, which is populated by a table (the...
9
by: Cogito | last post by:
My program builds several tables using inner HTML. All the tables are displayed only when the program terminates. How can I make it display one table at a time and then wait for a click before...
5
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big...
5
by: peck2000 | last post by:
This has been driving me up the wall for a couple of weeks. I set out to convert my comic collection check list (geek that I am!) from a static HTML table to a dynamic ASP generated one. The...
4
osward
by: osward | last post by:
I had made a table colum sortable and paging the table, following are the code // Display Event List echo "<center>"._EVENTLIST."</center><br>"; $now = Date(Y-m-d); // sort table...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.