Jump to content

brian914

Members
  • Posts

    32
  • Joined

  • Last visited

    Never

Everything posted by brian914

  1. I am building a php site and would like to keep all my page titles, copy, and certain image references inside a json file, so I can edit that info more easily and have it all in one place. I know how to load the json, but am wondering if there was a way to load it where it would only load once and then be stored in a variable that was available from any page. Maybe load it front he header include and store it in a session variable? I am pretty new to php, so hoping for some advice on how to do this best. Thanks a lot!
  2. Okay great. That is even better than what I thought it could be then! Thank you very very much! This is really nice of you to take all this time to answer my questions!
  3. Wow, amazing! Thank you so much Josh! I so very much appreciate the help! I have one last question in regards to your last comment: "This is common in for instance shared hosting environments, where multiple people share the same server." I guess I am a little bit worried about this, as in my experience, a lot of servers do share. So I was hoping to create a place where I could set a variable referring to "my root". I would like to do this, so if all of a sudden, when I move this to the actual server, or a different server, I could just set the "root" in one place, instead of having to go through all my code and look for the "$_SERVER['DOCUMENT_ROOT'].'/" and make the adjustment in many places. I was hoping there was something I could set in one place, like so: $my_root = $_SERVER['DOCUMENT_ROOT'] . '/somedirectory/'; Then I could use $my_root the rest of the time, instead of $_SERVER['DOCUMENT_ROOT']. But not sure if that is possible and not sure where that would reside? Maybe this is a pipe dream...
  4. Thank you so much for the help everyone! I really like the second solution for its simplicity and am wondering how I can apply that to include tags, which I can't seem to make work yet. While this seems to work: <img src="/img/home/home-04.jpg" alt="Home Image"> This doesn't work: <?php include '/inc/head.php'; ?> I have includes inside other includes files, so they still would all have to know where the "root" is. Thanks a lot!
  5. I am pretty new to php, so I apologize if this is a stupid question. I am building a web site and have include files that get used from the root and different sub directories within my site. For example I have a header include that gets used from files both on the root level and inside directories. Inside that header I need to for example call a style sheet. I am trying to do this like this: <link rel="stylesheet" href="<?php echo $_SERVER['DOCUMENT_ROOT']; ?>/css/style.css"> If I look at the source that this generates, here is what it looks like which is the correct path I think: <link rel="stylesheet" href="/Users/brian/Documents/Client Name/6_WebFiles/css/style.css"> But somehow the stylesheet does not seem to work. What am I doing wrong here? Thanks a lot for help!
  6. Could this be a permissions issue? And if so, what should it be and how do I set it?
  7. Thanks a lot for the suggestion! I don't really know what I am doing... But I have created a virtual host now and I like this for a number of reasons already. Is the following the correct way to refer to my style sheet? Somehow it is not quite working yet, and I wonder if it might be from the space in client name? Here is how I am calling the style sheet: <link rel="stylesheet" href="<?php echo $_SERVER['DOCUMENT_ROOT']; ?>/css/style.css"> If I look at the source, here is what it looks like which is the correct path: (I changed the client name, but it is two works just like below) <link rel="stylesheet" href="/Users/brian/Documents/Client Name/6_WebFiles/css/style.css"> Why wouldn't this pull in the style sheet?
  8. I am running MAMP and have a number of directories with different sites in my /Applications/MAMP/htdocs directory. The problem I am having is that inside one of those projects, I have a header file that gets included in pages that reside in different directories. So they need different paths for example for the style.css file. For example, from one file that path would be ../css/style.css but from another file inside another directory it would be ../../css/style.css. My question is if there is a way to set a "root" path for this projects, so I can use something like $root_dir . /css/style.css and it would always work, regardless of where in the site structure I am calling it from. Something similar to what wordpress does with TEMPLATEPATH.
  9. I am trying to figure out how to have an if statement in the middle of strings I am trying to concatenate. I have a from that has a address1 and address2, where address2 often does not exist. So I want to only add that line if there is actually content. I was trying something like the following, but that is giving me an error. I am pretty new to php, so I can't seem figure it out. Any help would be greatly appreciated. "<p><strong>Address 1: </strong><br>" . $address1 . "<br>" if ( isset($address2) ) { echo . $address2 . "<br>" } . $city . ", " . $state . " " . $zip . "</p>"
  10. Yes, thank you. That I think is all I need!!!
  11. I am about to build a site for a liqueur brand and have to create a simple screen that asks if the user is of the right age. This does not have to be linked to a credit card, just a simple yes or no screen. I am thinking this would probably be done via a cookie, but I am not sure. Somehow it would have to work where it gets checked each time anyone goes to the site, regardless of the entry point. So for example it would get checked on mydomain.com, but also on mydomain.com/about, or mydomain.com/somethingelse. The yes or no screen would of course only show the first time the user came to site. Via what technology would I do this? Cookie? Can cookies have an expiration date? I would love some comments or direction on how this is done best. Thanks a lot!
  12. I have the following function, which takes a string with commas in it and attempts remove those commas. The way I have it here is that I use explode to take out the commas, which makes an array, and then iterate through that array to put a string back together without the commas. function tags_to_sort_by( $sortMeta ) { $sortByArray = explode(",", $sortMeta); $sortByCount = count($sortByArray); for ($i = 0; $i < $sortByCount; $i++) { $sortByString += $sortByArray[$i]; } return $sortByString; } What does not work is the following line: $sortByString += $sortByArray[$i]; Somehow that outputs a 0, which I don't understand. It should output something like: arrayItem1 arrayItem2 array3 etc. My question is if there either is an easier way to remove the commas from the original string or what I am doing wrong in this line: $sortByString += $sortByArray[$i]; // I am trying to concatenate each part of the array back into the string. Thanks a lot for help with this!
  13. That gives me the following error. Fatal error: Call to undefined function: php�echo�() in /home/content/s/w/1/sw1tchbl4de/html/stage/v1/sidenav_bios.php on line 2
  14. I pretty much know no php, but am redesigning a site that was built in php. The php on the site is super simple and I am trying to add to it a little bit. All the pages in this site have their own page, meaning my about page has an about.php, home has index.php, etc. I am trying to set my navigation so when I am on that page for the navigation to show the page you are on. So, I would like to do something like this: On each of the pages, I would set my page variable just before the include tag of the navigation, something like this: <?php $thisPage = 'deathValley'; ?> Then in the navigation php file, I would test for my page like so? But I guess you can't use html with php like that? How would I write this? <?php <ul> <li> {if mypageVariable == deathValley} <a id="uberlink2" href="#">DeathValley</a> {if:else} <a href="bio_deathvalley.php">DeathValley</a> {/if} </li> </ul> ?> Also, is there a way to test for the url of the page, or something else? That way I would not have to set the variable on each page? Thanks a lot for any help with this!
  15. I tried the above and it did not work. The error I get is: Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1' at line 1
  16. I have the following and it gives me an error. function get_subject_by_id($subject_id) { global $connection; $query = "SELECT * "; $query .= "FROM subjects "; $query .= "WHERE id=" . $subject_id ." "; $query .= "LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); if($subject = mysql_fetch_array($result_set)) { return $subject; } else { return NULL; } } If I comment out the following line, it no longer gives me the error. But it also does not do what it needs to $query .= "WHERE id=" . $subject_id ." "; I am getting this from a tutorial, so it seems like I have everything. What am I missing? Thanks a lot for any help!
  17. OMG, that was it!!!! <?php instead of <? Sorry, I am so lame. I just could not find that and don't know enough to figure it out! Thank you so much for your help!!!
  18. Haha, I need very basic, so offense taken. 1: Have you created a database? Yes, it is called "widget_corp" 2: If you have. Make sure that you're connecting to the database and not the table. How do I do this? I thought that is what we were doing above? 3: Usually mysql on your computer doesn't have a password, unless you set one yourself. Did you set one? Part of the tutorial I am doing was setting up a password via the commend line. So, yes, I do have a password. Thank you!
  19. Still nothing. So what does that mean? I am not connecting? Thanks so much for your help! Brian
  20. Yeah, the title changes to Basic, but that is all that changes. <? $connection = mysql_connect("localhost","root","Otl_PHP07"); $select_db = mysql_query("widget_corp"); if(!$select_db){ echo "Could not select database"; } ?> <html> <head> <title>Basic</title> </head> <body> </body> </html>
  21. I tried this. <? $connection = mysql_connect("localhost","root","Otl_PHP07"); $select_db = mysql_query("use databasename"); if(!$select_db){ echo "Could not select database"; } ?> <html> <head> <title>Basic</title> </head> <body> </body> </html> It loads the file, but nothing happens. Do I have something in my html? Thanks a lot!!!
  22. It is local, but I am wondering if it might be named different? I noticed that in a previous tutorial, when looking at cookies, in the list mine was named a bit different then in the tutorial, where it was called "localhost". How can I find that out?
×
×
  • 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.