Jump to content


Photo

Code Question.


  • Please log in to reply
11 replies to this topic

#1 coljung

coljung
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 28 September 2006 - 12:29 AM

well i'm kinda new to php but not to programming.
i just installed a server package on my pc ( apache, php, mysql, etc.... ) and it comes with some examples, one of them is about retrieving some data from a database, i understand most of whats going on except for a few lines that retrieve some info which i have NO idea where it's coming from.

here is the code from the file:
<html>
<head>
<title>apachefriends.org cd collection</title>
<link href="xampp.css" rel="stylesheet" type="text/css">
</head>

<body>

&nbsp;<p>
<h1><?=$TEXT['cds-head']?></h1>

<?=$TEXT['cds-text1']?><p>
<?=$TEXT['cds-text2']?><p>

<?

	if(!mysql_connect("localhost","root","######"))
	{
		echo "<h2>".$TEXT['cds-error']."</h2>";
		die();
	}
	mysql_select_db("cdcol");
?>

<h2><?=$TEXT['cds-head1']?></h2>

<table border=0 cellpadding=0 cellspacing=0>
<tr bgcolor=#f87820>
<td><img src=img/blank.gif width=10 height=25></td>
<td class=tabhead><img src=img/blank.gif width=200 height=6><br><b><?=$TEXT['cds-attrib1']?></b></td>
<td class=tabhead><img src=img/blank.gif width=200 height=6><br><b><?=$TEXT['cds-attrib2']?></b></td>
<td class=tabhead><img src=img/blank.gif width=50 height=6><br><b><?=$TEXT['cds-attrib3']?></b></td>
<td class=tabhead><img src=img/blank.gif width=50 height=6><br><b><?=$TEXT['cds-attrib4']?></b></td>
<td><img src=img/blank.gif width=10 height=25></td>
</tr>


What is =$TEXT['cds-head']? doing for example ???

i know that i retrieve the info from the database through mysql_select_db("cdcol");

but what are all the =$TEXT[ ]  mean ?

the page looks like this : 
Posted Image

As you can see,

=$TEXT['cds-head'] = CD Collection (Example for PHP+MySQL+PDF Class)
=$TEXT['cds-text1'] = A very simple CD programm.
=$TEXT['cds-text2'] = CD list as PDF document.

my question is, where did this words came from ?

i've been the whole day trying to understand that part of the code but im unable to figure it out.

thanks in advance for the help.

???

#2 pedrobcabral

pedrobcabral
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 28 September 2006 - 12:37 AM

That is arrays, do this code on a "test.php" to try to understand
<?php

$test = array("onething","twothings","treethings");

echo "<pre>";
print_r($test); 

echo $test[1];
?>

And check out this link: http://www.tizag.com/phpT/arrays.php

#3 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 28 September 2006 - 12:40 AM

Cripes!  In the first place <?= is the 'good luck this might work' method of actually printing whatever comes next. <?php echo is better practice.

The code example you cite isn't going to do anything useful, since what's actually needed to get 'something' to happen is:

connect to database server
select a database
.. and what's completely missing in your example
select some data from a specific database table
display the data
Legend has it that reading the manual never killed anyone.
My site

#4 coljung

coljung
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 28 September 2006 - 01:06 AM

thanks for the fast replies.

now, my specific question is what is :
=$TEXT['cds-head']
=$TEXT['cds-text1']
=$TEXT['cds-text2']

in this case is not relevant if its an array of if the code isn't doing anything useful but im wondering is where is the value of that coming from.

why 'cds-head' shows as CD Collection (Example for PHP+MySQL+PDF Class) for example

is cds-head part of the database ?
where was the info added into the array ?


#5 Fehnris

Fehnris
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 28 September 2006 - 06:37 AM

Its not possible from the code you have supplied to say whether the $text variables are either an array or part of the database.

There is no association between $text and data in your database.  There would be a couple of lines in there after the database connection and database selection to select data. Something like:-

$somequery = "Select......";
$somequeryresult("$somequery");
$text = mysql_fetch_array($somequeryresult);

to give an indication that the $text variables contain your database records.

