Jump to content

questions about syntax and structure


dglp

Recommended Posts

I'm trying to learn about PHP in order to pull data from several sources and present it in a special kind of layout. At the moment I am stumped by two things. One is the meaning of 'global' in the following lines:

<?php function select()  {  global $a;  global $showrecs;  global $page;}?>

Is it just a variable name assigned by the author, or is it a specific bit of PHP syntax in the same way that 'function' is a bit of syntax? I've looked high & low for an explanation.The other thing is a more important matter, and has to do with getting bits of PHP to run within DIV containers on my page. For example, on given page of data I get a table row. But when I put some of the code in a DIV, it produces no output. I'm guessing that the PHP 'blocks' don't like being separated this way, even though there is other HTML code between the blocks. My question about this is very broad: where do I find out how to display data in different containers on my page? I have 30 columns in my table/database, but I want some displayed in each corner, some in the middle, etc.

Link to comment
Share on other sites

In a plain script (one with no functions) all variables are global, even if the file is partitioned into many "microscripts."When a script is broken into functions, variables declared outside a function are normally invisible to the function, and variables declared inside the function are invisble outside.If a variable is declared global (with that keyword) it can be visible inside a function (or inside another function) as long as that function likewise declares it global. Really, the best way to learn about scope is to write a test script with a couple of functions and then just play with the declarations, inside and out.A link to the manual: http://us2.php.net/manual/en/language.variables.scope.phpOn the question of mixing php with HTML, there is a lot of flexibility as to what works and what doesn't. You might check the manual on that too. We could comment on something specific if you pasted some code, but the manual might clear it up first. I'll give you a hint to get started. The following structure is legal:

 <?php if ($myVar == 2){ ?>   <div><p>Hello</p></div><?php } ?>

The result is that if $myVar == 2, the hello div gets printed; if not, it doesn't get printed. Yes, it could be done with an echo, but you could also put hundreds of lines of html in that conditional. Cool, huh?To clarify: php is a server-side language. It doesn't run "within" a div, but it can be used at page-download time to determine whether a div gets printed, what it looks like, what it holds, etc. Once the page is on its way to the browser, php is done with it, the script has stopped running, and the end user can't even see the php code, much less run it.As to display, better start reading about CSS.In fact, it sounds like you have a lot of reading to do. :)

Link to comment
Share on other sites

Thank you for all this. I feel like I've hit the jackpot, so to speak.I did the CSS first, some time ago, and am now trying to fit the PHP to it. I knew what layout I wanted, but not how I was going to get my data into it. Of all the things you wrote, one thing makes a big difference: that the PHP doesn't run 'within' the blocks of HTML. I've read a bunch of introductions to PHP, most of which make some mention of server side stuff. But it doesn't really mean anything until it's set in the context of a particular process, such as loading the page I'm working on. That brings home the concept in a much clearer way!I will do some more reading at the manual you linked to. I will also post a more detailed example of something I want to do. But first I have a meeting to attend!thanks again

Link to comment
Share on other sites

I have pasted an entire page layout below. I want it to display four things:

  • a data record from a MySQL table
  • images from local files
  • map (probably through an API link)
  • static text and graphics

