Web Hosting Talk







View Full Version : Help with php code needed


smarty-boots
12-17-2009, 11:29 AM
Hi
I have this code:

foreach ($tab_name as $key => $tabtitle)
{
$tabtitle = substr ($tabtitle, 1);
$taburl = str_replace (' ', '_', $tabtitle);
$tabtitle2 = titlecase ($tabtitle);
echo '<li class="tab"><a href="' . $modlink . '&par=' . $taburl . '.php">' . $tabtitle2 . '</a></li>';
}
and I need this
foreach ($tab_name as $key => $tabtitle)
{
$tabtitle = substr ($tabtitle, 1);
$taburl = str_replace (' ', '_', $tabtitle);
$tabtitle2 = titlecase ($tabtitle);
if ($_GET['par'] = ' . $taburl . '.php){
echo '<li class="tab"><a href="' . $modlink . '&par=' . $taburl . '.php"><b>' . $tabtitle2 . '</b></a></li>';
}else{
echo '<li class="tab"><a href="' . $modlink . '&par=' . $taburl . '.php">' . $tabtitle2 . '</a></li>';
}
}
but this is not working all I get is all the foreach bold but I only want the one that match the
if ($_GET['par'] = ' . $taburl . '.php)So how do I do this?

mattle
12-17-2009, 12:42 PM
if ($_GET['par'] = ' . $taburl . '.php)So how do I do this?

The first thing you need to do is turn on error_reporting:


ini_set("display_errors", true);
error_reporting(E_ALL);
Here are the problems I see with this code:



You are not checking to see if $_GET['par'] is even set.
I think you've got a quoting problem...the single quotes will not allow the variable to be interpolated.
.php is outside of the quotes, therefore the "." will be seen as a concatenation operator and php will be seen as a undefined constant (and "php" will be used).
You are doing an assignment instead of an equality test...this will return whatever the Boolean cast of the right-hand side of the assignment is.

This is literally how your code breaks down.



Evaluate constant 'php' (Evaluates to "php")
Concatenate ' . $taburl . ' and "php" (Yields " . $taburl . php"--thats a literal dollar sign, not the value of $taburl)
Assigns the result of the concatenation to $_GET['par']
Evaulates the contents of $_GET['par'] for truth

This is probably what you want:


if (isset($_GET['par']) && $_GET['par'] == "$taburl.php")
You managed to write bad code that passed the parser...which is all the more reason to enable error reporting. You would have at least gotten the message "Use of undefined constant php, assuming 'php'", which would have been your first clue that something was wrong.

smarty-boots
12-17-2009, 04:01 PM
Thanks for your help the oddest thing is that I have
ini_set("display_errors", true);
error_reporting(E_ALL); at the top of the page anyway just one more question for you do you do subcontract work?

HostBill
12-17-2009, 04:51 PM
ini_set("display_errors", true);
error_reporting(E_ALL);

Depends if your PHP configuration allows to turn this values on locally, if not you'll still wont see any error.

mattle
12-17-2009, 05:18 PM
Depends if your PHP configuration allows to turn this values on locally, if not you'll still wont see any error.

Correct. If that's the case (which usually means you're on shared hosting), your hosting provider should be making a PHP error_log available to you. You can use that instead of directing errors to the browser.

just one more question for you do you do subcontract work?

On a case by case basis...right now nothing until the new year. PM me.

rasin
12-18-2009, 01:39 AM
if ($_GET['par'] = ' . $taburl . '.php){


change the above mentioned code to

if ($_GET['par'] = $taburl.'.php'){

also check the web server error log

For eg:
if you are using apache webserver and operating system is linux

then use this command

tail -f /etc/httpd/logs/error_log

path depends upon your local settings,type the coomand 'httpd -V' for the correct path

csparks
12-18-2009, 02:15 AM
Corrected code should be:


if (isset($_GET['par']) && $_GET['par'] == $taburl'.php'){
echo '<li class="tab"><a href="' . $modlink . '&par=' . $taburl . '.php"><b>' . $tabtitle2 . '</b></a></li>';
}else{
echo '<li class="tab"><a href="' . $modlink . '&par=' . $taburl . '.php">' . $tabtitle2 . '</a></li>';
}

mattle
12-18-2009, 10:09 AM
Just another thought...an IDE with grammatical highlighting and syntax-checking might help you out a great deal here.

smarty-boots
12-18-2009, 10:29 AM
I need a new one I have D/W but i now do not like it what have you got?

csparks
12-18-2009, 10:58 AM
For single file editing (such as this), I use crimson editor. For full projects, its netbeans.

M Bacon
12-18-2009, 11:13 AM
Note Pad Plus is an excellent alternative.

mattle
12-18-2009, 11:31 AM
This has been discussed to death on other threads :) However, I generally use Eclipse. I've recently installed NetBeans on a Solaris server that I use, and I have to say, I'm pretty impressed. The CVS integration is remarkable! +1 for NB

Christian
12-18-2009, 04:58 PM
Corrected code should be:


if (isset($_GET['par']) && $_GET['par'] == $taburl'.php'){
echo '<li class="tab"><a href="' . $modlink . '&par=' . $taburl . '.php"><b>' . $tabtitle2 . '</b></a></li>';
}else{
echo '<li class="tab"><a href="' . $modlink . '&par=' . $taburl . '.php">' . $tabtitle2 . '</a></li>';
}


Without looking over that code intently, you are missing a period in your conditional FYI. ;)

$taburl.'.php'

csparks
12-18-2009, 09:20 PM
oops, I guess I should have double checked that before I posted it.:blush:

smarty-boots
12-18-2009, 09:33 PM
THANKS FOR ALL YOUR HELP "mattle (http://www.webhostingtalk.com/member.php?u=304186)" POST #2 WORKS AND IS THE ONE I AM USING.

AGAIN THANKS