coljung Posted September 28, 2006 Share Posted September 28, 2006 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> <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. ??? Quote Link to comment https://forums.phpfreaks.com/topic/22321-code-question/ Share on other sites More sharing options...
pedrobcabral Posted September 28, 2006 Share Posted September 28, 2006 That is arrays, do this code on a "test.php" to try to understand[code]<?php$test = array("onething","twothings","treethings");echo "<pre>";print_r($test); echo $test[1];?>[/code]And check out this link: http://www.tizag.com/phpT/arrays.php Quote Link to comment https://forums.phpfreaks.com/topic/22321-code-question/#findComment-99978 Share on other sites More sharing options...
AndyB Posted September 28, 2006 Share Posted September 28, 2006 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 serverselect a database.. and what's completely missing in your exampleselect some data from a specific database tabledisplay the data Quote Link to comment https://forums.phpfreaks.com/topic/22321-code-question/#findComment-99982 Share on other sites More sharing options...
coljung Posted September 28, 2006 Author Share Posted September 28, 2006 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 exampleis cds-head part of the database ?where was the info added into the array ? Quote Link to comment https://forums.phpfreaks.com/topic/22321-code-question/#findComment-99994 Share on other sites More sharing options...
Fehnris Posted September 28, 2006 Share Posted September 28, 2006 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 Link to comment https://forums.phpfreaks.com/topic/22321-code-question/#findComment-100079 Share on other sites More sharing options...
Cell0518 Posted September 28, 2006 Share Posted September 28, 2006 What package did you install? This would give us a way to see ALL of the code.Thanks,Chris Quote Link to comment https://forums.phpfreaks.com/topic/22321-code-question/#findComment-100081 Share on other sites More sharing options...
coljung Posted September 28, 2006 Author Share Posted September 28, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/22321-code-question/#findComment-100552 Share on other sites More sharing options...
Fehnris Posted October 1, 2006 Share Posted October 1, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/22321-code-question/#findComment-101699 Share on other sites More sharing options...
Barand Posted October 1, 2006 Share Posted October 1, 2006 Is there an include (or require) statement at top of script somewhere that you haven't posted here? Quote Link to comment https://forums.phpfreaks.com/topic/22321-code-question/#findComment-101765 Share on other sites More sharing options...
AndyB Posted October 1, 2006 Share Posted October 1, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/22321-code-question/#findComment-101785 Share on other sites More sharing options...
janroger Posted March 9, 2007 Share Posted March 9, 2007 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 tocds.php -> langsettings.php -> en.phpRegardsJan-Roger Quote Link to comment https://forums.phpfreaks.com/topic/22321-code-question/#findComment-203689 Share on other sites More sharing options...
AndyW Posted August 10, 2009 Share Posted August 10, 2009 Thank you! I'm brand new to PHP and had exactly the same question. Andy Quote Link to comment https://forums.phpfreaks.com/topic/22321-code-question/#findComment-894702 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.