wintallo Posted February 1, 2007 Share Posted February 1, 2007 Hey, First, thanks for the read. Second, I need help using the contents of PHP variable ( in my case it's called $category ) to call another variable. In other words I want to call an variable called "$(whatever the contents of the $category is)_count". The category variable varies widely in its contents so I want to do it this way so I don't have to manually type in $whatever_count on every page is used this method. If you don't get what I'm sayings please feel free to ask questions. Again, thanks for the read. -Joel wintallo@gmail.com Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 1, 2007 Share Posted February 1, 2007 $($category)_count Quote Link to comment Share on other sites More sharing options...
.josh Posted February 2, 2007 Share Posted February 2, 2007 variable variables Quote Link to comment Share on other sites More sharing options...
wintallo Posted February 2, 2007 Author Share Posted February 2, 2007 Well, I'm kind of unsure on how to implement that knowledge in my case. This is what I tried, but it doesn't work. <?php $category = "animations"; include 'greatmovies_categorycount.php'; sort($animations); $($category)_length = count(($category)); for ( $counter = 0; $counter <= ( $($category)_length - 1); $counter++ ) { $title = ${$category}[$counter]; $image = ereg_replace(' ', '_', ${$category}[$counter]); $image = ereg_replace('\:', '', $image); $image = ereg_replace('\.', '', $image); $image = ereg_replace('\,', '', $image); $image = ereg_replace('\;', '', $image); $image = ereg_replace('\?', '', $image); $image = ereg_replace('\'', '', $image); $image = "images/game-movie_pictures/".strtolower($image)."_pic_small.png"; $url = ereg_replace(' ', '', ${$category}[$counter]); $url = ereg_replace('\:', '', $url); $url = ereg_replace('\.', '', $url); $url = ereg_replace('\,', '', $url); $url = ereg_replace('\;', '', $url); $url = ereg_replace('\?', '', $url); $url = ereg_replace('\'', '', $url); $url = "game-movie_pages/".strtolower($url).".php"; if ( $new_movie == $title ) { ${$category . "_done"}[$counter] = '<img alt="New!" src="images/new_button.png" /><br /><a href="'.$url.'"><img alt="'.$title.'" src="'.$image.'" /></a> <a href="'.$url.'">'.$title.'</a>'; } else { ${$category . "_done"}[$counter] = '<a href="'.$url.'"><img alt="'.$title.'" src="'.$image.'" /></a> <a href="'.$url.'">'.$title.'</a>'; } } echo "if this doesn't display then the codes broken!"; ?> Thanks for the replies too! Quote Link to comment Share on other sites More sharing options...
corbin Posted February 2, 2007 Share Posted February 2, 2007 replace all the ${$catergory}'s with $$category and it should work if I read the PHP documentation correctly. Quote Link to comment Share on other sites More sharing options...
wintallo Posted February 2, 2007 Author Share Posted February 2, 2007 Ok, I tried that and it still doesn't work! This is my revised (non-functional ) code. <?php $category = "animations"; include 'greatmovies_categorycount.php'; sort($animations); $($category)_length = count(($category)); for ( $counter = 0; $counter <= ( $($category)_length - 1); $counter++ ) { $title = $$category[$counter]; $image = ereg_replace(' ', '_', $$category[$counter]); ... $image = "images/game-movie_pictures/".strtolower($image)."_pic_small.png"; $url = ereg_replace(' ', '', $$category[$counter]); ... $url = "game-movie_pages/".strtolower($url).".php"; if ( $new_movie == $title ) { ${$category . "_done"}[$counter] = '<img alt="New!" src="images/new_button.png" /><br /><a href="'.$url.'"><img alt="'.$title.'" src="'.$image.'" /></a> <a href="'.$url.'">'.$title.'</a>'; } else { ${$category . "_done"}[$counter] = '<a href="'.$url.'"><img alt="'.$title.'" src="'.$image.'" /></a> <a href="'.$url.'">'.$title.'</a>'; } } echo "if this doesn't display then the codes broken!"; ?> Quote Link to comment Share on other sites More sharing options...
.josh Posted February 2, 2007 Share Posted February 2, 2007 so is this: include 'greatmovies_categorycount.php'; where $animations is being set? if not, then where are you assigning something to $animations? also, can you be more specific than "it doesn't work"? Are you getting some kind of error, or just a blank page? Quote Link to comment Share on other sites More sharing options...
corbin Posted February 2, 2007 Share Posted February 2, 2007 Hmmm its supposed to be used as either $$var or ${$var}... My bad on tellin you to drop the curly braces... Try changin it back to what it was... And $category and $animations are set correctly right? Quote Link to comment Share on other sites More sharing options...
wintallo Posted February 2, 2007 Author Share Posted February 2, 2007 Crayon Violent: First, yes include 'greatmovies_categorycount.php'; is where $animations is being set. It's being set to $animations = array("Animator vs. Animation","Black Dude Falling","Over the Rainbow","United Airlines: Dragon","Motion"); Second, when it test it out, it spits out a blank page, when it should output "if this doesn't display then the codes broken!" because off the third to last line in my code. Corbin: Yes $category is declared correctly, (3rd line of my code) <?php $category = "animations"; // right here include 'greatmovies_categorycount.php'; And what I said to Crayon Violent explains that $animations is set correctly Quote Link to comment Share on other sites More sharing options...
wintallo Posted February 2, 2007 Author Share Posted February 2, 2007 currently, this is what my code is <?php $category = "animations"; include 'greatmovies_categorycount.php'; sort($animations); $($category)_length = count(($category)); for ( $counter = 0; $counter <= ( $($category)_length - 1); $counter++ ) { $title = ${$category}[$counter]; $image = ereg_replace(' ', '_', ${$category}[$counter]); // stuff $image = "images/game-movie_pictures/".strtolower($image)."_pic_small.png"; $url = ereg_replace(' ', '', ${$category}[$counter]); // stuff $url = "game-movie_pages/".strtolower($url).".php"; if ( $new_movie == $title ) { ${$category . "_done"}[$counter] = '<img alt="New!" src="images/new_button.png" /><br /><a href="'.$url.'"><img alt="'.$title.'" src="'.$image.'" /></a> <a href="'.$url.'">'.$title.'</a>'; } else { ${$category . "_done"}[$counter] = '<a href="'.$url.'"><img alt="'.$title.'" src="'.$image.'" /></a> <a href="'.$url.'">'.$title.'</a>'; } } echo "if this doesn't display then the codes broken!"; ?> Thanks for all of you guy's help so far! Quote Link to comment Share on other sites More sharing options...
hvle Posted February 2, 2007 Share Posted February 2, 2007 try this: replace this line $($category)_length = count(($category)); with: $catLen = $category.'_length'; now use: $$catLen instead of $($category)_length Quote Link to comment Share on other sites More sharing options...
wintallo Posted February 2, 2007 Author Share Posted February 2, 2007 Yah, I though of that, but the problem is, is that I need the multiple length variables co-existing. I'll give the code for both greatmovies_categorycount.php and greatmovies_include.php (the code I been revising). greatmovies_categorycount.php <?php $animations = array("Animator vs. Animation","Black Dude Falling","Over the Rainbow","United Airlines: Dragon","Motion"); $clever = array("Banned Xbox 360 Commercial","Instant Kiwi Exam","What Old People Do For Fun"); $first_rate_films = array("Big Ad","Christmas Lights Show","Honda Rube Goldberg Commercial","Kiwi","Ryan vs Dorkman","Gnarls Barkley CRAZY"); $heart_stoppers = array("Ghostly Car","Pumpkin Carve"); $pure_irony = array("Ameriquest Cat Commerical","Antidote for Workaholics","Car Bait","German Coast Guard","Ice Scraping","Oh, Mama","Wow Satellite Dish","Acupuncture Insurance Commercial","Smoking Kills"); $parodies = array("Got Milk?","iPod Flea","Numa Numa Man","Small Ad","They're Taking the Hobbits to Isengard","White and Nerdy"); $short_clips = array("Blonde Antelope","Hamster Wheel Gone Wrong","How to Park a Dirt Bike","Ice Fishing","Pool Jump","Road Rage Granny"); $self_produced = array("The Random Adventures of Aaron","Three for All, and None for Us"); $slapstick = array("Cubicle War","Funny Toyota Spot","Horse and Sleigh","Man vs. Bear"); $super_bowl = array("FedEx: Stick","Sierra Mist","Vault: Scarecrow"); $weird = array("Nintendo 64 Kid Goes Crazy","Indian Rollerskater"); $wicked_skills = array("Matrix Ping Pong","Ok Go","Nintendo Accapella","Peugeot Style","Robot Dance","Pepsi Super People"); $new_movie = "Motion"; $self_produced_count = count($self_produced); $animations_count = count($animations); $clever_count = count($clever); $first_rate_films_count = count($first_rate_films); $heart_stoppers_count = count($heart_stoppers); $parodies_count = count($pure_irony); $pure_irony_count = count($parodies); $short_clips_count = count($short_clips); $slapstick_count = count($slapstick); $super_bowl_count = count($super_bowl); $weird_count = count($weird); $wicked_skills_count = count($wicked_skills); //$new_category = "self_produced"; $new_category = "animations"; //$new_category = "clever"; //$new_category = "first_rate_films"; //$new_category = "heart_stoppers"; //$new_category = "parodies"; //$new_category = "pure_irony"; //$new_category = "short_clips"; //$new_category = "slapstick"; //$new_category = "super_bowl"; //$new_category = "weird"; //$new_category = "wicked_skills"; ?> greatmovies_include.php <?php $category = "animations"; include 'greatmovies_categorycount.php'; sort($animations); for ( $counter = 0; $counter <= ( $($category)_count - 1); $counter++ ) { $title = ${$category}[$counter]; $image = ereg_replace(' ', '_', ${$category}[$counter]); $image = ereg_replace('\:', '', $image); $image = ereg_replace('\.', '', $image); $image = ereg_replace('\,', '', $image); $image = ereg_replace('\;', '', $image); $image = ereg_replace('\?', '', $image); $image = ereg_replace('\'', '', $image); $image = "images/game-movie_pictures/".strtolower($image)."_pic_small.png"; $url = ereg_replace(' ', '', ${$category}[$counter]); $url = ereg_replace('\:', '', $url); $url = ereg_replace('\.', '', $url); $url = ereg_replace('\,', '', $url); $url = ereg_replace('\;', '', $url); $url = ereg_replace('\?', '', $url); $url = ereg_replace('\'', '', $url); $url = "game-movie_pages/".strtolower($url).".php"; if ( $new_movie == $title ) { ${$category . "_done"}[$counter] = '<img alt="New!" src="images/new_button.png" /><br /><a href="'.$url.'"><img alt="'.$title.'" src="'.$image.'" /></a> <a href="'.$url.'">'.$title.'</a>'; } else { ${$category . "_done"}[$counter] = '<a href="'.$url.'"><img alt="'.$title.'" src="'.$image.'" /></a> <a href="'.$url.'">'.$title.'</a>'; } } echo "if this doesn't display then the codes broken!"; ?> Quote Link to comment Share on other sites More sharing options...
wintallo Posted February 2, 2007 Author Share Posted February 2, 2007 Ok the success message comes up but I added a bit of code to see if the generated html doesn't come up. When I look in the source of the generated page, the only this that was there was "if this doesn't display then the codes broken!" Not any of the genrated code here's my code <?php $category = "animations"; include 'greatmovies_categorycount.php'; sort($animations); $length = $category.'_count'; for ( $counter = 0; $counter <= ( $length - 1); $counter++ ) { $title = ${$category}[$counter]; $image = ereg_replace(' ', '_', ${$category}[$counter]); $image = ereg_replace('\:', '', $image); $image = ereg_replace('\.', '', $image); $image = ereg_replace('\,', '', $image); $image = ereg_replace('\;', '', $image); $image = ereg_replace('\?', '', $image); $image = ereg_replace('\'', '', $image); $image = "images/game-movie_pictures/".strtolower($image)."_pic_small.png"; $url = ereg_replace(' ', '', ${$category}[$counter]); $url = ereg_replace('\:', '', $url); $url = ereg_replace('\.', '', $url); $url = ereg_replace('\,', '', $url); $url = ereg_replace('\;', '', $url); $url = ereg_replace('\?', '', $url); $url = ereg_replace('\'', '', $url); $url = "game-movie_pages/".strtolower($url).".php"; if ( $new_movie == $title ) { ${$category . "_done"}[$counter] = '<img alt="New!" src="images/new_button.png" /><br /><a href="'.$url.'"><img alt="'.$title.'" src="'.$image.'" /></a> <a href="'.$url.'">'.$title.'</a>'; } else { ${$category . "_done"}[$counter] = '<a href="'.$url.'"><img alt="'.$title.'" src="'.$image.'" /></a> <a href="'.$url.'">'.$title.'</a>'; } echo ${$category . "_done"}[$counter]; echo "<p> </p>"; } echo "if this doesn't display then the codes broken!"; ?> Quote Link to comment Share on other sites More sharing options...
wintallo Posted February 2, 2007 Author Share Posted February 2, 2007 Hip Hip Hooray! I found the problem. BUt thanks for all you help. For future notice, this is my code. <?php include 'greatmovies_categorycount.php'; sort($animations); for ( $counter = 0; $counter <= ( ${ $category . '_count' } - 1 ); $counter++ ) { $title = ${$category}[$counter]; $image = ereg_replace(' ', '_', ${$category}[$counter]); $image = ereg_replace('\:', '', $image); $image = ereg_replace('\.', '', $image); $image = ereg_replace('\,', '', $image); $image = ereg_replace('\;', '', $image); $image = ereg_replace('\?', '', $image); $image = ereg_replace('\'', '', $image); $image = "images/game-movie_pictures/".strtolower($image)."_pic_small.png"; $url = ereg_replace(' ', '', ${$category}[$counter]); $url = ereg_replace('\:', '', $url); $url = ereg_replace('\.', '', $url); $url = ereg_replace('\,', '', $url); $url = ereg_replace('\;', '', $url); $url = ereg_replace('\?', '', $url); $url = ereg_replace('\'', '', $url); $url = "game-movie_pages/".strtolower($url).".php"; if ( $new_movie == $title ) { ${$category . "_done"}[$counter] = '<img alt="New!" src="images/new_button.png" /><br /><a href="'.$url.'"><img alt="'.$title.'" src="'.$image.'" /></a> <a href="'.$url.'">'.$title.'</a>'; } else { ${$category . "_done"}[$counter] = '<a href="'.$url.'"><img alt="'.$title.'" src="'.$image.'" /></a> <a href="'.$url.'">'.$title.'</a>'; } echo ${$category . "_done"}[$counter]; echo "<p> </p>"; } echo "if this doesn't display then the codes broken!"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.