...

View Full Version : How to display specific variables on a page?



aimerzz4
12-25-2007, 02:52 AM
I am categorizing comic book issues through a PHP variable, and I need to know how to display a specific variable on a page:

$bp = '<p><b>Black Panther</b></p><p>
Black Panther #18<br><br>
Black Panther #22<br><br>
Black Panther #31</p>';
$cd = '<p><b>Cable & Deadpool</b></p>
<p>Cable & Deadpool #6<br><br>
Cable & Deadpool #7<br><br>
Cable & Deadpool #8<br><br>
Cable & Deadpool #9</p>'

Now, I'd like to then create a new page and split B from C and also display only the variable $cd and vice versa...how would I do that? I am a complete n00b at PHP so please talk in baby talk. I would like to also "categorize" these variables such as $cd would be 'ongoing' and let's say $bp would be a mini-series. Then I could display only a certain variable such as 'ongoing' and it'd only show the variables categorized as 'ongoing.' Is there such a way?

mic2100
12-25-2007, 09:46 PM
you would need to use the command echo.



$bp = '<p><b>Black Panther</b></p><p>
Black Panther #18<br><br>
Black Panther #22<br><br>
Black Panther #31</p>';
$cd = '<p><b>Cable & Deadpool</b></p>
<p>Cable & Deadpool #6<br><br>
Cable & Deadpool #7<br><br>
Cable & Deadpool #8<br><br>
Cable & Deadpool #9</p>';

echo $bp;

echo $cb;


Merry Christmas

oesxyl
12-25-2007, 10:41 PM
I am categorizing comic book issues through a PHP variable, and I need to know how to display a specific variable on a page:

how mic2100 allready say, use echo




$bp = '<p><b>Black Panther</b></p><p>
Black Panther #18<br><br>
Black Panther #22<br><br>
Black Panther #31</p>';
$cd = '<p><b>Cable & Deadpool</b></p>
<p>Cable & Deadpool #6<br><br>
Cable & Deadpool #7<br><br>
Cable & Deadpool #8<br><br>
Cable & Deadpool #9</p>'

Now, I'd like to then create a new page and split B from C and also display only the variable $cd and vice versa...how would I do that? I am a complete n00b at PHP so please talk in baby talk. I would like to also "categorize" these variables such as $cd would be 'ongoing' and let's say $bp would be a mini-series. Then I could display only a certain variable such as 'ongoing' and it'd only show the variables categorized as 'ongoing.' Is there such a way?

I don't understand what do you want to do, what do you mean by "split B from C", "categorize", what is "ongoing", maybe if you give an example of what do you want I could help you.

happy holydays.

aimerzz4
12-28-2007, 08:23 PM
Thanks guys. I'll try this out right now. I'll get back to you, oesxyl, so I can explain it better. Lol

aimerzz4
12-28-2007, 08:30 PM
Yeah, Okay, I used the echo command and see, I have a whole ton of variables on this PHP file.

You can see it here:
http://emmafrostfiles.com/appearancesa.php

I only want to display $axm ....when I use the echo command, it not only displays $axm but it also displays all the rest of the variables. How do I get it so that it only displays $axm ?

johnnyb
12-28-2007, 08:33 PM
What's the line of the code that does the echoing? Do display $axm it should read:

echo $axm;

Also, can you show us the variable $axm? I'm wondering if there's a problem with quotation marks.

aimerzz4
12-28-2007, 08:36 PM
$axm = '<p><b>Astonishing X-Men</b></p>
<p>Astonishing X-Men #1<br><br>
Astonishing X-Men #2<br><br>
Astonishing X-Men #3<br><br>
Astonishing X-Men #4<br><br>
Astonishing X-Men #5<br><br>
Astonishing X-Men #6<br><br>
Astonishing X-Men #7<br><br>
Astonishing X-Men #8<br><br>
Astonishing X-Men #9<br><br>
Astonishing X-Men #10<br><br>
Astonishing X-Men #11<br><br>
Astonishing X-Men #12<br><br>
Astonishing X-Men #13<br><br>
Astonishing X-Men #14<br><br>
Astonishing X-Men #15<br><br>
Astonishing X-Men #16<br><br>
Astonishing X-Men #17<br><br>
Astonishing X-Men #18<br><br>
Astonishing X-Men #19<br><br>
Astonishing X-Men #20<br><br>
Astonishing X-Men #21<br><br>
Astonishing X-Men #22<br><br>
Astonishing X-Men #23<br><br>
Astonishing X-Men #24<br><br>Giant Sized Astonishing X-Men #1</p>';
$bp = '<p><b>Black Panther</b></p><p>
Black Panther #18<br><br>
Black Panther #22<br><br>
Black Panther #31</p>';
$cd = '<p><b>Cable & Deadpool</b></p>
<p>Cable & Deadpool #6<br><br>
Cable & Deadpool #7<br><br>
Cable & Deadpool #8<br><br>
Cable & Deadpool #9</p>';

