Jump to content

Code Question.


coljung

Recommended Posts

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:
[code]<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>

[/code]

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

i know that i retrieve the info from the database through [b]mysql_select_db("cdcol");[/b]

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

the page looks like this : 
[img]http://img147.imageshack.us/img147/3663/questionphpbp6.jpg[/img]

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.

???
Link to comment
Share on other sites

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
Link to comment
Share on other sites

thanks for the fast replies.

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

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 [i]'cds-head'[/i] shows as [i]CD Collection (Example for PHP+MySQL+PDF Class)[/i] for example

is cds-head part of the database ?
where was the info added into the array ?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

i installed xampp.

[quote]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.[/quote]

The screen grab is what results from the code.

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

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.

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

Let's try to clear up one minor mystery:

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

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

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

It is equivalent to:

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

<?= 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
Link to comment
Share on other sites

  • 5 months later...
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
Link to comment
Share on other sites

  • 2 years later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.