This is a discussion on Question about 'sizeof' within the PHP Language forums, part of the PHP Programming Forums category; On May 8, 12:31 pm, Piotr <s...@poczta.onet.pl> wrote: > SM wrote: > > On ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
On May 8, 12:31 pm, Piotr <s...@poczta.onet.pl> wrote:
> SM wrote: > > On May 8, 11:50 am, SM <servandomont...@gmail.com> wrote: > >> On May 8, 11:42 am, Piotr <s...@poczta.onet.pl> wrote: > > >>>>> $thumb = 1; > >>>>> $item = '$thumbs_cat_' . $thumb; //this outputs a string: > >>>>> $thumbs_cat_1 > >>>>> $item_total = sizeof($item); > >>>>> output: Nothing! > >>>>> How do i pass a variable to the 'sizeof' function? > >>>> You should use variable variable: > >>>> $item_total = sizeof($$item); > >>>> Mark double $$ > >>>> This is true in any situation, not only with sizeof > >>> Forgot about one small detail: > >>> $item = 'thumbs_cat_' . $thumb; //this outputs a string: > >>> ---------^ loose the '$'; > >>> best regards > >>> Piotr N > >> I don't need the length of the string , just the actual variable. But > >> i did like the fact that sizeof is an alias of count. So i will use > >> count instead. > >> I didn't know about the $$ tip. Wow! so easy. Thanks, It Works! > > >> Heres the final code: > > >> $thumb = 1; > >> $item = 'thumbs_cat_' . $thumb; > >> $item_total = count($$item); > > >> Thanks again > >> Marco > > > Maybe i should open a new post for this one, but here it goes: > > > I'm stock! When i want to reference that variable in a echo statment, > > it does't work. Any suggestions? > > Thanks > > > <li><a href="<?php echo $SERVER['PHP_SELF']; ?>?cat=<?php echo > > $category_this; ?>"><img src="images/<?php echo($$item[$i]);?>" > > alt="" /></a></li> > > :) > It should look like this. Mark the { and } > echo ${$item[$i]}; > > As a side note, is this really best way to access needed data this way ? > Cant you keep original values in the array instead of the variable names ? > > best regards > Piotr N I've tried it, It doesn't work. When i look at the source code, i see empty an empty string: <img src="images/" alt="" /> Here's what im trying to do: -From a list, the user selects the type of discography (either original, compilation, tributes, other) -Each type of discography is associated with an array that contains the name of the cd cover. -Then i show a thumbnail (using a loop) of all the cd covers depending on the array. my arrays look like this $thumbs_cat_1 = array('moonlight.jpg'', shadow.jpg', 'luna'); $thumbs_cat_2 = array(...); $thumbs_cat_3 = array(...); $thumbs_cat_4 = array(...); the thumbs look like this: for($i=0; ...){ ....<img src="images/discography/thumbs/<?php echo $thumbs_cat_1[$i]; ? >" alt="" /> } All of this , works for the first array. That's why i have a variable that contains the selection from the user: $thumb = $_GET['cat']; $item = 'thumbs_cat_' . $thumb; $item_total = count($$item); .... and so on That's why i need to create images according to the user selection Any ideas what's wrong with the code? Thanks Marco |
|
|||
|
On May 8, 12:31 pm, Piotr <s...@poczta.onet.pl> wrote:
> SM wrote: > > On May 8, 11:50 am, SM <servandomont...@gmail.com> wrote: > >> On May 8, 11:42 am, Piotr <s...@poczta.onet.pl> wrote: > > >>>>> $thumb = 1; > >>>>> $item = '$thumbs_cat_' . $thumb; //this outputs a string: > >>>>> $thumbs_cat_1 > >>>>> $item_total = sizeof($item); > >>>>> output: Nothing! > >>>>> How do i pass a variable to the 'sizeof' function? > >>>> You should use variable variable: > >>>> $item_total = sizeof($$item); > >>>> Mark double $$ > >>>> This is true in any situation, not only with sizeof > >>> Forgot about one small detail: > >>> $item = 'thumbs_cat_' . $thumb; //this outputs a string: > >>> ---------^ loose the '$'; > >>> best regards > >>> Piotr N > >> I don't need the length of the string , just the actual variable. But > >> i did like the fact that sizeof is an alias of count. So i will use > >> count instead. > >> I didn't know about the $$ tip. Wow! so easy. Thanks, It Works! > > >> Heres the final code: > > >> $thumb = 1; > >> $item = 'thumbs_cat_' . $thumb; > >> $item_total = count($$item); > > >> Thanks again > >> Marco > > > Maybe i should open a new post for this one, but here it goes: > > > I'm stock! When i want to reference that variable in a echo statment, > > it does't work. Any suggestions? > > Thanks > > > <li><a href="<?php echo $SERVER['PHP_SELF']; ?>?cat=<?php echo > > $category_this; ?>"><img src="images/<?php echo($$item[$i]);?>" > > alt="" /></a></li> > > :) > It should look like this. Mark the { and } > echo ${$item[$i]}; > > As a side note, is this really best way to access needed data this way ? > Cant you keep original values in the array instead of the variable names ? > > best regards > Piotr N I've tried it, It doesn't work. When i look at the source code, i see empty an empty string: <img src="images/" alt="" /> Here's what im trying to do: -From a list, the user selects the category of discography (either original, compilation, tributes, other) -Each type of discography is associated with an array that contains the name of the cd covers. -Then i show a thumbnail (using a loop) of all the cd covers. my arrays look like this (one for each category of discography) $thumbs_cat_1 = array('moonlight.jpg'', shadow.jpg', 'luna.jpg'); $thumbs_cat_2 = array(...); $thumbs_cat_3 = array(...); $thumbs_cat_4 = array(...); Then i create the thumbs like this: for($i=0; ...){ ....<img src="images/discography/thumbs/<?php echo $thumbs_cat_1[$i]; ? >" alt="" /> } All of this works perfectly for the first array. That's why, i think, i need a variable that contains the selection from the user (the category of discography) so i can select values from the correct array. I do it like this: $cat = $_GET['cat']; //output: 1 $sel_array = 'thumbs_cat_' . $cat;//create the string: thumbs_cat_1 Then i create the thumbs like this: for($i=0; ...){ ....<img src="images/discography/thumbs/<?php echo ${$sel_array[$i]}; ? >" alt="" /> } .... and so on You think my code makes sense? Maybe i'm doing it wrong. The last part is were im stock... Any ideas what's wrong? Thanks again Marco |
|
|||
|
On May 8, 12:31 pm, Piotr <s...@poczta.onet.pl> wrote:
> SM wrote: > > On May 8, 11:50 am, SM <servandomont...@gmail.com> wrote: > >> On May 8, 11:42 am, Piotr <s...@poczta.onet.pl> wrote: > > >>>>> $thumb = 1; > >>>>> $item = '$thumbs_cat_' . $thumb; //this outputs a string: > >>>>> $thumbs_cat_1 > >>>>> $item_total = sizeof($item); > >>>>> output: Nothing! > >>>>> How do i pass a variable to the 'sizeof' function? > >>>> You should use variable variable: > >>>> $item_total = sizeof($$item); > >>>> Mark double $$ > >>>> This is true in any situation, not only with sizeof > >>> Forgot about one small detail: > >>> $item = 'thumbs_cat_' . $thumb; //this outputs a string: > >>> ---------^ loose the '$'; > >>> best regards > >>> Piotr N > >> I don't need the length of the string , just the actual variable. But > >> i did like the fact that sizeof is an alias of count. So i will use > >> count instead. > >> I didn't know about the $$ tip. Wow! so easy. Thanks, It Works! > > >> Heres the final code: > > >> $thumb = 1; > >> $item = 'thumbs_cat_' . $thumb; > >> $item_total = count($$item); > > >> Thanks again > >> Marco > > > Maybe i should open a new post for this one, but here it goes: > > > I'm stock! When i want to reference that variable in a echo statment, > > it does't work. Any suggestions? > > Thanks > > > <li><a href="<?php echo $SERVER['PHP_SELF']; ?>?cat=<?php echo > > $category_this; ?>"><img src="images/<?php echo($$item[$i]);?>" > > alt="" /></a></li> > > :) > It should look like this. Mark the { and } > echo ${$item[$i]}; > > As a side note, is this really best way to access needed data this way ? > Cant you keep original values in the array instead of the variable names ? > > best regards > Piotr N I've tried it, It doesn't work. When i look at the source code, i see an empty string: <img src="images/" alt="" /> Here's what im trying to do: -From a list, the user selects the category of discography (either original, compilation, tributes, other) -Each type of discography is associated with an array that contains the name of the cd covers. -Then i show a thumbnail (using a loop) of all the cd covers. my arrays look like this (one for each category of discography) $thumbs_cat_1 = array('moonlight.jpg'', shadow.jpg', 'luna.jpg'); $thumbs_cat_2 = array(...); $thumbs_cat_3 = array(...); $thumbs_cat_4 = array(...); Then i create the thumbs like this: for($i=0; ...){ ....<img src="images/discography/thumbs/<?php echo $thumbs_cat_1[$i]; ? >" alt="" /> } All of this works perfectly for the first array. That's why, i think, i need a variable that contains the selection from the user (the category of discography) so i can select values from the correct array. I do it like this: $cat = $_GET['cat']; //output: 1 $sel_array = 'thumbs_cat_' . $cat;//create the string: thumbs_cat_1 Then i create the thumbs like this: for($i=0; ...){ ....<img src="images/discography/thumbs/<?php echo ${$sel_array[$i]}; ? >" alt="" /> } .... and so on You think my code makes sense? Maybe i'm doing it wrong. The last part is were im stock... Any ideas what's wrong? Thanks again Marco |
|
|||
|
SM wrote:
> On May 8, 12:31 pm, Piotr <s...@poczta.onet.pl> wrote: >> SM wrote: >>> On May 8, 11:50 am, SM <servandomont...@gmail.com> wrote: >>>> On May 8, 11:42 am, Piotr <s...@poczta.onet.pl> wrote: >>>>>>> $thumb = 1; >>>>>>> $item = '$thumbs_cat_' . $thumb; //this outputs a string: >>>>>>> $thumbs_cat_1 >>>>>>> $item_total = sizeof($item); >>>>>>> output: Nothing! >>>>>>> How do i pass a variable to the 'sizeof' function? >>>>>> You should use variable variable: >>>>>> $item_total = sizeof($$item); >>>>>> Mark double $$ >>>>>> This is true in any situation, not only with sizeof >>>>> Forgot about one small detail: >>>>> $item = 'thumbs_cat_' . $thumb; //this outputs a string: >>>>> ---------^ loose the '$'; >>>>> best regards >>>>> Piotr N >>>> I don't need the length of the string , just the actual variable. But >>>> i did like the fact that sizeof is an alias of count. So i will use >>>> count instead. >>>> I didn't know about the $$ tip. Wow! so easy. Thanks, It Works! >>>> Heres the final code: >>>> $thumb = 1; >>>> $item = 'thumbs_cat_' . $thumb; >>>> $item_total = count($$item); >>>> Thanks again >>>> Marco >>> Maybe i should open a new post for this one, but here it goes: >>> I'm stock! When i want to reference that variable in a echo statment, >>> it does't work. Any suggestions? >>> Thanks >>> <li><a href="<?php echo $SERVER['PHP_SELF']; ?>?cat=<?php echo >>> $category_this; ?>"><img src="images/<?php echo($$item[$i]);?>" >>> alt="" /></a></li> >> :) >> It should look like this. Mark the { and } >> echo ${$item[$i]}; >> >> As a side note, is this really best way to access needed data this way ? >> Cant you keep original values in the array instead of the variable names ? >> >> best regards >> Piotr N > > I've tried it, It doesn't work. When i look at the source code, i see > an empty string: > <img src="images/" alt="" /> > > Here's what im trying to do: > -From a list, the user selects the category of discography (either > original, compilation, tributes, other) > -Each type of discography is associated with an array that contains > the name of the cd covers. > -Then i show a thumbnail (using a loop) of all the cd covers. > > my arrays look like this (one for each category of discography) > $thumbs_cat_1 = array('moonlight.jpg'', shadow.jpg', 'luna.jpg'); > $thumbs_cat_2 = array(...); > $thumbs_cat_3 = array(...); > $thumbs_cat_4 = array(...); > > Then i create the thumbs like this: > for($i=0; ...){ > ...<img src="images/discography/thumbs/<?php echo $thumbs_cat_1[$i]; ? >> " alt="" /> > } > > All of this works perfectly for the first array. > > > That's why, i think, i need a variable that contains the selection > from the user (the category of discography) so i can select values > from the correct array. > I do it like this: > > $cat = $_GET['cat']; //output: 1 > $sel_array = 'thumbs_cat_' . $cat;//create the string: thumbs_cat_1 > > > > > Then i create the thumbs like this: > for($i=0; ...){ > ...<img src="images/discography/thumbs/<?php echo ${$sel_array[$i]}; ? >> " alt="" /> > } > ... and so on > > You think my code makes sense? Maybe i'm doing it wrong. > The last part is were im stock... > > > Any ideas what's wrong? > Thanks again > Marco > Why go to all that trouble. Just use a two dimensional array, i.e. $thumb_cats = array(); $thumb_cats[] = array('moonlight.jpg'', shadow.jpg', 'luna.jpg'); $thumb_cats[] = array(...); $thumb_cats[] = array(...); $thumb_cats[] = array(...); $thumb_cats[] = array(...); <img src="images/discography/thumbs/<?php echo $thumb_cats[$sel][$i];?>" alt="" /> Much cleaner. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
On May 8, 4:27 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> SM wrote: > > On May 8, 12:31 pm, Piotr <s...@poczta.onet.pl> wrote: > >> SM wrote: > >>> On May 8, 11:50 am, SM <servandomont...@gmail.com> wrote: > >>>> On May 8, 11:42 am, Piotr <s...@poczta.onet.pl> wrote: > >>>>>>> $thumb = 1; > >>>>>>> $item = '$thumbs_cat_' . $thumb; //this outputs a string: > >>>>>>> $thumbs_cat_1 > >>>>>>> $item_total = sizeof($item); > >>>>>>> output: Nothing! > >>>>>>> How do i pass a variable to the 'sizeof' function? > >>>>>> You should use variable variable: > >>>>>> $item_total = sizeof($$item); > >>>>>> Mark double $$ > >>>>>> This is true in any situation, not only with sizeof > >>>>> Forgot about one small detail: > >>>>> $item = 'thumbs_cat_' . $thumb; //this outputs a string: > >>>>> ---------^ loose the '$'; > >>>>> best regards > >>>>> Piotr N > >>>> I don't need the length of the string , just the actual variable. But > >>>> i did like the fact that sizeof is an alias of count. So i will use > >>>> count instead. > >>>> I didn't know about the $$ tip. Wow! so easy. Thanks, It Works! > >>>> Heres the final code: > >>>> $thumb = 1; > >>>> $item = 'thumbs_cat_' . $thumb; > >>>> $item_total = count($$item); > >>>> Thanks again > >>>> Marco > >>> Maybe i should open a new post for this one, but here it goes: > >>> I'm stock! When i want to reference that variable in a echo statment, > >>> it does't work. Any suggestions? > >>> Thanks > >>> <li><a href="<?php echo $SERVER['PHP_SELF']; ?>?cat=<?php echo > >>> $category_this; ?>"><img src="images/<?php echo($$item[$i]);?>" > >>> alt="" /></a></li> > >> :) > >> It should look like this. Mark the { and } > >> echo ${$item[$i]}; > > >> As a side note, is this really best way to access needed data this way ? > >> Cant you keep original values in the array instead of the variable names ? > > >> best regards > >> Piotr N > > > I've tried it, It doesn't work. When i look at the source code, i see > > an empty string: > > <img src="images/" alt="" /> > > > Here's what im trying to do: > > -From a list, the user selects the category of discography (either > > original, compilation, tributes, other) > > -Each type of discography is associated with an array that contains > > the name of the cd covers. > > -Then i show a thumbnail (using a loop) of all the cd covers. > > > my arrays look like this (one for each category of discography) > > $thumbs_cat_1 = array('moonlight.jpg'', shadow.jpg', 'luna.jpg'); > > $thumbs_cat_2 = array(...); > > $thumbs_cat_3 = array(...); > > $thumbs_cat_4 = array(...); > > > Then i create the thumbs like this: > > for($i=0; ...){ > > ...<img src="images/discography/thumbs/<?php echo $thumbs_cat_1[$i]; ? > >> " alt="" /> > > } > > > All of this works perfectly for the first array. > > > That's why, i think, i need a variable that contains the selection > > from the user (the category of discography) so i can select values > > from the correct array. > > I do it like this: > > > $cat = $_GET['cat']; //output: 1 > > $sel_array = 'thumbs_cat_' . $cat;//create the string: thumbs_cat_1 > > > Then i create the thumbs like this: > > for($i=0; ...){ > > ...<img src="images/discography/thumbs/<?php echo ${$sel_array[$i]}; ? > >> " alt="" /> > > } > > ... and so on > > > You think my code makes sense? Maybe i'm doing it wrong. > > The last part is were im stock... > > > Any ideas what's wrong? > > Thanks again > > Marco > > Why go to all that trouble. Just use a two dimensional array, i.e. > > $thumb_cats = array(); > $thumb_cats[] = array('moonlight.jpg'', shadow.jpg', 'luna.jpg'); > $thumb_cats[] = array(...); > $thumb_cats[] = array(...); > $thumb_cats[] = array(...); > $thumb_cats[] = array(...); > > <img src="images/discography/thumbs/<?php echo $thumb_cats[$sel][$i];?>" > alt="" /> > > Much cleaner. > > -- > ================== > Remove the "x" from my email address > Jerry Stuckle > JDS Computer Training Corp. > jstuck...@attglobal.net > ================== Hey Jeery! Thanks . That help a lot! Much cleaner and nicer. Marco |
|
|||
|
On May 8, 4:27 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> SM wrote: > > On May 8, 12:31 pm, Piotr <s...@poczta.onet.pl> wrote: > >> SM wrote: > >>> On May 8, 11:50 am, SM <servandomont...@gmail.com> wrote: > >>>> On May 8, 11:42 am, Piotr <s...@poczta.onet.pl> wrote: > >>>>>>> $thumb = 1; > >>>>>>> $item = '$thumbs_cat_' . $thumb; //this outputs a string: > >>>>>>> $thumbs_cat_1 > >>>>>>> $item_total = sizeof($item); > >>>>>>> output: Nothing! > >>>>>>> How do i pass a variable to the 'sizeof' function? > >>>>>> You should use variable variable: > >>>>>> $item_total = sizeof($$item); > >>>>>> Mark double $$ > >>>>>> This is true in any situation, not only with sizeof > >>>>> Forgot about one small detail: > >>>>> $item = 'thumbs_cat_' . $thumb; //this outputs a string: > >>>>> ---------^ loose the '$'; > >>>>> best regards > >>>>> Piotr N > >>>> I don't need the length of the string , just the actual variable. But > >>>> i did like the fact that sizeof is an alias of count. So i will use > >>>> count instead. > >>>> I didn't know about the $$ tip. Wow! so easy. Thanks, It Works! > >>>> Heres the final code: > >>>> $thumb = 1; > >>>> $item = 'thumbs_cat_' . $thumb; > >>>> $item_total = count($$item); > >>>> Thanks again > >>>> Marco > >>> Maybe i should open a new post for this one, but here it goes: > >>> I'm stock! When i want to reference that variable in a echo statment, > >>> it does't work. Any suggestions? > >>> Thanks > >>> <li><a href="<?php echo $SERVER['PHP_SELF']; ?>?cat=<?php echo > >>> $category_this; ?>"><img src="images/<?php echo($$item[$i]);?>" > >>> alt="" /></a></li> > >> :) > >> It should look like this. Mark the { and } > >> echo ${$item[$i]}; > > >> As a side note, is this really best way to access needed data this way ? > >> Cant you keep original values in the array instead of the variable names ? > > >> best regards > >> Piotr N > > > I've tried it, It doesn't work. When i look at the source code, i see > > an empty string: > > <img src="images/" alt="" /> > > > Here's what im trying to do: > > -From a list, the user selects the category of discography (either > > original, compilation, tributes, other) > > -Each type of discography is associated with an array that contains > > the name of the cd covers. > > -Then i show a thumbnail (using a loop) of all the cd covers. > > > my arrays look like this (one for each category of discography) > > $thumbs_cat_1 = array('moonlight.jpg'', shadow.jpg', 'luna.jpg'); > > $thumbs_cat_2 = array(...); > > $thumbs_cat_3 = array(...); > > $thumbs_cat_4 = array(...); > > > Then i create the thumbs like this: > > for($i=0; ...){ > > ...<img src="images/discography/thumbs/<?php echo $thumbs_cat_1[$i]; ? > >> " alt="" /> > > } > > > All of this works perfectly for the first array. > > > That's why, i think, i need a variable that contains the selection > > from the user (the category of discography) so i can select values > > from the correct array. > > I do it like this: > > > $cat = $_GET['cat']; //output: 1 > > $sel_array = 'thumbs_cat_' . $cat;//create the string: thumbs_cat_1 > > > Then i create the thumbs like this: > > for($i=0; ...){ > > ...<img src="images/discography/thumbs/<?php echo ${$sel_array[$i]}; ? > >> " alt="" /> > > } > > ... and so on > > > You think my code makes sense? Maybe i'm doing it wrong. > > The last part is were im stock... > > > Any ideas what's wrong? > > Thanks again > > Marco > > Why go to all that trouble. Just use a two dimensional array, i.e. > > $thumb_cats = array(); > $thumb_cats[] = array('moonlight.jpg'', shadow.jpg', 'luna.jpg'); > $thumb_cats[] = array(...); > $thumb_cats[] = array(...); > $thumb_cats[] = array(...); > $thumb_cats[] = array(...); > > <img src="images/discography/thumbs/<?php echo $thumb_cats[$sel][$i];?>" > alt="" /> > > Much cleaner. > > -- > ================== > Remove the "x" from my email address > Jerry Stuckle > JDS Computer Training Corp. > jstuck...@attglobal.net > ================== Hey Jerry! Thanks . That help a lot! Much cleaner and nicer and it works perfectly! :) Marco |
![]() |
| Thread Tools | |
| Display Modes | |
|
|