Nor is there an association between $text and it being an array containing data.  There is no array initialisation.  Something like:-

$text = array($variable1, $variable2,.....$variableN)).

Quite frankly it doesnt look like the $text values do anything at all.

What does this code do when you run it?  You have included a screen grab of what the page is supposed to look like when viewed in a browser but from the code you've posted I just dont see how the code and output match up.

#6 Cell0518

Cell0518
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts
  • LocationUSA / Japan (US Navy)

Posted 28 September 2006 - 06:52 AM

What package did you install?  This would give us a way to see ALL of the code.

Thanks,
Chris
Chris

#7 coljung

coljung
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 28 September 2006 - 11:19 PM

i installed xampp.

Its not possible from the code you have supplied to say whether the $text variables are either an array or part of the database.

There is no association between $text and data in your database.  There would be a couple of lines in there after the database connection and database selection to select data. Something like:-

$somequery = "Select......";
$somequeryresult("$somequery");
$text = mysql_fetch_array($somequeryresult);

to give an indication that the $text variables contain your database records.

Nor is there an association between $text and it being an array containing data.  There is no array initialisation.  Something like:-

$text = array($variable1, $variable2,.....$variableN)).

Quite frankly it doesnt look like the $text values do anything at all.

What does this code do when you run it?  You have included a screen grab of what the page is supposed to look like when viewed in a browser but from the code you've posted I just dont see how the code and output match up.


The screen grab is what results from the code.

for example =$TEXT['cds-head'] shows as CD Collection (Example for PHP+MySQL+PDF Class)

What I think is that $TEXT is some kind of global array. Going though some of the files, I found several instances of $TEXT['  '], i just haven't been able to find where the array is taking the information from. And i don't think it is the database because i checked it an in this case it has only one table with 4 fields.

It does look as it has been initialized somewhere else, in this case the filename is cds.php and the $TEXT values are ['cds-head'], ['cds-text1']....., and i have another file called biorythim.php which is another example and there's also some $TEXT values like ['bio-head'], ['bio-ok'].

I used to program in ASP and there were session variables, im wondering if $TEXT is something like that .

anyways thanks for the help.



#8 Fehnris

Fehnris
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 01 October 2006 - 06:36 AM

Yeah very possibly part of the superglobal or session variables.  PHP has both of these although to have PHP automatically register superglobals you need to either be running a version of PHP less than 4.3 something.  Any version above that you have to enable the automatic registering as a setting in your config file. 

You could check to see what version of PHP you are running and also how your register superglobals option is set.  If its enabled then quite possibly these variables are session/superglobal variables.

#9 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 01 October 2006 - 10:03 AM

Is there an include (or require) statement at top of script somewhere that you haven't posted here?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#10 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 01 October 2006 - 12:43 PM

Let's try to clear up one minor mystery:

now, my specific question is what is :
=$TEXT['cds-head']
=$TEXT['cds-text1']
=$TEXT['cds-text2']


The answer is you misinterpreted the code.  An example complete line is:

<?=$TEXT['cds-text1']?><p>

It is equivalent to:

<?php echo $TEXT['cds-text1']; ?><p>

<?= only works to display stuff if your set-up has 'short tags enabled'. Don't rely on that being true on other servers.

$TEXT is an array - where it came from we don't know.  My guess is that it's the array obtained from a database query statement and holds the value that's in a field named cds-text1
Legend has it that reading the manual never killed anyone.
My site

#11 janroger

janroger
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 09 March 2007 - 06:58 PM

Here is the answer to this question:
Its not that easy to see at first.  In XAMPP, the file that contains all the TEXT[] -elements is located in your xampplite\htdocs\xampp\lang -folder. If you run english, the filename would be en.php.  This en.php is included in a file named langsettings.php, which is included in the cds.php you are referring to.

      refers to              refers to
cds.php -> langsettings.php -> en.php

Regards
Jan-Roger

#12 AndyW

AndyW
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 10 August 2009 - 11:08 AM

Thank you! I'm brand new to PHP and had exactly the same question.  :facewall:
Andy




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users