That's part of the file ^^^. I'd like to use this

<?php include 'allapp.php';
echo $axm ?>

And display just the $axm variable, not all the others.

johnnyb
12-28-2007, 08:43 PM
I took another look at the link you posted, and it looks like the whole allapp.php file is getting echoed, then $axm is getting echoed again at the end.

I'm thinking that there must be something in allapp.php echoing all of the variables, then your 'echo $axm;' is doing its job properly, making the "Astonishing X-men" section appear twice.

Look at the end of allapp.php and see what else is there. I'm guessing you'll find some sort of echo or print command.

If you want to try removing stuff without messing around with the file too much just comment the sections out:


// the two slashes comment out a single line
/* the slash then * comment out several lines
this is still part of the same comment
end the comment with a * then a slash, like this: */

aimerzz4
12-28-2007, 08:44 PM
Oh, you know what...I fixed it guys. I had a whole bunch of echos in the allapp.php

As for the other question I had, is there a way I can...hmm...

Like

$axm, $bp, $cd = $ongoing

So if echoed the variable $ongoing, it would display $axm, $bp, and $cd. Know what I mean?

ETA: That was exactly the problem jonny, thanks!

johnnyb
12-28-2007, 08:48 PM
For your new question:


$ongoing = $axm . $bp . $cd (etc...);


The . combines strings. You don't need the spaces like I've shown above, but it makes it easier to read.

aimerzz4
12-28-2007, 08:53 PM
Thank you!

...And another dumb question, I completely forgot to center the allapp.php ....is there a way I can do this thru


<?php include 'allapp.php';
echo '<p class="center">$axm</p>' ?>

Now that obviously doesn't work, but is there way I can center thru that code?

oesxyl
12-28-2007, 09:01 PM
try to use data structure as that:


$baxm = array('Astonishing X-Men' => array ('#1', '#2', ...),
'Giant Sized Astonishing X-Men' => array( '#1'),
'Black Panther' => array('#18', '#22', '#31'),
'Cable & Deadpool' => array('#6', '#7', '#8', '#9')
);

echo $baxm['Black Panter'][2];


or maybe a database, that's depend of your abillity to work with php, :D

that's could be 'categorize'?

best regards

aimerzz4
12-28-2007, 09:05 PM
That's confusing, but I have to go now. I'll get back to you. Thanks a lot guys!

johnnyb
12-28-2007, 09:21 PM
Thank you!


<?php include 'allapp.php';
echo '<p class="center">$axm</p>' ?>

Now that obviously doesn't work, but is there way I can center thru that code?

Do it like this:


echo '<p class="center">'.$axm.'</p>';




oesxyl is suggesting that having everything in big variables in a PHP file is not the most convenient way to store your data. It'll be a real pain to change things later on and it's much more flexible to store it in an Array or a Database. If you want to learn more about Arrays check out the PHP Manual Array Page (http://ca3.php.net/manual/en/language.types.array.php).

aimerzz4
12-29-2007, 02:01 AM
You know with something like that, I might as well just hire someone! Thanks!

aimerzz4
12-29-2007, 02:05 AM
echo '<p class="center">'.$axm.'</p>';

That did not work and won't center....I might just have to change the external <P> tag on my stylesheet now.

oesxyl
12-29-2007, 02:18 AM
echo '<p class="center">'.$axm.'</p>';

That did not work and won't center....I might just have to change the external <P> tag on my stylesheet now.

in http://emmafrostfiles.com/style.css line 355, change text-align: justified; with text-align: center;

before any other change, be sure that don't affect other pages.

best regards

aimerzz4
12-29-2007, 02:23 AM
Thanks! You guys are very nice and helpful. Instead of editing the external file, which would also effect all the other <p>'s, I just searched and found <p> and replaced it with <p class="center"> in the allapp.php file.

oesxyl
12-29-2007, 02:28 AM
Thanks! You guys are very nice and helpful. Instead of editing the external file, which would also effect all the other <p>'s, I just searched and found <p> and replaced it with <p class="center"> in the allapp.php file.

if you have firefox, install firebug extension, is more easy to walk and debug your page, :D

PS: just in case you don't have allready installed, :thumbsup:
best regards

aimerzz4
12-29-2007, 02:33 AM
Sorry but how do I display multiple echos? It's not letting me.
'
ETA: Nevermind, got it! I also installed the firebug plugin. Thanks.

oesxyl
12-29-2007, 02:39 AM
Sorry but how do I display multiple echos? It's not letting me.

what do you mean it's not letting you?



echo "first";
echo "second";


same thing with variables.

best regards

aimerzz4
12-29-2007, 02:48 AM
<?php include 'allapp.php';
echo $f4xm . $fs ;
?>

I actually have it displayed like that and it works fine....



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum