473,397 Members | 1,974 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,397 software developers and data experts.

call the function twice?

150 100+
I'm having problem with this code i can't describe the problem, that is my code:

[PHP]<?php
$announce = mysql_query("SELECT * FROM announce LIMIT 4");
while($key = mysql_fetch_assoc($announce)){
echo '<td style="border:#999999 solid 1px;"><center>'.$key['Title'].'</center></td>';
}
?>
</tr>
<tr>
<?php
while($key = mysql_fetch_assoc($announce)){
for($i=1;$i<=3;$i++){
$PicArray = 'Pic'.$i;
if($key[$PicArray]!=''){
$PicType = explode(',',$key[$PicArray]);
$tum = $PicType[1];
if(is_file($tum)){
echo '<td style="border:#999999 solid 1px;"><center><img src="'.$tum.'"/></center></td>';
break;
}
}
}
}
?>[/PHP]

in this code to solve it i have to call this function again in the second row why?

[PHP]$announce = mysql_query("SELECT * FROM announce LIMIT 4");[/PHP]
Jun 1 '08 #1
1 2181
Atli
5,058 Expert 4TB
The result returned by the mysql_query() function keeps an internal row pointer, which is incremented whenever you call a mysql_fetch_*() function on it.

So after the first loop has completed, the internal pointer has already reached the end of the result set, so any mysql_fetch_*() call will fail on it.

Try using the mysql_data_seek function on it before the second loop. Like:
Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query("SELECT cols FROM tbl");
  2. while($row = mysql_fetch_assoc($result)) {#...}
  3.  
  4. mysql_data_seek($result, 1);
  5. while($row = mysql_fetch_assoc($result)) {#...}
  6.  
Jun 1 '08 #2

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

Similar topics

9
by: beliavsky | last post by:
I can define a function that transforms either a scalar or each element in a list as follows: def twice(x): try: return map(twice,x) except: return 2*x print twice(3) # 6
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
3
by: Cong Wang | last post by:
Hi,all! I found an interesting problem,it is that how to implement a C function which can be called once and return twice? Just like the POSIX function fork() or the library function...
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
2
by: ACaunter | last post by:
Hi all, I have to push a button twice to open a new window, only because i have to set some session variables before opening the window so i can't have the opennewwindow function called in the...
6
by: Philip Warner | last post by:
I have a set of classes: C (base) C1 (inherits C) C2 (inherits C) ... Cn (inherits C) (the C1..Cn also have subclasses, but thats not really relevant to the question)
11
by: Felix Kater | last post by:
Hi, I can compile and run this code (see below) which twice calls the function f, first with too less, second with too much arguments. But is it legal and free of memory leaks and other...
0
by: shama | last post by:
Hi all, I want to develop add-in for OUTLOOK, In that for event handling use IDispEventSimpleImpl Interface, use BEGIN_SINK_MAP and declare handler function (fn) for the specified event using...
6
by: alho | last post by:
The web service is called by a program running on pocket pc. When to call the web service, the first call is still ok, but for the second or later calls, it will throw "403 Forbidden" WebException....
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.