| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Member Join Date: Nov 2005
Posts: 66
![]() | PHP Problems Hello, On my site, it consists of a few PHP scripts. This is how it works: Loads functions.php Loads a php include, which contains a function that functions.php needs to process. However, within that function contains another variable, which another script needs to process (done afterwards). The problem is, since the function requested the processing of functions.php, but the variable inside the function has not yet loaded, it does not work properly. Ill try and make it more simple: ????: NamePros.com http://www.namepros.com/programming/213670-php-problems.html <?php include functions.php ?> (Function contains $id function processing) <?php include content.php ?> Content.php contains $id=$value. Function needs to process $id, but $value still has not been processed yet, therefore it does not work properly. Later in content.php it processes the value, but it has already asked functions to process the id, therefore the value is still unknown. I've tried ob_start, but it doesnt work. Any ideas? Thanks |
| |
| | #2 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,069
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | ob_start only stops output being sent to the browser. If a function requires a variable and that variable is not available yet then you shouldn't be calling it. Why are you calling it before you are ready? |
| |
| | THREAD STARTER #3 (permalink) |
| NamePros Member Join Date: Nov 2005
Posts: 66
![]() | Thats why i am asking how do you delay calling it? Actually i am not entirely sure if its the function that's not ready, or mysql playing tricks on me. If you set the variable down, function abc(x) , the mysql statment: $query=mysql_query("SELECT total_votes, total_value, used_ips FROM ratings WHERE id=x ")or die(" Error: ".mysql_error()); works fine. However, if you put a variable in, (function abc($x); ), the mysql statement $query=mysql_query("SELECT total_votes, total_value, used_ips FROM ratings WHERE id='$x' ")or die(" Error: ".mysql_error()); doesnt work. However later on in the script, you ask it to <?php echo $x ?>, $x echos. Does anyone have any ideas? |
| |
| | #4 (permalink) |
| Buy my domains. Join Date: Feb 2006
Posts: 2,796
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Uh.. function abc(x) wouldn't do anything and probably give you an error. function abc($x) is correct and does not add quotes unless the quotes are in the variable and it should work. I'm still not completely sure what you are doing and what you are trying to do.. |
| |
| | THREAD STARTER #5 (permalink) |
| NamePros Member Join Date: Nov 2005
Posts: 66
![]() | Well here is whats happening: If i have <?php abc('1') ?> run through the CMS it works if i have <?php abc('$x') ?> run through the CMS, it Doesnt Work it has a $output = str_replace("$x", "news_arr[0]", "$output"); in the script which replaces the $x, but the function has already been called, and it is sending $x without the processed variable. Therefore, i need a way to delay the function, even when it is called. Okay this is the script: Functions.php: PHP Code: PHP Code: PHP Code:
Last edited by nigelwong; 07-05-2006 at 10:27 PM.
|
| |
| | #7 (permalink) |
| Senior Member Join Date: Nov 2005 Location: on a oil rig just off Ireland
Posts: 1,408
![]() ![]() ![]() ![]() ![]() | <?php abc('$x') ?> won't work. Try <?php abc("$x") ?> or <?php abc($x) ?>.
__________________ You design in photoshop, I code into valid XHTML/CSS. Professional PSD, PNG or HTML to tableless XHTML/CSS designs. For more info, send me a PM. |
| |
| | #9 (permalink) | ||||
| NamePros Member Join Date: Mar 2006 Location: USA - RI
Posts: 49
![]() |
A global command tells the function that the variable you set inside the function should be available to the rest of the script. PHP Code: The below code would not ????: NamePros.com http://www.namepros.com/showthread.php?t=213670 PHP Code: Hope that helps. | ||||
| |
| | THREAD STARTER #10 (permalink) |
| NamePros Member Join Date: Nov 2005
Posts: 66
![]() | Am i supposed to put the function script inside the same php file as my output script? Cause currently they are both php included on the page. I dont think the globals command will help. Here is a more detailed rundown of whats happening: The functions script is php included onto my page (script posted in previous post) A template for my CMS is stored like this: <div> {title} {story} <?php ranking('{news-id}')?> (ive removed the ' ' but i get Parse error: syntax error, unexpected '{', expecting ')' ) </div> In the output script, it loads news.txt file, then the template. It looks in the template for {title}, {news-id} etc. then does a series of $output = str_replace("{news-id}", "news_arr[0]", "$output"); ????: NamePros.com http://www.namepros.com/showthread.php?t=213670 then echo's $output. Hopefully what i wanted it to echo the output like: <div> Title Goes here Story Goes here <?php ranking('0001')?> </div>
Last edited by nigelwong; 07-06-2006 at 08:55 PM.
|
| |
| | THREAD STARTER #12 (permalink) |
| NamePros Member Join Date: Nov 2005
Posts: 66
![]() | Ok im making abit of process. I have this: <?php rating_bar($newsid) ?> And my function: PHP Code: <div id="unit_long<?php echo $id ?>"> This line won't work: <?php echo @number_format($current_rating/$count,2)*25; ?> If i have something like $count <div id="unit_long<?php echo $count ?>"> it outputs nothing.
Last edited by nigelwong; 07-06-2006 at 09:54 PM.
|
| |
| | THREAD STARTER #16 (permalink) |
| NamePros Member Join Date: Nov 2005
Posts: 66
![]() | It was coded right, i typed it in my post wrong. I now found out its my SQL Statement: This works: $query=mysql_query("SELECT total_votes, total_value, used_ips FROM ratings WHERE id=1152076887") This doesnt. $query=mysql_query("SELECT total_votes, total_value, used_ips FROM ratings WHERE id='$id'") Even though if you echo $id in the function, it gives you 1152076887 |
| |