I am currently trying to understand how PHP retrieves data, and how to position that data on the page. I have some rudimentary ideas, but not enough to do more than a simple table.You will see that I have several containers, each of which displays some of the MySQL data. There are no forms, nor does the data need to change dynamically. I've set aside the CSS stuff for now, and just done a simple HTML layout. So it seems like a pretty straightforward task - once I understand the basics.If this clarifies things and you can make further suggestions, I'm all ears! Well, mostly. :) dp

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>detail page</title></head><body style="font-family:Verdana; font-size:12;"><B><span style="font-size:26pt;">Mapping Project</span></B><div id="navigation1" style="width:513px; height:37px; position:absolute; left:536px; top:15px; z-index:1;"><p align="right"> <a href="http://">Home</a> |<a href="http://">Project</a>| <a href="http://">List</a> |<a href="http://">Search</a> |<a href="http://">Feedback</a></p></div><div id="ID" style="width:180px; height:80px; position:absolute; left:536px; top:70px; z-index:1;"><B>Point Number: 22</B><br><B>Date: 24/02/2007</B><br><B>Team: 1</B><br></div><div id="mapping" style="width:300px; height:438px; position:absolute; left:750px; top:70px; z-index:1;"><img src="../images/map.jpg" width="300" height="300" border="0"><br><B>Area:</B> 3<br><B>100m Grid:</B> 400300<br><B>Grid Ref:</B> SP 0680082200<br><B>Latitude:</B> 52.437673<br><B>Longitude:</B> -1.901547<br><B>Link:</B><a href="http://maps.google.co.uk/maps?q=52.4381994191202%2C-1.90210399514833">Google</a></div><div id="names" style="width:500px; height:80px; position:absolute; left:10px; top:70px; z-index:1;"><B><span style="font-size:18pt;">Event:</span></B><span style="font-size:18pt;"><br><i>sequence:</i></span></div><div id="info" style="width:500px; height:220px; position:absolute; left:10px; top:180px; z-index:1;"><B>About this event:</B><br> "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquamlacinia massa eget ligula. Integer elementum rutrum ipsum. Suspendissepotenti. Donec posuere nibh id magna. Phasellus a magna. Fusce semper.Vestibulum tortor enim, tincidunt sit amet, tincidunt sit amet, blanditet, justo. Aliquam tortor est, varius tristique, volutpat a, imperdietporta, risus. Aliquam pharetra orci quis justo. Proin fringilla, neque neclaoreet euismod, orci orci fringilla est, eu dictum arcu lorem venenatismauris. Fusce orci. Maecenas velit lectus, consectetuer interdum, viverralaoreet, tristique quis, nisl. Nam ut diam."[<a href="http://www.lipsum.com/">Lorem Ipsum</a>]</div><div id="character" style="width:180px; height:435px; position:absolute; left:536px; top:180px; z-index:1;"><B>East_NSIH:</B><br><B>North_NSI:</B><br><B>Easting:</B><br><B>Northing:</B><br><B>SeriesName:</B><br><B>Landuse:</B><br><B>Slope:</B><br><B>Slopeform:</B><br><B>MadeGround:</B><br><B>Outcrop:</B><br><B>Alt:</B><br><B>Aspect:</B><br><B>Erosion:</B><br><B>Deposition:</B><br><B>Rocktype:</B><br></div><div id="further" style="width:299px; height:131px; position:absolute; left:750px; top:519px; z-index:1;"><p><B>Further Info:</B></p></div><div id="photo" style="width:500px; height:234px; position:absolute; left:10px; top:416px; z-index:1;"><B>Photos</B> <div id="north" style="width:234px; height:188px; position:absolute; left:10px; top:36px; z-index:1;"><img src="../images/north.jpg" width="111" height="32" border="0" align="top" vspace="2" hspace="1" alt="north view"></div><div id="east" style="width:234px; height:188px; position:absolute; left:250px; top:35px; z-index:1;"><img src="../images/east.jpg" width="114" height="32" border="0" vspace="2" hspace="1" alt="east view"></div></div></body></html>

Link to comment
Share on other sites

So far it looks pretty good. I'm guessing your resolution is set at 1152 or 1280; mine (like a lot of people's) is set at 1024, so a chunk of your content is scrolling off to the right. That can be addressed with floats or just by wrapping everything in a big div and centering it.I think you're next step is to move all those style declarations out of your tags and into a true CSS sheet. FWIW, I find it easier to design with my stylesheet in the same document as my html; that way I'm not going back and forth between docs. When I'm pretty much done I move it into a separate file and then link it.And I gather you want to pull the real data out of SQL; what I'm seeing now was dropped in by hand for the prototype, but what you're going toward is php grabbing it from sql and putting it into the document dynamically, yes.So I guess you need to know what the structure of your sql tables are, what the names of things are, etc. Then you can start working with it? Or are you designing your database at this moment too? That would be best, because then the static text and URLs to your images and maps can all be stored together. (Unless they're already there, in which case you're in great shape.)For now I'll refer you here: http://www.w3schools.com/sql/default.asp . You might also want to search through the SQL forum here and just look at some code in action. You seem pretty sharp; imitation goes a long way for us sharp types. :)

