RE: [PHP] WHILE LOOP PROBLEM
-Original Message- From: Andrew Williams [mailto:andrew4willi...@gmail.com] Sent: 27 March 2009 10:12 AM To: PHP LIST Subject: [PHP] WHILE LOOP PROBLEM can some tell why the below loop stop running after some time. $start=10; const run=0; while($start >run){ //do somthing } -- The webserver or php environment is probably terminating the script. It will only run for the max number of seconds set in your php.ini file. Arno -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] WHILE LOOP PROBLEM
On Fri, 2009-03-27 at 08:11 +, Andrew Williams wrote: > can some tell why the below loop stop running after some time. > > $start=10; > const run=0; > while($start >run){ > > //do somthing > > } > max_execution_time -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while loop
Reinhart Viane wrote: Well I'm able to do that, there are only 4 different types, but the 4 queries have exactly the same syntax so I think it's better to combine them. Not? what about using UNION on the four queries? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while loop
Reinhart Viane wrote: Well I'm able to do that, there are only 4 different types, but the 4 queries have exactly the same syntax so I think it's better to combine them. Not? Since mysql 4.1 you can use GROUP_CONCAT() function: SELECT Act_date, Act_type_id, LEFT( GROUP_CONCAT(Act_name ORDER BY Act_date SEPARATOR '|'), 129 ) as Act_names FROM activities GROUP BY Act_date, Act_type_id; Act_names will be string containing the names separated by | 129 is the maximum size of Act_name * 2 + 1 for the separator. -Oorspronkelijk bericht- Van: Justin Lilly [mailto:[EMAIL PROTECTED] Verzonden: woensdag 23 februari 2005 18:57 Aan: php-general@lists.php.net Onderwerp: Re: [PHP] while loop Perhaps it is just me, but wouldn't it be easier to make individual mysql queries for each different act type? That would make the sorting -much- easier. I'm not sure if that's an option, but if it is, I'd consider exploring it. select * from activities where act_date >= NOW() && act_type_id = 1 or something of that nature. -justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] while loop
Well I'm able to do that, there are only 4 different types, but the 4 queries have exactly the same syntax so I think it's better to combine them. Not? -Oorspronkelijk bericht- Van: Justin Lilly [mailto:[EMAIL PROTECTED] Verzonden: woensdag 23 februari 2005 18:57 Aan: php-general@lists.php.net Onderwerp: Re: [PHP] while loop Perhaps it is just me, but wouldn't it be easier to make individual mysql queries for each different act type? That would make the sorting -much- easier. I'm not sure if that's an option, but if it is, I'd consider exploring it. select * from activities where act_date >= NOW() && act_type_id = 1 or something of that nature. -justin On Wed, 23 Feb 2005 13:05:53 +0100, Reinhart Viane <[EMAIL PROTECTED]> wrote: > > > Hey list > > > > I have a mysql table like this: > > > > Act_name Act_type_id Act_date > > Heyhey 1 22-06-05 > > Aloha2 22-06-05 > > Tralala 2 22-06-05 > > Wuhu1 22-06-05 > > Hehe 3 22-06-05 > > Olalal3 22-06-05 > > Pompom 1 22-06-05 > > Wuhu2 22-06-05 > > > > Now I retrieve all activities happening in the future with this query: > > $sqlact="select * from activities where act_date >= NOW() order by > act_type_id"; > > $getact=mysql_query($sqlact) > > > > What I'm trying to do now is: > > From the result array, pick from every different act_type_id the two > activities that will happen first and put them in 2 variables > > Eg. > > The two act_date with act_type_id 1 > > Should be stored in > > $Act1result1 and $act1result2 > > > > The two act_date with act_type_id 2 > > Should be stored in > > $Act2result1 and $act2result2 > > > > I think this can be done with a loop in a loop but I always manage to create > some errors causing my apache to crash (infinite loop I suppose) > > Can someone help me on this? > > > > Thx in advance > > > > Reinhart > > > No virus found in this outgoing message. > Checked by AVG Anti-Virus. > Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 22/02/2005 > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Justin Lilly University of South Carolina -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 22/02/2005 -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 22/02/2005 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while loop
Perhaps it is just me, but wouldn't it be easier to make individual mysql queries for each different act type? That would make the sorting -much- easier. I'm not sure if that's an option, but if it is, I'd consider exploring it. select * from activities where act_date >= NOW() && act_type_id = 1 or something of that nature. -justin On Wed, 23 Feb 2005 13:05:53 +0100, Reinhart Viane <[EMAIL PROTECTED]> wrote: > > > Hey list > > > > I have a mysql table like this: > > > > Act_name Act_type_id Act_date > > Heyhey 1 22-06-05 > > Aloha2 22-06-05 > > Tralala 2 22-06-05 > > Wuhu1 22-06-05 > > Hehe 3 22-06-05 > > Olalal3 22-06-05 > > Pompom 1 22-06-05 > > Wuhu2 22-06-05 > > > > Now I retrieve all activities happening in the future with this query: > > $sqlact="select * from activities where act_date >= NOW() order by > act_type_id"; > > $getact=mysql_query($sqlact) > > > > What I'm trying to do now is: > > From the result array, pick from every different act_type_id the two > activities that will happen first and put them in 2 variables > > Eg. > > The two act_date with act_type_id 1 > > Should be stored in > > $Act1result1 and $act1result2 > > > > The two act_date with act_type_id 2 > > Should be stored in > > $Act2result1 and $act2result2 > > > > I think this can be done with a loop in a loop but I always manage to create > some errors causing my apache to crash (infinite loop I suppose) > > Can someone help me on this? > > > > Thx in advance > > > > Reinhart > > > No virus found in this outgoing message. > Checked by AVG Anti-Virus. > Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 22/02/2005 > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Justin Lilly University of South Carolina -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while loop
Reinhart Viane wrote: > Hey list > > I have a mysql table like this: > > Act_name Act_type_id Act_date > > Heyhey 1 22-06-05 > > Aloha2 22-06-05 > > Tralala 2 22-06-05 > > Wuhu1 22-06-05 > > Hehe 3 22-06-05 > > Olalal3 22-06-05 > > Pompom 1 22-06-05 > > Wuhu2 22-06-05 > > Now I retrieve all activities happening in the future with this query: > > $sqlact="select * from activities where act_date >= NOW() order by > act_type_id"; > > $getact=mysql_query($sqlact) > > What I'm trying to do now is: > > From the result array, pick from every different act_type_id the two > activities that will happen first and put them in 2 variables Change your "ORDER BY" to : "order by Act_date" That's the only way you're gonna get them in date order to get the NEXT two in time. Then you need to get just two of each kind, which SQL isn't really geared to do, at least not easily. Hopefully, you'll never have, like, *THOUSANDS* of upcoming Acts... $next_two = array(); while (list($name, $type, $date) = mysql_fetch_row($getact)){ if (!isset($next_two[$type]) || count($next_two[$type]) < 2){ $new_two[$type][] = "$name $date"; } } You now have an array $new_two with indices of the Act's type, and values of arrays of at most 2 entries, with "$name $date". If you need $name and $date separated, you could use: array($name, $date) instead of "$name $date" inside the loop. You'll need to use some kind of loop to go through the $next_two array. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while loop
Reinhart Viane wrote: Hey list I have a mysql table like this: [ snipped ] Now I retrieve all activities happening in the future with this query: $sqlact="select * from activities where act_date >= NOW() order by act_type_id”; $getact=mysql_query($sqlact) What I’m trying to do now is: From the result array, pick from every different act_type_id the two activities that will happen first and put them in 2 variables while($row = mysql_fetch_assoc($getact)) { $results[$row['act_type_id']][] = $row; } echo ""; print_r($results); echo ""; Please send only plain text messages to the list, and avoid attachments. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while loop with mysql
Hi, Monday, March 10, 2003, 7:20:37 PM, you wrote: RK> Can somebody look at this and tell me way the first while loop will RK> only loop through the database once when there is more than one record RK> that should be processed. RK> while($members = @mysql_fetch_object($result)) { RK> $logged_email=$members->email; RK> $logged_title=$members->title; RK> $logged_first_name=$members->first_name; RK> $logged_last_name=$members->last_name; RK> $logged_time=$members->mtime; RK> $logged_date=$members->signdate ; RK> $logged_sent=$members->sent; RK> $current_time = time(); RK> $high_level = $current_time - $logged_time; RK> $low_level = $high_level - 86400; RK> $result1=safe_query("Select * from email"); RK> while ($emails = @mysql_fetch_object($result1)) { RK> $keys= $emails->days_send; RK> $keys=trim($keys); RK> $sendoff = $keys * 86400; RK> if ($sendoff > $low_level) { RK> if ($sendoff < $high_level) { RK> $logged_sent=trim($logged_sent); RK> if ($logged_sent==$keys){ RK> }else{ RK> //update the members table sent field with the key # RK> $sql1="Update members set sent='$keys' where email='$logged_email'"; RK> $result=safe_query($sql1); RK> send_email(); RK> }}}//end of all three if statements RK> }//end of $emails while loop RK> } //end $members while loop RK> -- RK> Best regards, RK> Richard mailto:[EMAIL PROTECTED] This resets $result //update the members table sent field with the key # $sql1="Update members set sent='$keys' where email='$logged_email'"; $result=safe_query($sql1); send_email(); needs $result3 or something -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] while loop- will this work?
> -Original Message- > From: SpyProductions Support Team [mailto:[EMAIL PROTECTED]] > Sent: Thursday, January 30, 2003 11:57 AM > To: [EMAIL PROTECTED] > Subject: [PHP] while loop- will this work? > > > > > Should this work? Nope...because the value returned by mysql_query() isn't the number of rows returned by the query...it's a pointer to the result set (which could be empty). > $f1 = rand(999,999); > > while($check_sid = mysql_query("SELECT * FROM > that_table WHERE this = > '$f1'")){ > > $f1 = rand(999,999); > > } You'll want something more like... do { $f1 = rand(999,); $check_sid = mysql_query("SELECT * from that_table WHERE this='$f1'")); } while (mysql_num_rows($check_sid)) --- Mark Roedel | "The most overlooked advantage to owning a Systems Programmer| computer is that if they foul up there's no LeTourneau University | law against whacking them around a little." Longview, Texas USA |-- Owen Porterfield -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] while loop- will this work?
> -Original Message- > From: SpyProductions Support Team [mailto:[EMAIL PROTECTED]] > Sent: Thursday, January 30, 2003 12:57 PM > To: [EMAIL PROTECTED] > Subject: [PHP] while loop- will this work? > > > > > Should this work? > > $f1 = rand(999,999); > > while($check_sid = mysql_query("SELECT * FROM > that_table WHERE this = > '$f1'")){ > > $f1 = rand(999,999); > > } > > > i.e. put the random number in a loop to check and make sure > it is already > not in use? If you check the result set for a match. $result being true will only mean the sql executed, and not that the value was in the table. So you should do a mysql_fetch_row($result) and if it succeeds the row exists in the table. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while loop question - problem (new set of eyes needed)
You are resetting $row inside your loop. Don't do that. On Sun, 19 May 2002, Lee P Reilly wrote: > Hi, > > I wonder if someone could have a quick look at this for me? It's a > simple while loop, but it's not acting the way (I think) it should. If I > break down the while loop, it reads: > > > // $result contains 3 rows > while($row = mysql_fetch_array($result)) > { > echo " xxx "; > } > > => xxx xxx xxx is displayed (as expected) > > If I add the following code to the loop, it only seems to iterate > through it *once*: > > > while($row = mysql_fetch_array($result)) > { > $pri = $row['pri']; > $fg = $row['fg']; > $molw = $row['molw']; > $density = $row['density']; > $denstype = $row['denstype']; > $pctd = $row['pctd']; > $maxpctd = $row['maxpctd']; > $compid = $row['compid']; > > $sql = "select * from compounds where compid = \"$compid\""; > $result = mysql_query($sql,$conn); > $row = mysql_fetch_array($result); > > $compname = $row['compname']; > $concentration = $row['concentration']; > $concunit = $row['concunit']; > $type = $row['type']; > $composition = $row['composition']; > > if ($fg=="Y") >$html .= "$concentration $concunit $compname"; > else if ($pri=="Y") >$html .= " $concentration $concunit > $compname"; > else >$html .= " $concentration $concunit $compname"; > } > > > Expected results: > >Actin #2543: Description here. > >1 mol AEBSF >1.3 mol Calcium Chloride >1.4 mol Potassium Chloride > > > Actual results: > >Actin #2543: Description here. > >1 mol AEBSF > >i.e the last two compounds are not displayed. > > I can't for the life of me see the problem. A new set of eyes looking at > this would be GREATLY appreciated. Thanks very much in advance. > > - Best regards, > > Lee > > > -- > 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] while loop question - problem (new set of eyes needed)
> while($row = mysql_fetch_array($result)) > { So, your while loop is based on values of $row. > $row = mysql_fetch_array($result); Now within your while loop you've altered the value of $row - poor thing is probably a tad confused. CYA, Dave -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] while loop question - problem (new set of eyes needed)
Line 13 is re-assigning $result, the save variable you're using in line 1! 1 while($row = mysql_fetch_array($result)) 2 { 3$pri = $row['pri']; 4$fg = $row['fg']; 5$molw = $row['molw']; 6$density = $row['density']; 7$denstype = $row['denstype']; 8$pctd = $row['pctd']; 9$maxpctd = $row['maxpctd']; 10$compid = $row['compid']; 11 12$sql = "select * from compounds where compid = \"$compid\""; 13$result = mysql_query($sql,$conn); 14$row = mysql_fetch_array($result); 15 16$compname = $row['compname']; 17$concentration = $row['concentration']; 18$concunit = $row['concunit']; 19$type = $row['type']; 20$composition = $row['composition']; 21 22if ($fg=="Y") 23 $html .= "$concentration $concunit $compname"; 24else if ($pri=="Y") 25 $html .= " $concentration $concunit $compname"; 26else 27 $html .= " $concentration $concunit $compname"; 28 } -Original Message- From: Lee P Reilly [mailto:[EMAIL PROTECTED]] Sent: Monday, May 20, 2002 9:24 AM To: PHP List Subject: [PHP] while loop question - problem (new set of eyes needed) Hi, I wonder if someone could have a quick look at this for me? It's a simple while loop, but it's not acting the way (I think) it should. If I break down the while loop, it reads: // $result contains 3 rows while($row = mysql_fetch_array($result)) { echo " xxx "; } => xxx xxx xxx is displayed (as expected) If I add the following code to the loop, it only seems to iterate through it *once*: while($row = mysql_fetch_array($result)) { $pri = $row['pri']; $fg = $row['fg']; $molw = $row['molw']; $density = $row['density']; $denstype = $row['denstype']; $pctd = $row['pctd']; $maxpctd = $row['maxpctd']; $compid = $row['compid']; $sql = "select * from compounds where compid = \"$compid\""; $result = mysql_query($sql,$conn); $row = mysql_fetch_array($result); $compname = $row['compname']; $concentration = $row['concentration']; $concunit = $row['concunit']; $type = $row['type']; $composition = $row['composition']; if ($fg=="Y") $html .= "$concentration $concunit $compname"; else if ($pri=="Y") $html .= " $concentration $concunit $compname"; else $html .= " $concentration $concunit $compname"; } Expected results: Actin #2543: Description here. 1 mol AEBSF 1.3 mol Calcium Chloride 1.4 mol Potassium Chloride Actual results: Actin #2543: Description here. 1 mol AEBSF i.e the last two compounds are not displayed. I can't for the life of me see the problem. A new set of eyes looking at this would be GREATLY appreciated. Thanks very much in advance. - Best regards, Lee -- 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] while loop question - problem (new set of eyes needed)
LPR> LPR> while($row = mysql_fetch_array($result)) LPR> { LPR> $pri = $row['pri']; LPR> $fg = $row['fg']; LPR> $molw = $row['molw']; LPR> $density = $row['density']; LPR> $denstype = $row['denstype']; LPR> $pctd = $row['pctd']; LPR> $maxpctd = $row['maxpctd']; LPR> $compid = $row['compid']; LPR> $sql = "select * from compounds where compid = \"$compid\""; LPR> $result = mysql_query($sql,$conn); LPR> $row = mysql_fetch_array($result); LPR> $compname = $row['compname']; LPR> $concentration = $row['concentration']; LPR> $concunit = $row['concunit']; LPR> $type = $row['type']; LPR> $composition = $row['composition']; LPR> if ($fg=="Y") LPR>$html .= "$concentration $concunit $compname"; LPR> else if ($pri=="Y") LPR>$html .= " $concentration $concunit LPR> $compname"; LPR> else LPR>$html .= " $concentration $concunit $compname"; LPR> } LPR> You are re-assigning the value of $row within the while construct. When you get to your query within the while chunk, use different variable names than the "master". - Julie --> Julie Meloni --> [EMAIL PROTECTED] --> www.thickbook.com Find "Sams Teach Yourself MySQL in 24 Hours" at http://www.amazon.com/exec/obidos/ASIN/0672323494/thickbookcom-20 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while loop: detect next loop?
Hi add the newline and white space first like this $data_printed = ""; while ($row = mysql_fetch_assoc($result)) { if($data_printed != ""){ $data_printed .= " \n"; } $data_printed = "" . $row['file_name'] . ""; } That will add to all except the last one. Tom At 07:04 AM 28/03/2002, you wrote: >There is a nice feature of a for loop, that I would like to replicate >somehow within a while loop. The short question is this -- is there any >way to detect if the while loop has one or more iterations remaining >(after the current iteration) to go through, so that I can [for instance] >add a comma or a newline or something to the text that is printed in the >loop iteration? > >In a for loop I can do this: > >for ($c = 0; $c < sizeof($array); $c++) { > $data_printed = $array[$c]; > if ($c < sizeof($array) - 1) { > $data_printed .= "\n"; > } >} > >I have a while loop like this: > >while ($row = mysql_fetch_assoc($result)) { > $data_printed = "" > . $row['file_name'] . ""; >} > >This prints things like this: >somefile.txtotherfile.pdf > >etc > >I do not want to blindly add a newline and some whitespace to EVERY >iteration, because this is XML and the whitespace is significant (and this >code will impact thousands of files), but I can't think of a clever way of >adding the newline and whitespace to every iteration EXCEPT the last one. > >TIA for any Jedi insight, > > >Erik > > > > > > >Erik Price >Web Developer Temp >Media Lab, H.H. Brown >[EMAIL PROTECTED] > > >-- >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] while loop: detect next loop?
On Thursday 28 March 2002 05:20, Erik Price wrote: > On Wednesday, March 27, 2002, at 04:11 PM, Matt Friedman wrote: > > When you have all your items in an array use implode to add a character > > in between every item. > > > > $str = implode($yourArray, $separator); > > > > This will add the separator to the end of each string except the last > > one. > > I like that idea, but I don't think it would work in this case -- for > one thing, the array is a pointer to a mysql_fetch_assoc() result, so I > am not sure how to implode that (not saying it can't be done), and for > another, I would have to explode the array again and would lose the > separator. > > Unless... unless I were to implode with say, a bogus separator AND a > 'real' separator, and then explode using only the bogus separator > (leaving the 'real' separator hanging onto the end of each element). > > This seems like it could work, but in a complex array like a > mysql_fetch_assoc() result, I'm not sure how to implode. All this imploding and exploding would probably eat lots of memory and CPU time if you have a large amount of data. What I do is just remove the extra bits after the while loop has finished. -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* I base my fashion taste on what doesn't itch. -- Gilda Radner */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while loop: detect next loop?
On Wednesday, March 27, 2002, at 04:11 PM, Matt Friedman wrote: > When you have all your items in an array use implode to add a character > in between every item. > > $str = implode($yourArray, $separator); > > This will add the separator to the end of each string except the last > one. I like that idea, but I don't think it would work in this case -- for one thing, the array is a pointer to a mysql_fetch_assoc() result, so I am not sure how to implode that (not saying it can't be done), and for another, I would have to explode the array again and would lose the separator. Unless... unless I were to implode with say, a bogus separator AND a 'real' separator, and then explode using only the bogus separator (leaving the 'real' separator hanging onto the end of each element). This seems like it could work, but in a complex array like a mysql_fetch_assoc() result, I'm not sure how to implode. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] while loop with if statement - here's the code
At 11:02 AM -0400 8/20/01, [EMAIL PROTECTED] wrote: > > >$results = mysql_db_query("$db", "select * from $table where $query order >by update_datetime desc limit $offset, 10"); > >while($one = mysql_fetch_array($results)){ > $id=$one["id"]; > $title=$one["title"]; > $description=$one["description"]; > > print " > height=8>HREF=/view_top.php3?id=$id>$title$description\n > width=10 height=6>\n > "; > }; > > if($results <= 0) > { > print " > NO >RESULTS\n > width=10 height=6>\n > "; > > } > >?> try... NO RESULTS\n \n "; else { print " $title$description\n \n "; }; } ?> The if should be before the print statement. You want it to compare then print, not print then compare. Alnisa -- . Alnisa Allgood Executive Director Nonprofit Tech (ph) 415.337.7412 (fx) 415.337.7927 (url) http://www.nonprofit-techworld.org (url) http://www.nonprofit-tech.org (url) http://www.tech-library.org . Nonprofit Tech E-Update mailto:[EMAIL PROTECTED] . applying technology to transform . -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop with if statement - here's the code
okay - read all the code now. this might be a better way: 0) { for ($x=0;$x<$numrows;$x++) { $id=$one["id"]; $title=$one["title"]; $description=$one["description"]; print " $title$description\n \n "; } // end of for } else { print " NO RESULTS\n \n "; } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop with if statement - here's the code
try using mysql_num_rows() to get the number of rows returned by the query. you need to supply it with the identifier for the query not the sql you sent to the query. not exactly sure what you're trying to do though ... Steve <[EMAIL PROTECTED]> wrote in message BB6D932A42D6D211B4AC0090274EBB1D2EF0F0@GLOBAL1">news:BB6D932A42D6D211B4AC0090274EBB1D2EF0F0@GLOBAL1... > Thanks Steve! :) Here's the code: > > > $results = mysql_db_query("$db", "select * from $table where $query order > by update_datetime desc limit $offset, 10"); > > while($one = mysql_fetch_array($results)){ > $id=$one["id"]; > $title=$one["title"]; > $description=$one["description"]; > > print " > height=8> HREF=/view_top.php3?id=$id>$title$description\n > width=10 height=6>\n > "; > }; >>>$numrows=mysql_num_rows($one); > if($numrows= =0) > { > print " > NO > RESULTS\n > width=10 height=6>\n > "; > > } > > ?> > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] while loop with if statement - here's the code
Thanks Steve! :) Here's the code: $title$description\n \n "; }; if($results <= 0) { print " NO RESULTS\n \n "; } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop with if statement - here's the attachment
did you do it again ? :-) pasting you code is ok ... Steve <[EMAIL PROTECTED]> wrote in message BB6D932A42D6D211B4AC0090274EBB1D2EF0EE@GLOBAL1">news:BB6D932A42D6D211B4AC0090274EBB1D2EF0EE@GLOBAL1... > > Here's the attachment - I hate it when I do that! :) > > > > -Original Message- > From: [EMAIL PROTECTED] > To: [EMAIL PROTECTED] > Sent: 8/20/01 10:25 AM > Subject: [PHP] while loop with if statement > > I can't figure out why the if statement isn't working. The page > displays > the same with or without the if statement. Any idea what I'm doing > wrong? > > I attached the code in a word document. > > Thank you, Shawna > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] while loop with if statement - here's the attachment
Here's the attachment - I hate it when I do that! :) -Original Message- From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: 8/20/01 10:25 AM Subject: [PHP] while loop with if statement I can't figure out why the if statement isn't working. The page displays the same with or without the if statement. Any idea what I'm doing wrong? I attached the code in a word document. Thank you, Shawna -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop
> > On Tue, 10 Apr 2001 15:16, Zeus wrote: > > > > $query = mysql_query("some SQL here"); > > > > while ($row = mysql_fetch_array($query)) { This line is the same as do while( ($row = mysql_fetch_array($query)) == TRUE) { Common coding style in C/C++ and PHP :) Regards, -- Yasuo Ohgaki ""Zeus"" <[EMAIL PROTECTED]> wrote in message 00b601c0c183$55647f60$4f7618d2@zeus">news:00b601c0c183$55647f60$4f7618d2@zeus... > Isn't the '=' operator suppose to be used for assigning and not for > evaluation. > > I thought '==' should be used in this context? > > Zeus > - Original Message - > From: David Robley <[EMAIL PROTECTED]> > To: Zeus <[EMAIL PROTECTED]>; Michael Hall <[EMAIL PROTECTED]>; Jacky > <[EMAIL PROTECTED]> > Cc: <[EMAIL PROTECTED]> > Sent: Tuesday, 10 April, 2001 1:53 PM > Subject: Re: [PHP] while loop > > > > On Tue, 10 Apr 2001 15:16, Zeus wrote: > > > > $query = mysql_query("some SQL here"); > > > > while ($row = mysql_fetch_array($query)) { > > > > do stuff; > > > > } > > > > > > Isn't this suppose to be an infinite loop? > > > > > > while ($row is assigned to mysql_fetch_array($query)) { > > > do stuffs; > > > } > > > > > > someone correct me if I'm wrong? > > > > > > Zeus > > > > Consider yourself corrected :-) mysql_fetch-array returns an array > > corresponding to the fetched row, or _false if there are no more rows_ > > > > So as soon as there are no more rows, $row = mysql_fetch_array($query) > > evaluates to false and the while exits. > > > > -- > > David Robley| WEBMASTER & Mail List Admin > > RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ > > AusEinet| http://auseinet.flinders.edu.au/ > > Flinders University, ADELAIDE, SOUTH AUSTRALIA > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop
What does this do : '; } } else { echo ' no result '. mysql_error(); } ?> Regards, Philip On Tue, 10 Apr 2001, Jacky@lilst wrote: > Here I got this script: > > $queryoffers = "SELECT * FROM MiniOffers WHERE hotel_id = '$hotelID' ORDER > BY start_date ASC"; > $resultofrs = mysql_query($queryoffers, $connection) or die(mysql_error()); > > while($row = mysql_fetch_array($resultofrs)) > > > $IsAva = $row[6]; > } > > and it keep saying "maximum execution time exceeded 30 secs", am I doing > something time consuming here? There are only 2 records in the table. > cheers > Jack > [EMAIL PROTECTED] > "There is nothing more rewarding than reaching the goal you set for > yourself" > - Original Message - > From: Zeus <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]>; Michael Hall <[EMAIL PROTECTED]>; > Jacky <[EMAIL PROTECTED]> > Cc: <[EMAIL PROTECTED]> > Sent: Tuesday, April 10, 2001 12:58 AM > Subject: Re: [PHP] while loop > > > > Isn't the '=' operator suppose to be used for assigning and not for > > evaluation. > > > > I thought '==' should be used in this context? > > > > Zeus > > - Original Message ----- > > From: David Robley <[EMAIL PROTECTED]> > > To: Zeus <[EMAIL PROTECTED]>; Michael Hall <[EMAIL PROTECTED]>; > Jacky > > <[EMAIL PROTECTED]> > > Cc: <[EMAIL PROTECTED]> > > Sent: Tuesday, 10 April, 2001 1:53 PM > > Subject: Re: [PHP] while loop > > > > > > > On Tue, 10 Apr 2001 15:16, Zeus wrote: > > > > > $query = mysql_query("some SQL here"); > > > > > while ($row = mysql_fetch_array($query)) { > > > > > do stuff; > > > > > } > > > > > > > > Isn't this suppose to be an infinite loop? > > > > > > > > while ($row is assigned to mysql_fetch_array($query)) { > > > > do stuffs; > > > > } > > > > > > > > someone correct me if I'm wrong? > > > > > > > > Zeus > > > > > > Consider yourself corrected :-) mysql_fetch-array returns an array > > > corresponding to the fetched row, or _false if there are no more rows_ > > > > > > So as soon as there are no more rows, $row = mysql_fetch_array($query) > > > evaluates to false and the while exits. > > > > > > -- > > > David Robley| WEBMASTER & Mail List Admin > > > RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ > > > AusEinet| http://auseinet.flinders.edu.au/ > > > Flinders University, ADELAIDE, SOUTH AUSTRALIA > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop
Zeus wrote: > > That was detailed :) > > Thanks Jack, it fixed my misconception of the = and == operators. > > BUT ... > > > mysql_fetch_array keeps track of where it is in the array. > > after each while loop it moves a 'step ahead' in the result > > the mysql_fetch_array fetches the results in an array but should it be an > one time affair ? hey, i'm not sure i follow the 'should it be an one time affair' question... if should be a X time affair, where X is the amount of rows returned from mysql. if you're wondering about the = and it being a 'one time' thing...well, it is, but since its stuck in a while loop, it used 'once' again and again...if that's not TOO confusing... i think of it the same way as something like this: $count=0; while($count++<10){ echo "count is $count"; } the increment operater is a 'one time' operation, but used in a loop, it'll keep going... same if you had this... while(($count+=1)<10){ echo "count is $count"; } (except of course the second loop cuts off before 10...) this help? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop
That was detailed :) Thanks Jack, it fixed my misconception of the = and == operators. BUT ... > mysql_fetch_array keeps track of where it is in the array. > after each while loop it moves a 'step ahead' in the result the mysql_fetch_array fetches the results in an array but should it be an one time affair ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop
Hi Jacky, @ 2:11:06 PM on 4/10/2001, Jacky@lilst wrote: > Not in the actual code, sorry, I did not copy the opnneing bit, but there is > one in the code. > So the same question, I got error said, maximum execution time exceed, am I > doing something time consuming here? Unless I'm blind this morning, I don't believe so. Try this and see what you get: ... >> @ 1:58:40 PM on 4/10/2001, Jacky@lilst wrote: >> >> > Here I got this script: >> >> > $queryoffers = "SELECT * FROM MiniOffers WHERE hotel_id = '$hotelID' >> > ORDER BY start_date ASC"; >> > $resultofrs = mysql_query($queryoffers, $connection) or > die(mysql_error()); >> >> > while($row = mysql_fetch_array($resultofrs)) >> >> Are you missing the opening curly brace in the actual code? >> >> > $IsAva = $row[6]; >> > } ... -Brian -- PGP is spoken here: 0xE4D0C7C8 Please do not carbon copy me on list replies. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop
Not in the actual code, sorry, I did not copy the opnneing bit, but there is one in the code. So the same question, I got error said, maximum execution time exceed, am I doing something time consuming here? Jack [EMAIL PROTECTED] "There is nothing more rewarding than reaching the goal you set for yourself" - Original Message - From: Brian Clark <[EMAIL PROTECTED]> To: PHP is not a drug. <[EMAIL PROTECTED]> Sent: Tuesday, April 10, 2001 1:05 AM Subject: Re: [PHP] while loop > > Hi Jacky, > > @ 1:58:40 PM on 4/10/2001, Jacky@lilst wrote: > > > Here I got this script: > > > $queryoffers = "SELECT * FROM MiniOffers WHERE hotel_id = '$hotelID' > > ORDER BY start_date ASC"; > > $resultofrs = mysql_query($queryoffers, $connection) or die(mysql_error()); > > > while($row = mysql_fetch_array($resultofrs)) > > Are you missing the opening curly brace in the actual code? > > > $IsAva = $row[6]; > > } > ... > > > -Brian > -- > PGP is spoken here: 0xE4D0C7C8 > Please do not carbon copy me on list replies. > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop
Zeus wrote: > > Isn't the '=' operator suppose to be used for assigning and not for > evaluation. > yup. > I thought '==' should be used in this context? nope. Thing is, you ARE assigning. Here's a breakdown of the controlling part of the loop in english: --->while ($row = mysql_fetch_array($query)) { this can be thought of as this: 1. fetch an array from $query, which is a mysql result. 2. assign this value to $row 3. we do this AS LONG AS WE ARE ABLE TO FETCH THE ARRAY. that's the while part mysql_fetch_array keeps track of where it is in the array. after each while loop it moves a 'step ahead' in the result when it gets to the end, it can't fetch anymore information from your result. then it returns false. thus, it can't assign a value to $row. thus that statement is false. therefore the while loop exits > > > do stuffs; > > > } > > > > > > someone correct me if I'm wrong? > > > > > > Zeus > > > > Consider yourself corrected :-) mysql_fetch-array returns an array > > corresponding to the fetched row, or _false if there are no more rows_ > > > > So as soon as there are no more rows, $row = mysql_fetch_array($query) > > evaluates to false and the while exits. > > > > -- > > David Robley| WEBMASTER & Mail List Admin > > RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ > > AusEinet| http://auseinet.flinders.edu.au/ > > Flinders University, ADELAIDE, SOUTH AUSTRALIA > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop
Hi Zeus, @ 1:58:56 AM on 4/10/2001, Zeus wrote: > Isn't the '=' operator suppose to be used for assigning and not for > evaluation. In this case, it /is/ used for assignment. print $row['some_column']; ... >> > Isn't this suppose to be an infinite loop? >> > >> > while ($row is assigned to mysql_fetch_array($query)) { >> > do stuffs; >> > } >> > >> > someone correct me if I'm wrong? ... >> Consider yourself corrected :-) mysql_fetch-array returns an array >> corresponding to the fetched row, or _false if there are no more rows_ >> >> So as soon as there are no more rows, $row = mysql_fetch_array($query) >> evaluates to false and the while exits. >> >> -- >> David Robley| WEBMASTER & Mail List Admin ... -Brian -- PGP is spoken here: 0xE4D0C7C8 Please do not carbon copy me on list replies. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop
Hi Jacky, @ 1:58:40 PM on 4/10/2001, Jacky@lilst wrote: > Here I got this script: > $queryoffers = "SELECT * FROM MiniOffers WHERE hotel_id = '$hotelID' > ORDER BY start_date ASC"; > $resultofrs = mysql_query($queryoffers, $connection) or die(mysql_error()); > while($row = mysql_fetch_array($resultofrs)) Are you missing the opening curly brace in the actual code? > $IsAva = $row[6]; > } ... -Brian -- PGP is spoken here: 0xE4D0C7C8 Please do not carbon copy me on list replies. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop
Here I got this script: $queryoffers = "SELECT * FROM MiniOffers WHERE hotel_id = '$hotelID' ORDER BY start_date ASC"; $resultofrs = mysql_query($queryoffers, $connection) or die(mysql_error()); while($row = mysql_fetch_array($resultofrs)) $IsAva = $row[6]; } and it keep saying "maximum execution time exceeded 30 secs", am I doing something time consuming here? There are only 2 records in the table. cheers Jack [EMAIL PROTECTED] "There is nothing more rewarding than reaching the goal you set for yourself" - Original Message - From: Zeus <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; Michael Hall <[EMAIL PROTECTED]>; Jacky <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Tuesday, April 10, 2001 12:58 AM Subject: Re: [PHP] while loop > Isn't the '=' operator suppose to be used for assigning and not for > evaluation. > > I thought '==' should be used in this context? > > Zeus > - Original Message - > From: David Robley <[EMAIL PROTECTED]> > To: Zeus <[EMAIL PROTECTED]>; Michael Hall <[EMAIL PROTECTED]>; Jacky > <[EMAIL PROTECTED]> > Cc: <[EMAIL PROTECTED]> > Sent: Tuesday, 10 April, 2001 1:53 PM > Subject: Re: [PHP] while loop > > > > On Tue, 10 Apr 2001 15:16, Zeus wrote: > > > > $query = mysql_query("some SQL here"); > > > > while ($row = mysql_fetch_array($query)) { > > > > do stuff; > > > > } > > > > > > Isn't this suppose to be an infinite loop? > > > > > > while ($row is assigned to mysql_fetch_array($query)) { > > > do stuffs; > > > } > > > > > > someone correct me if I'm wrong? > > > > > > Zeus > > > > Consider yourself corrected :-) mysql_fetch-array returns an array > > corresponding to the fetched row, or _false if there are no more rows_ > > > > So as soon as there are no more rows, $row = mysql_fetch_array($query) > > evaluates to false and the while exits. > > > > -- > > David Robley| WEBMASTER & Mail List Admin > > RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ > > AusEinet| http://auseinet.flinders.edu.au/ > > Flinders University, ADELAIDE, SOUTH AUSTRALIA > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop
Isn't the '=' operator suppose to be used for assigning and not for evaluation. I thought '==' should be used in this context? Zeus - Original Message - From: David Robley <[EMAIL PROTECTED]> To: Zeus <[EMAIL PROTECTED]>; Michael Hall <[EMAIL PROTECTED]>; Jacky <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Tuesday, 10 April, 2001 1:53 PM Subject: Re: [PHP] while loop > On Tue, 10 Apr 2001 15:16, Zeus wrote: > > > $query = mysql_query("some SQL here"); > > > while ($row = mysql_fetch_array($query)) { > > > do stuff; > > > } > > > > Isn't this suppose to be an infinite loop? > > > > while ($row is assigned to mysql_fetch_array($query)) { > > do stuffs; > > } > > > > someone correct me if I'm wrong? > > > > Zeus > > Consider yourself corrected :-) mysql_fetch-array returns an array > corresponding to the fetched row, or _false if there are no more rows_ > > So as soon as there are no more rows, $row = mysql_fetch_array($query) > evaluates to false and the while exits. > > -- > David Robley| WEBMASTER & Mail List Admin > RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ > AusEinet| http://auseinet.flinders.edu.au/ > Flinders University, ADELAIDE, SOUTH AUSTRALIA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop
On Tue, 10 Apr 2001 15:16, Zeus wrote: > > $query = mysql_query("some SQL here"); > > while ($row = mysql_fetch_array($query)) { > > do stuff; > > } > > Isn't this suppose to be an infinite loop? > > while ($row is assigned to mysql_fetch_array($query)) { > do stuffs; > } > > someone correct me if I'm wrong? > > Zeus Consider yourself corrected :-) mysql_fetch-array returns an array corresponding to the fetched row, or _false if there are no more rows_ So as soon as there are no more rows, $row = mysql_fetch_array($query) evaluates to false and the while exits. -- David Robley| WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet| http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] while loop
> Isn't this suppose to be an infinite loop? > > while ($row is assigned to mysql_fetch_array($query)) { > do stuffs; > } > > someone correct me if I'm wrong? They key here is that there's a single "=" in the condition. ... this is actually "while 'row equals the result of mysql_fetch_array($query)' returns true, do this..." mysql_fetch_array returns false when you run out of rows. Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop
> $query = mysql_query("some SQL here"); > while ($row = mysql_fetch_array($query)) { > do stuff; > } Isn't this suppose to be an infinite loop? while ($row is assigned to mysql_fetch_array($query)) { do stuffs; } someone correct me if I'm wrong? Zeus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop
$query = mysql_query("some SQL here"); while ($row = mysql_fetch_array($query)) { do stuff; } Mick On Tue, 10 Apr 2001, Jacky wrote: > Hi people > I am more like ASP programmer and new to PHP, In ASP, when we want to take all >records in dayabase to display. After we did do the query, we call " Do while not >RS.EOF ( mean do while not end of record file) , and display record accroding to the >query. > Is there anything that do teh same in PHP?? > cheers > Jack > [EMAIL PROTECTED] > "There is nothing more rewarding than reaching the goal you set for yourself" > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop
On Tue, 10 Apr 2001 22:52, Jacky wrote: > Hi people > I am more like ASP programmer and new to PHP, In ASP, when we want to > take all records in dayabase to display. After we did do the query, we > call " Do while not RS.EOF ( mean do while not end of record file) , > and display record accroding to the query. Is there anything that do > teh same in PHP?? > cheers While - have a look at the example for mysql_fetch_array for the concept. If you aren't using mysql, check the functions for the DB you are using for specific examples. -- David Robley| WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet| http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop
On 4/10/01 6:22 AM, "Jacky" <[EMAIL PROTECTED]> wrote: > Hi people > I am more like ASP programmer and new to PHP, In ASP, when we want to take all > records in dayabase to display. After we did do the query, we call " Do while > not RS.EOF ( mean do while not end of record file) , and display record > accroding to the query. > Is there anything that do teh same in PHP?? > cheers > Jack > [EMAIL PROTECTED] > "There is nothing more rewarding than reaching the goal you set for yourself" > sure, while ($row = ODBC_fetch_into($result) {} will loop through every result record found, putting the contents of each record into an array, $row. see the www.php.net/manual for a general overview of the language -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] while loop and modulus?
by default, HTML browsers, according to spec, will handle the rendering of any and all empty cells at the end of a row. even netscape ;) so, this is technically not a bug. my question is how it works when you have 7 photos in a row, or 4? DanO -Original Message- From: James, Yz [mailto:[EMAIL PROTECTED]] Sent: Tuesday, February 27, 2001 11:18 AM To: [EMAIL PROTECTED] Subject: [PHP] while loop and modulus? OK, using this code: \n"; echo "\n"; $photocount = 0; while($row = mysql_fetch_array($result)) { $smallpic = $row['smallpic']; echo "$smallpic\n"; if (($photocount % 3) == 2) { echo "\n\n"; } $photocount++; } echo "\n"; echo ""; ?> And 8 photos in the table, I'm getting this output: sm982438092.gif sm982437452.gif sm982439016.gif sm982529915.gif sm983222652.gif sm983222686.gif sm983222868.gif sm983222919.gif Great, except it's missing an end cell, and after a few hours fiddling about with code last night, I still didn't get any further in working out how I was going to echo a table cell even if data's missing. So, any help would be appreciated. Apologies for what're probably "easy" questions. I slog away at work all day, come back hoping to get something productive done on this, and the ol'brain won't take it. Frustrating, to say the least. James. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while loop and modulus?
"James, Yz" wrote: OK, using this code: echo "\n"; echo "\n"; $photocount = 0; while($row = mysql_fetch_array($result)) { $smallpic = $row['smallpic']; echo "$smallpic\n"; if (($photocount % 3) == 2) { echo "\n\n"; } $photocount++; } This should fill in the remaining cells you need. You might have to tinker with it a bit to fit your code though. Good luck :-) for ($cnt = 0; $cnt < $phonecount % 3; $cnt++) echo " echo "\n"; echo ""; ?> And 8 photos in the table, I'm getting this output: sm982438092.gif sm982437452.gif sm982439016.gif sm982529915.gif sm983222652.gif sm983222686.gif sm983222868.gif sm983222919.gif Great, except it's missing an end cell, and after a few hours fiddling about with code last night, I still didn't get any further in working out how I was going to echo a table cell even if data's missing. So, any help would be appreciated. Apologies for what're probably "easy" questions. I slog away at work all day, come back hoping to get something productive done on this, and the ol'brain won't take it. Frustrating, to say the least. James. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- 209 Media Ron Wills <[EMAIL PROTECTED]> Programmer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]