Web Hosting Talk







View Full Version : php variable explanations needed


bambinou
04-06-2010, 08:03 PM
Hi,

I am on a very basic level of programming, I decided to do more work on my own, I am ok with CSS and html, now I struggle with PHP.
I would like to understand the principal of $variables, let's say I have the code below(only partial code):

<table>
<tr>
<td width='250'><b>Band Name:</b><br>
".$artistInfo['artist_band_name']."
</td>
<td align='left' width='191'>".$moreReviewLink."</td>
</tr><tr>
<td colspan = '2'>&nbsp;</td>
</tr>
<tr width='441' height = '130'>
<td colspan = '2' valign='top'> <b>Review: </b>
<br>".$reviewInformation[$i]['review_text']."</td></tr></table></td></tr>
</table></a>";
echo "<li style='overflow: hidden; float: left; width: 579px; height: 312px;' class='carousel-mainMod-panel'>".$strTabular."</li>";

If If I wanted to add some text just below the "$review Information" how could I do this?

How does a variable works? how to create a text and then put the full text in one single variable, this way I dont have to copy all the text each time but just add an echo statemen instead.

I hope you understand what I mean but I also hope I have not misunderstood what a PHP variable is used for.

I would really like to be able to show a full text through a variable.


Now I explain why I am looking at having a variable in the text above, the way the code works is, people can post a review on my site from time to time, but, I want to add some publicity at the end of all the reviews, now I have been trying to add pure html code with an echo statement to the code above but the problem is that my code shows only once and is not repeated on each review, therefore, I believed that having a variable instead would enable the code to repeat this action each time a review is written.....I hope I am right :-)




Regards,


BamBam

canishosting
04-06-2010, 10:51 PM
First, a little basic programming 101... Variables..

Variables are items that hold information.

$blah = "hello";.

echo $blah;

output: hello

Echo....

echo "woof"; -- echo means "print", "output", "send it to the screen".

If you want to add some text, between the </table></a>"; and the next line, just put an echo in there.

</table></a>";
echo "this is what I want to output";
echo "<li>....

if you just want to add html, make sure its before the "; and after the </a>.

I hope that helps.

bambinou
04-07-2010, 07:03 AM
Thank you very much for that.


What I would like to know is,
Where can you define variables and how to point it to when you have created it in a subfolder.

Let's say we have 2 pages, one here:
http://www.mysite.com/index.php

and one here http://www.mysite.com/file/index.php

On the first page I created this line:
$blah = "hello";.


On the second page I wish to output this echo but bear in mind, the echo statement $blah = "hello";. is not in the same folder as the page I wish to output the echo to.

Finally my last question:

When you create variables, in which part of the page this should be done and what type of code should it come before and after the $variable line.



My idea would be to create 1 single file with all my site echos and print these echo on other pages when necessary.

The way my site is built right now, I would believe that I can create as many echos as possible on one page and output them where ever I want(subfolders) without showing a path, but I need to double check with you.

I am very sorry to ask such stupid questions but I have bought a php book and I believe it is a little too advanced for me, therefore you are my only possible chance to progress to a point where I will be able to handle this book correctly.


Regards,

BamBam

bambinou
04-07-2010, 07:18 AM
Just adding a new question...what would this means in php?
$reviewInformation[$reviewIndex] = $reviewData;

Does this means that the data $reviewindex that has been posted in the $reviewinformation variable will now be called $reviewdata > Am I right|?

meijin
04-07-2010, 08:00 AM
$reviewInformation is an array (read about it - its basic)
$reviewIndex is a key - and this key contains $reviewData (value of $reviewData) ...

bambinou
04-07-2010, 08:53 AM
thanks for the explanation, I will try to find a basic guide on the net

meijin
04-07-2010, 08:57 AM
thanks for the explanation, I will try to find a basic guide on the net

You should especially take a look at PHP documentation (google: php arrays).

You should also search other stuff there because for basic use you will find there everything

bambinou
04-07-2010, 09:24 AM
Thanks Meijin