Link to comment
Share on other sites

So far it looks pretty good. I'm guessing your resolution is set at 1152 or 1280; mine (like a lot of people's) is set at 1024, so a chunk of your content is scrolling off to the right. That can be addressed with floats or just by wrapping everything in a big div and centering it.
Now that I think about it, yes, the containers are set out across 1050 pixels. I do work at 1280x1024, and sometimes forget that my real estate is wider than average. It won't be a problem to rearrange things for a narrower display.
I think your next step is to move all those style declarations out of your tags and into a true CSS sheet.
You mean the style declarations within the DIVs, right? While I ultimately agree with you, I figure I can move those once I've got the other stuff working. Does it make any difference whether it's sooner or later?
And I gather you want to pull the real data out of SQL; what I'm seeing now was dropped in by hand for the prototype, but what you're going toward is php grabbing it from sql and putting it into the document dynamically, yes.
Yes, that's my main concern at the moment. I don't know enough about either MySQL or PHP to make it work. I've been reading books and online explanations for a week and am now more confused than I was initially! (Although I now know a bit more about what the 'global' keyword is about.) Making my way through the volumes of text and explanation means that I'm trying to digest far more than I 'need' to know for completing the initial task I've set myself. I am getting the idea that I may only need something like a FETCH command to do most of what I'm after. But I have had to go through reams of other stuff before coming to that conclusion.
So I guess you need to know what the structure of your sql tables are, what the names of things are, etc.
I know some or all of that already. I have some samples set up here. This is produced on a script generator.
Then you can start working with it?
Yes.
Or are you designing your database at this moment too?
Yes, that too! :mellow:I am working from a small sample. Once I get that working I will extrapolate to something bigger.
That would be best, because then the static text and URLs to your images and maps can all be stored together. (Unless they're already there, in which case you're in great shape.)
I'm pretty much there too. But I keep the 'sitegraphics' and style elements separate from the 'image data' (photos associated with a specific record).
For now I'll refer you here: http://www.w3schools.com/sql/default.asp. You might also want to search through the SQL forum here and just look at some code in action. You seem pretty sharp; imitation goes a long way for us sharp types. :)
Just sharp enough to ask other people questions! :) But yes, imitation works for me, as does taking apart something that works. You can see an example of how I've gutted the generated script here.The main thing with exploring other people's scripts are that variables are frequently difficult to understand, so I don't know which bits are doing something I don't need. Some combination of taking things apart and putting my own together works well for me!
Link to comment
Share on other sites

Yeah, you can move the style stuff any time. Was there another question? We've dealt with the things the thread started with, so I'm thinking if you want to get the SQL folks involved, maybe post a new question there. If you're ready to, I mean.

Link to comment
Share on other sites

My guess is that I need to spend more time on PHP, learning to manipulate things from the database and other sources. SQL will be part of it, but I want to think more about the overall process first.You are right that my initial questions have been answered. (And thank you for the assistance!)I have figured out how to position the selected data in a container, and have a general idea of what a global does. My next task is to continue getting a grip on the ways PHP requests data, so that I can simplify that process and apply it to photographs and a Google map. I also need to think about page navigation. I'll be looking for examples of how those things get done. But first priority seems to be developing a clearer understanding of 'what's legal' in setting out the code, getting a sense of the order in which things need to get done. Thanks again for your guidance. It's made things a lot more straightforward for me.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...