rpmorrow
Members-
Posts
27 -
Joined
-
Last visited
Never
Everything posted by rpmorrow
-
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.
-
Using a HTML template with includes can't read from $_GET
rpmorrow replied to rpmorrow's topic in PHP Coding Help
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. -
Using a HTML template with includes can't read from $_GET
rpmorrow replied to rpmorrow's topic in PHP Coding Help
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; -
Using a HTML template with includes can't read from $_GET
rpmorrow replied to rpmorrow's topic in PHP Coding Help
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? -
Using a HTML template with includes can't read from $_GET
rpmorrow replied to rpmorrow's topic in PHP Coding Help
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'); ?> -
Using a HTML template with includes can't read from $_GET
rpmorrow replied to rpmorrow's topic in PHP Coding Help
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 -
Using a HTML template with includes can't read from $_GET
rpmorrow replied to rpmorrow's topic in PHP Coding Help
Maybe, but I don't see how that solves my problem. -
Using a HTML template with includes can't read from $_GET
rpmorrow replied to rpmorrow's topic in PHP Coding Help
So.. any ideas..? :'( -
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>"; } ?>
-
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.
-
Using a HTML template with includes can't read from $_GET
rpmorrow replied to rpmorrow's topic in PHP Coding Help
Yes you can! Just adding "AddType x-mapp-php5 .html .htm" to the .htaccess file does it. -
Using a HTML template with includes can't read from $_GET
rpmorrow posted a topic in PHP Coding Help
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? -
dropdown menu for select different table
rpmorrow replied to vaskovasilev's topic in PHP Coding Help
Your query needs to use $_POST['dropdown'] instead of $dropdown -
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?
-
Organising hierarchical data in an array (using foreach?)
rpmorrow replied to rpmorrow's topic in PHP Coding Help
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 -
Organising hierarchical data in an array (using foreach?)
rpmorrow replied to rpmorrow's topic in PHP Coding Help
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. -
Organising hierarchical data in an array (using foreach?)
rpmorrow replied to rpmorrow's topic in PHP Coding Help
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 -
$openPos = strpos($filename, "["); $closePos= strrpos($filename, "]", $openPos); $hits = substr($filename, $openPos, $closePos - $openPos)
-
Organising hierarchical data in an array (using foreach?)
rpmorrow posted a topic in PHP Coding Help
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? -
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
-
SELECT * FROM DatabaseName WHERE location = 'spain' AND language = 'spanish' AND age >= '16' AND age <= '20';
-
help limiting number of characters pulled from database
rpmorrow replied to RyanSF07's topic in PHP Coding Help
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); } -
Making a menu from an array of URL's in a DB
rpmorrow replied to rpmorrow's topic in PHP Coding Help
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? -
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