473,395 Members | 1,639 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.

modifying 'for... loop ' with php to leave out one number

Hello
Im using the following loop to populate a list box but I dont want th
current selected value (from database) to show in the list
The one I want to omitt is in the variable

$row['bbannerorgfont']

I wish to some how include this in the below loop to the effect of

echo from 0 to 6 except for $row['bbannerorgfont']

VB has select...case... etc. Is there something similar with PHP?

<?
for($i = 0; $i < 7; $i++) {
echo "<option value='".$i+1."'>".$i+1."</option><br>";
}
?>

cheers ian
Jul 31 '06 #1
11 1415
Ian Davies wrote:
VB has select...case... etc. Is there something similar with PHP?
The PHP equivalent is the Switch statement
See: http://us3.php.net/manual/en/control...res.switch.php

Jul 31 '06 #2
Like:
($i = 0; ($i < 7)&&($i!=$row['bbannerorgfont']); $i++) {....
?

Ian Davies wrote:
Hello
Im using the following loop to populate a list box but I dont want th
current selected value (from database) to show in the list
The one I want to omitt is in the variable

$row['bbannerorgfont']

I wish to some how include this in the below loop to the effect of

echo from 0 to 6 except for $row['bbannerorgfont']

VB has select...case... etc. Is there something similar with PHP?

<?
for($i = 0; $i < 7; $i++) {
echo "<option value='".$i+1."'>".$i+1."</option><br>";
}
?>

cheers ian
Jul 31 '06 #3
Ignore me...it would end the loop!...duhhh...

Gary Hasler wrote:
Like:
($i = 0; ($i < 7)&&($i!=$row['bbannerorgfont']); $i++) {....
?
Jul 31 '06 #4
*** Ian Davies escribió/wrote (Mon, 31 Jul 2006 20:16:50 GMT):
Hello
Im using the following loop to populate a list box but I dont want th
current selected value (from database) to show in the list
The one I want to omitt is in the variable

$row['bbannerorgfont']
[...]
for($i = 0; $i < 7; $i++) {
echo "<option value='".$i+1."'>".$i+1."</option><br>";
}

if($i != $row['bbannerorgfont']){
echo .......
}

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Jul 31 '06 #5
"Ian Davies" <ia********@virgin.netwrote:
Im using the following loop to populate a list box but I dont want th
current selected value (from database) to show in the list
The one I want to omitt is in the variable

$row['bbannerorgfont']

I wish to some how include this in the below loop to the effect of

echo from 0 to 6 except for $row['bbannerorgfont']

VB has select...case... etc. Is there something similar with PHP?
switch($i)
{
case 0:
do something;
break;
case 1:
do something else;
break;
}
<?
for($i = 0; $i < 7; $i++) {
echo "<option value='".$i+1."'>".$i+1."</option><br>";
}
?>
for ($i = 0; $i < 7; $i++)
{
if ($i == $row['bbannerorgfont'])
continue;
echo "<option value='" . $i + 1 . "'>" . $i + 1 . "</option><br>";
}
--
Photos from 40 countries on 5 continents: http://travel.u.nu
Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
Airports of the world: http://airport.u.nu
Jul 31 '06 #6
Thans all
I think the switch would be best thanks
Ian

"Miguel Cruz" <sp**@admin.u.nuwrote in message
news:spam-61CD95.05034201082006@localhost...
"Ian Davies" <ia********@virgin.netwrote:
Im using the following loop to populate a list box but I dont want th
current selected value (from database) to show in the list
The one I want to omitt is in the variable

$row['bbannerorgfont']

I wish to some how include this in the below loop to the effect of

echo from 0 to 6 except for $row['bbannerorgfont']

VB has select...case... etc. Is there something similar with PHP?

switch($i)
{
case 0:
do something;
break;
case 1:
do something else;
break;
}
<?
for($i = 0; $i < 7; $i++) {
echo "<option value='".$i+1."'>".$i+1."</option><br>";
}
?>

for ($i = 0; $i < 7; $i++)
{
if ($i == $row['bbannerorgfont'])
continue;
echo "<option value='" . $i + 1 . "'>" . $i + 1 . "</option><br>";
}
--
Photos from 40 countries on 5 continents: http://travel.u.nu
Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
Airports of the world: http://airport.u.nu

Jul 31 '06 #7
"Ian Davies" <ia********@virgin.netwrote in message
news:Od********************@newsfe6-gui.ntli.net...
Thans all
I think the switch would be best thanks
No, it's just closest thing to what you've used in VB. A simple if
statement, such as the one suggested by Miquel, would be the _best_ choice.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net || Gedoon-S @ IRCnet || rot13(xv***@bhgbyrzcv.arg)
Aug 1 '06 #8
"Kimmo Laine" <sp**@outolempi.netwrote in message
news:R7***************@reader1.news.jippii.net...
"Ian Davies" <ia********@virgin.netwrote in message
news:Od********************@newsfe6-gui.ntli.net...
Thans all
I think the switch would be best thanks

No, it's just closest thing to what you've used in VB. A simple if
statement, such as the one suggested by Miquel, would be the _best_
choice.
>
--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net || Gedoon-S @ IRCnet || rot13(xv***@bhgbyrzcv.arg)

Hello
I also realised this too and have decides afterall to go with the if
statement by Miquel (THANKS MIQUEL) as there will be less lines of code. Do
you know if there is a performance advantage over the switch method?

Ian
Aug 1 '06 #9
*** Ian Davies escribió/wrote (Tue, 01 Aug 2006 10:53:54 GMT):
I also realised this too and have decides afterall to go with the if
statement by Miquel (THANKS MIQUEL) as there will be less lines of code. Do
you know if there is a performance advantage over the switch method?
Don't care about performance at this level. Just try to do what best suits
your code logic: it's far more important to understand your code several
months after your wrote it.

Typical performance issues are more like:

* Fetching 5000 database records to display the top 5
* Dynamically generating the very same thumbnail every time it's requested
* Loading a full 20MB text file into memory to process it line by line

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Aug 1 '06 #10
"Ian Davies" <ia********@virgin.netwrote:
I also realised this too and have decides afterall to go with the if
statement by Miquel (THANKS MIQUEL) as there will be less lines of code. Do
you know if there is a performance advantage over the switch method?
I expect the 'if' method would be faster as there's less parsing and
testing.

miguel
--
Photos from 40 countries on 5 continents: http://travel.u.nu
Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
Airports of the world: http://airport.u.nu
Aug 1 '06 #11
Ian Davies wrote:
Hello
Im using the following loop to populate a list box but I dont want th
current selected value (from database) to show in the list
The one I want to omitt is in the variable

$row['bbannerorgfont']

I wish to some how include this in the below loop to the effect of

echo from 0 to 6 except for $row['bbannerorgfont']

VB has select...case... etc. Is there something similar with PHP?
create an array which contains the needed values*, then:

foreach ($array as $foo) {
echo '<option value="$foo">$foo</option>';
}

* or have a default array and remove the unecessary ones.
Aug 7 '06 #12

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

Similar topics

11
by: brainsucker | last post by:
Hi My name is Juan Carlos Rodrigo, and I love Python. It is the most impressive and usefull language that I have ever seen. I am studing, at http://www.uoc.edu, an Information Technology...
2
by: chuck | last post by:
Hi, I am modifying some code from here http://www.quirksmode.org/dom/domform.html I have a div 'readroot' that I clone. I change the change the id and name of the childnodes of 'readroot' to...
13
by: Robin Becker | last post by:
When young I was warned repeatedly by more knowledgeable folk that self modifying code was dangerous. Is the following idiom dangerous or unpythonic? def func(a): global func, data data =...
4
by: sklett | last post by:
(I posted this in a databinding NG, but it's a VERY low traffic NG so I thought I would post here as well. I hope no one minds too much, if you do I'm sorry) I have a DGV that is bound to a...
24
by: allpervasive | last post by:
hi all, this is reddy, a beginner to c lang,,here i have some problems in reading and modifying the contents of a file,, hope you can help to solve this problem. Here i attach the file to be...
4
by: nondos | last post by:
Hello I have a thread that run loop in queue variable like this: For each <somethingas <somethingin <queue variable>
11
by: magicman | last post by:
can anyone point me out to its implementation in C before I roll my own. thx
5
by: IUnknown | last post by:
Ok, we are all aware of the situation where modifying the folder structure (adding files, folders, deleting files, etc) will result in ASP.NET triggering a recompilation/restart of the application....
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.