Jump to content

rpmorrow

Members
  • Posts

    27
  • Joined

  • Last visited

    Never

Everything posted by rpmorrow

  1. Rather than counting characters from your occurrence of "Neighborhood:", use a combination of strpos and substr to find the position of the next font tag and then insert what you need using preg_replace, or str_replace.
  2. Thank you very much. It's all working great and my code is much simpler I had a look around about the buffering, it all looks quite interesting. I'm sure I will be using it more in future. Thanks again.
  3. Cool, that seems to be working! $_GET is working too!! To do the replacing repeatedly, I'm doing the following, its working but it feels so strange to do it like this (I never even heard of buffering the output like this b4 now). Is it ok? $output = preg_replace("/~~FIRSTTHING~~/",$row['first'],ob_get_clean(),1); $output = preg_replace("/~~SECONDTHING~~/",$row['second'],$output,1); $output = preg_replace("/~~THIRDTHING~~/",$row['third'],$output,1); echo $output; $output = preg_replace("/~~LASTTHING~~/",$row['last'],ob_get_clean(),1); echo $output;
  4. If I'm using file_get_contents(), it does not parse the PHP code, so when I go view-source, it looks as below. I've put the various code segments below. Example of template code (I've removed all the html header etc for simplicity): <div id="content"> <div id="leftColumn"> ~~LEFTMENU~~ <? include_once($_SERVER['DOCUMENT_ROOT'].'/includes/box-left.inc.php'); ?> </div> <div id="rightColumn"> <? include_once($_SERVER['DOCUMENT_ROOT'].'/includes/box-right.inc.php'); ?> </div> ~~PAGECONTENT~~ <? include_once($_SERVER['DOCUMENT_ROOT'].'/includes/searchresult.inc.php'); ?> </div> <div id="footer"> <? include_once($_SERVER['DOCUMENT_ROOT'].'/includes/footer.inc.php'); ?> </div> /includes/searchresult.inc.php <? $searchQuery = $_GET['q']; echo $searchQuery; //was empty ?> The code to replace ~~PAGECONTENT~~ etc is in functions.inc.php (simplified) <? function DisplayPage($page_id, $page_type) { //the two variables here are used to select the right info from database, and which template to use $template_html = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/templates/home-template.htm'); $parsed_html = preg_replace("/~~PAGECONTENT~~/",$row['page_content'],$template_html,1); echo $parsed_html; ?> The file visited by the user www.example.com/search.php?q=something <? include_once('includes/functions.inc.php'); DisplayPage("Search", "search"); //page_id, page_type ?> P.S. I'm using the code button in the forum, but it is not colouring the php for u, I need add something else?
  5. Thanks, I had tried using that but the includes in the template stop working. I'm calling them in the template as follows.. <? include_once($_SERVER['DOCUMENT_ROOT'].'/includes/menu-top.inc.php'); ?>
  6. I am using curl because I need to str_replace data in the template. I didn't know it would be slow.. hmm, maybe i should look at another approach for this
  7. You need to make a while loop that generates the html table rows. Example... <?php while ($row = mysql_fetch_assoc($result) ) { echo "<tr><td>".$row['name']."</td></tr>"; } ?>
  8. 1. Yes, FALSE is fine, or you could have NULL or... return ""; They are equivalent, but are NOT identical. (See if ===) 2. you can have return multiple times in a function because only one of them can ever call at once. As soon as whatever conditions you set executes the first "return" then the function is finished and any others are irrelevant at that time.
  9. Yes you can! Just adding "AddType x-mapp-php5 .html .htm" to the .htaccess file does it.
  10. I am trying to make a site with content in databases and using some template html files for the layout. The problem I am having is that the code is executing in the template directory and can't therefore read the value from any $_GET that is on the url used by the user. I hope you can understand my meaning. Let me give an example of the structure.. The user visits "www.example.com/search.php?q=something" The file "search .php" just contains a function call to display the page; e.g. DisplayPage("search"); The DisplayPage function uses CURL to read the contents of a HTML file (/templates/search-template.htm) into a string. It then uses preg_replace and str_replace to replace some markers that are in the template, with data from the database. At the end of the function it simply echoes the string. The template files contain some includes, which work fine, but the code executing within them "thinks" it is being executed from /templates/search-template.htm rather than /search.php. Therefore if I use $_GET['q'] in any of those includes, it is empty. I hope that makes sense! Is there any way for me to make the executing code work as if it is being executed from "/search.php" rather than the template?
  11. Hi, I try to execute the code below but I get the error "Cannot instantiate non-existent class: mysqli" so I assume it is not supported by my host. Is there an equivalent command I can use? (php5 not supported either) $dbh = new mysqli($db_host,$db_user,$db_pass,$db_name);
  12. Your query needs to use $_POST['dropdown'] instead of $dropdown
  13. Hi, I'm trying to create a menu such as an unordered list based on info in a single SQL table. I've seen examples of using LEFT OUTER JOIN to do it, but this seems to involve multiple tables and I just get an error if I try it with one table. The columns are as follows; id parent_id title 1 0 Some words 2 0 Some words2 3 2 Some words3 4 2 Some words4 5 3 Some words5 I want it to return the following; Some words Some words2 Some words3 Some words5 Some words4 Can anyone point me to an example?
  14. erm... If It shouldn't be used, and the code does not work anyway, then it only serves an an example of how NOT to do it. Thanks anyway
  15. Thanks! I'm pretty new to the OO stuff, but that looks good. Unfortunatley I'm getting a parse error.... Parse error: syntax error, unexpected T_CLASS ... refering to the line starting with abstract class MenuComponent { I can't see any missing parentheses or semicolons. Any ideas why I'd get the error? EDIT: In fact, if I delete all code before that point, I still get the error.
  16. It is for creating a menu (each row represents an item in the menu). "parent_id" contains a value representing the "id" of the menu level above that row. Anything with a "parent_id" of 0 is a top level item. id=9 is a sublevel of id=10 id=7 and id=8 are sublevels of id=9 I missed a digit from the ouptut in my first post It should be; The output should look like this 1 6 10 9 7 8
  17. $openPos = strpos($filename, "["); $closePos= strrpos($filename, "]", $openPos); $hits = substr($filename, $openPos, $closePos - $openPos)
  18. Hi, I have a DB table with the following columns [id] [parent_id] 1 0 6 0 7 9 8 9 9 10 10 0 I want to read from the DB and output it like a hierarchical structure. I keep trying with arrays and foreach loops but am failing. There is just some logic I'm overlooking I think. The output should look like this 1 6 10 9 7 Can anyone help me please?
  19. You need to add some code to the login script which stores the current timestamp in the DB or in a session variable. e.g. $_SESSION['loginTime'] = time(); Then the logout script should get the time again and subtract the previous number. This would give you the time in seconds for that session. You would then need to add the code for adding previous times from the DB
  20. SELECT * FROM DatabaseName WHERE location = 'spain' AND language = 'spanish' AND age >= '16' AND age <= '20';
  21. You are trying to test and trim your empty variable. Use this instead.. $assign = row2['assignment_number']; if(strlen($assign)>50){ echo substr($assign, 0, 50); }
  22. The info is in a database. Each row has the following data. "id", "parent_id", "title", "url", "content" "id" is a unique numerical key "parent_id" is the page 'above' this one There could be any number of parents and children as the site content would change over time (hence the need for a dynamic menu). I'm sure it is not too tricky, I just seem to be suffering from a mental logic block Does this make sense?
  23. Hi, I'm wanting to make an <ul> type menu based on info in a database. Each DB entry has a page URL, and page title among other info. I somehow need to loop through the database and fill some arrays in a way that structures the urls for a menu. The menu structure would be the same as the directory structure. For example; Level One Index (index.htm) SubLevel One (somepage.htm) SubLevel Two (someotherpage.htm) SubLevel Three Index (/sub/index.htm) SubLevel One (/sub/somepage.htm) Can I sort data in PHP by its path depth, or do I need to count slashes? I feel a bit confuse at where to start Cheers
×
×
  • 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.