473,513 Members | 2,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to read next row in a mySql Query

2 New Member
I have this php code which looks like this
Expand|Select|Wrap|Line Numbers
  1. $sql = ......
  2. $result = mysql_query($sql,$connection)
  3. or die("Couldn't execute SELECT query");
  4.  
  5. while ($row = mysql_fetch_array($result)) {
  6. ......
  7. }
  8.  
What i want to do is be able to read the next row in the query. So for example
Expand|Select|Wrap|Line Numbers
  1. while ($row = mysql_fetch_array($result)) {
  2. ......
  3. if (ID for next row/record = ID for this row/record) {
  4. do this
  5. }
  6. }
  7.  
Any help would be appreciated
Thank You
May 15 '07 #1
4 8194
pbmods
5,821 Recognized Expert Expert
Heya, phphelp87. Welcome to TSDN!

Your best bet would be to compile all your data first, then process it. That way, you have access to all your rows at any given time.

Check out this article for a fantastic tutorial on setting this up:
http://www.thescripts.com/forum/thread632487.html
May 15 '07 #2
phphelp87
2 New Member
Thanks for the quick reply
Is this the only way to read different rows in a sql query?
If so i will have an attempt

Thank You
May 15 '07 #3
pbmods
5,821 Recognized Expert Expert
Is this the only way to read different rows in a sql query?
If it isn't the only way, it's generally agreed to be the best way. Plus, it's reusable, so you'd only have to write this code once.
May 15 '07 #4
shidec
26 New Member
it can be tricked like this :)
[PHP]
$current_row=mysql_fetch_array($result); //read $current_row
while ($next_row = mysql_fetch_array($result)) { //read $next_row
......
if ($current_row['id']==$next_row['id']) { //compare it
.....
.....
}
$current_row=$next_row; //$next_row become current_row on next step :p
}
[/PHP]
May 18 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
9455
by: Bob Bedford | last post by:
Does exist a next prev function in PHP/Mysql. I've a website with returns lot of records (say about 200). The user may browse trough the list or returned records, but he has to click the record...
3
3038
by: Marcel | last post by:
Hello, I'm working on a search application for my website. The website contains a lot of pictures, and a search should return clickable thumbnails. No problems there. My problem started when I...
0
2748
by: Bennett Haselton | last post by:
I'm trying to port my MySQL tables for a database called "tracerlock" from one server to another. On the old server, in the /var/lib/mysql/tracerlock directory, there was a ".MYD", ".MYI" and...
0
1464
by: ccll20022000 | last post by:
Hi, new to mysql, php, designing a membership type of database, potentially many members. Essentially I am faced with a design choice; have an oft run (modifiable) query run every time any...
5
16151
by: Roman Mashak | last post by:
Hello, All! I already posted my question and received valuable feedbacks, I changed my code as was proposed here but still receive the same error of valgrind. SO, the code is: #define...
2
3379
by: LizzyFin | last post by:
Looking for a little assistance in understanding what I am missing! Using PHP/MySql to allow users to browse through items in a gallery. Clicking 'next' and 'previous' links works fine using the...
0
30982
by: whitemoss | last post by:
Hi All, I had written a code to read a file and insert it's contents to the database. Since I will receive 3 files every hour, so, this program should read those files and insert the contents...
3
8469
by: Me Alone | last post by:
Hello: I am trying to edit some C code I found in "The definitive guide to using, programming, and administering MySQL" by Paul DuBois. This C client program connects and then segfaults when...
4
1942
devikacs
by: devikacs | last post by:
I wanted to use the select of a mysql query as the input to the next mysql query. The output of the first query is stored in $result. Can I do select * from $result. If not is there any other...
0
7158
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
7380
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
7523
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5085
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.