Log in

View Full Version : OR Failure



marain
05-27-2013, 05:49 PM
Folks, I need help again.

The site is http://www.NJMarijuana.com. What I am trying to do is separate menu items at the bottom with " | " unless the menu item ends the line, in which case I want "<br />" instead. This works for the first four lines. For the last line, however, where I'm expecting the "<br />" I get instead the " | ". I even added what should be a completely redundent "OR" test intending to do the same thing. Neither works.

Here is my array:



$menuLinks = array(

'index',
'allanqual',
'byrnequal',
'quest',
'http://www.NJMarijuana.com/audio/njpot.mp3',
'contactus',

'possession',
'intent',
'http://www.NJDriversLicenses.com',
'http://www.NJExpungements.com',

'arrested',
'busted',
'76FR40552',
'drugs',
'resources',
'history',

'http://maps.google.com/maps?f=q&amp;hl=en&amp;q=100+Bayard+Street,+New+Brunswick+NJ+08901-2165',
'http://www.njnbpa.org/parking-locator/',
);




Later on, I have this test:



if ( $menuLinks[$i] === 'contactus'
|| $menuLinks[$i] === 'http://www.NJExpungements.com'
|| $menuLinks[$i] === '76FR40552'
|| $menuLinks[$i] === 'history'
|| $menulinks[$i] === 'http://www.njnbpa.org/parking-locator/'
|| strpos($menulinks[$i], 'njnbpa'))
{echo '<br />';}
else {echo ' | ';}



Baffled am I.

traq
05-27-2013, 07:21 PM
Notice: Undefined variable: menulinks

That's regarding these two lines:
|| $menulinks[$i] === 'http://www.njnbpa.org/parking-locator/'
|| strpos($menulinks[$i], 'njnbpa'))

There may be other problems (or, I suspect, a much more efficient way to accomplish the task). Please post the rest of your code.

marain
05-27-2013, 07:36 PM
Traq,

Here it comes. Please note its huge quantity of comments and data (as opposed to logic). I was tempted to delete all that before posting, but did not want to be the judge of what is and is not important inasmuch as I cannot find the problem where I think I ought to be looking. You may want to edit my post to delete the non-essential portions of the upload.

Well I had to delete much of the comments and text anyway, since I exceeded the 10,000 character limit. What I deleted was ONLY comments and text.



<?php

/***************************************************************************************************
adjust order by rearranging in both arrays

add or delete as desired but then must also adjust .htaccess and add/delete pageContent/[name].txt

For site to "process" a page as a full-fledged member, specify it in [root]\page.php.


On 12/29/2010 18:04, Allan Marain wrote:

> How do I put text in the left hand margin?

trivial:

if you want the same extra text on every page, copy the lines below to the end of

includes\menu.inc.php and fill in the blank line after the <p> with whatever text you want, multiple

lines ok (don't copy the start/end of course)

?>
<p>

</p>


if instead you want text on only one page, copy this in, and then change the ### to match the value

of the $here variable on the page you want it for (which is the same as the items in the $menuLinks

array)

if ( $here === '###' ) {
?>
<p>

</p>
<?php
}


if you want various text on various pages, copy the above lines again below the set above (as many

times as you need to) but this time write elseif instead of if at the beginning, like this:
elseif ( $here === '@@@' ) {



Michael


***************************************************************************************************/

$menuItems = array(

'Home',
'Allan Marain',
'Edward J. Byrne',
'Case Evaluation',
'Radio Promo',
'Contact Us',

'Possession',
'Distribution',
'Drivers Licenses',
'Expungements',

'Stopped by Police',
'Jersey Justice',
'The Twilight Zone',
'Dangerous Drugs',
'High Links',
'About Marijuana',

'Directions',
'Parking',
);


$menuLinks = array(

'index',
'allanqual',
'byrnequal',
'quest',
'http://www.NJMarijuana.com/audio/njpot.mp3',
'contactus',

'possession',
'intent',
'http://www.NJDriversLicenses.com',
'http://www.NJExpungements.com',

'arrested',
'busted',
'76FR40552',
'drugs',
'resources',
'history',

'http://maps.google.com/maps?f=q&amp;hl=en&amp;q=100+Bayard+Street,+New+Brunswick+NJ+08901-2165',
'http://www.njnbpa.org/parking-locator/',
);


if ( $menuType === 'button' ) echo '<br />'; // adjust vertical start position on left margin

menu
$menuCount = count( $menuItems) ;

for ( $i = 0; $i < $menuCount; $i++ ) {
if ( $menuItems[$i] ) {
echo '<a ';
if ( $here === $menuLinks[$i] ) echo 'class="here" ';
else echo 'class="' . $menuType . '" ';

/************************************************************************
*
* Now we're going to test for local links. We do that by seeing whether the URL
* omits 'http'. If so, it's a local link, since we use relative addressing for local links
*
************************************************************************/

if ( strpos( $menuLinks[$i], 'http' ) === FALSE ) {
if ( $menuLinks[$i] === 'index' ) echo 'href="http://www.NJMarijuana.com'; // closing " is in

line 61 below
else echo 'href="http://www.NJMarijuana.com/page.php?here=' . $menuLinks[$i];
}


/**************************************************************************
*
* Now we're going to see whether we want to open a new window. The two pages
* where we do want to open a new window are the google maps page, and the
* parking authority page. Allan added a third new-window page on 10-13-12,
* viz the Radio Promo page.
*
***************************************************************************/

elseif
( strpos( $menuLinks[$i], 'google' ) !== FALSE
|| strpos( $menuLinks[$i], 'parking' ) !== FALSE
|| strpos( $menuLinks[$i], 'njpot' ) !== FALSE )
echo 'target="_blank" href="' . $menuLinks[$i] . '" onclick="popwin(\'' . $menuLinks[$i] . '\');

return false';

// other marain links need no special handling

else echo 'href="' . $menuLinks[$i];

echo '">&nbsp;' . $menuItems[$i] . '&nbsp;</a>';
if ( $menuType === 'button' ) echo '<br />';
else {


/*****************************************************************************

Now we format the bottom menu
First do groupings, by category
Then examine individual entries

*****************************************************************************/

if ($menulinks[$i] === 'contactus'
|| $menulinks[$i] === 'http://www.NJExpungements.com'
|| $menulinks[$i] === 'history')
{echo 'br />';}


if ( $menuLinks[$i] === 'contactus'
|| $menuLinks[$i] === 'http://www.NJExpungements.com'
|| $menuLinks[$i] === '76FR40552'
|| $menuLinks[$i] === 'history'
|| $menulinks[$i] === 'http://www.njnbpa.org/parking-locator/'
|| strpos($menulinks[$i], 'njnbpa'))
{echo '<br />';}
else {echo ' | ';}
}
echo "\n";
}
}

if ( $menuType === 'button' ) {
if ( $here === 'resources' || $here === 'index' || $here === '76FR40552' ) {
if ( $here === 'resources' || $here === '76FR40552' ) {
?>
<br />
<br />
<br />
<br />
<br />
<font size="-1">
<a name="courts"></a>Municipal Courts<br />
Telephone Directories
<br />
<br />
<a href="#Hunterdon">Hunterdon County</a><br />
<a href="#Middlesex">Middlesex County</a><br />
<a href="#Monmouth">Monmouth County</a><br />
<a href="#Somerset">Somerset County</a><br />
<a href="#Warren">Warren County</a>
<br />
<br />
<a name="Hunterdon"></a>
Telephone Directory of Municipal Courts in Hunterdon County
<br />
<br />
Bethlehem and Bloomsbury Joint Municipal Court<br />
908-735-4559
<br />
<br />

<br />
<font size="-2"><a href="http://www.njmarijuana.com/page.php?here=resources">Return to

Top</a></font>
<a name="Middlesex"></a>
<?php
}
?>
<font size="-1">
<br />
<br />
Telephone Directory of Municipal Courts in Middlesex County
<br />
<br />

<br />
</font>
<font size="-2"><a href="http://www.njmarijuana.com/page.php?here=resources">Return to

Top</a></font>
<br />
<br />
<?php
if ( $here === 'resources' || $here === '76FR40552' ) {
?>
<a name="Monmouth"></a>
Telephone directory of Municipal Courts in Monmouth County
<br />
<br />
Aberdeen Municipal Court<br />
732-583-4200
<br />
<br />

<br />
<br />
<font size="-2"><a href="http://www.njmarijuana.com/page.php?here=resources">Return to

Top</a></font>
<br />
<br />
<a name="Somerset"></a>
Telephone Directory of Municipal Courts in Somerset County
<br />
<br />
Bedminster Municipal Court<br />
908-212-7020
<br />
<br />

<br />
<br />
<font size="-2"><a href="http://www.njmarijuana.com/page.php?here=resources">Return to

Top</a></font>
<br />
<br />
<a name="Warren"></a>
Telephone Directory of Municipal Courts in Warren County
<br />
<br />
Allamuchy Municipal Court<br />
908-852-6667

White Municipal Court<br />
908-475-4827
<br />
<br />
</font>
<font size="-2"><a href="http://www.njmarijuana.com/page.php?here=resources">Return to

Top</a></font>
<?php
}
}
elseif ( $here === 'arrested' ) {
?>
<p>
<font size="-2">
The policeman is <i>not</i> your friend. The policeman is a soldier in the “War Against

Drugs,&#8221 which is <i>really</i> a war against citizens. Do not try to talk your way out of an

arrest. Your “friendly” police officer is asking you questions in order to obtain

answers to use against you in court. Whatever you say can only hurt you. It will not improve your

situation.
<br />
<br />
To explore this subject in more depth, visit the web site of the <a

href="http://www.flexyourrights.org/" target="_blank">Flex Your Rights</a> Foundation. And

remember...
<br />
<br />
“Even a fish would not get caught if he kept his mouth shut.”</font>
<?php
}
elseif ( $here === 'allanqual' ) {
?>
<br />
<font size="-1">
<br />
<br />
Reflections of Allan Marain in Municipal Court:
<br />
<br />
As I sit in municipal court before my clients&#39; cases are called, I watch with frustration and


to have the benefit of that experience.
<br />
<br />
Call them.
</font>
<?php
}
elseif ( $here === 'drugs' ) {

echo '<p><font size="-1">At one time, proclaiming that the earth circled the sun could earn a


of that day.</font></p>'
?>

<?php
}
}

traq
05-27-2013, 08:51 PM
Well... I don't know how much of this you want (or are able) to refactor, but I'll offer suggestions where I think you should give consideration to.

$menuItems = array(

'Home',
'Allan Marain',
'Edward J. Byrne',
'Case Evaluation',
'Radio Promo',
'Contact Us',

'Possession',
'Distribution',
'Drivers Licenses',
'Expungements',

'Stopped by Police',
'Jersey Justice',
'The Twilight Zone',
'Dangerous Drugs',
'High Links',
'About Marijuana',

'Directions',
'Parking',
);


$menuLinks = array(

'index',
'allanqual',
'byrnequal',
'quest',
'http://www.NJMarijuana.com/audio/njpot.mp3',
'contactus',

'possession',
'intent',
'http://www.NJDriversLicenses.com',
'http://www.NJExpungements.com',

'arrested',
'busted',
'76FR40552',
'drugs',
'resources',
'history',

'http://maps.google.com/maps?f=q&hl=en&q=100+Bayard+Street,+New+Brunswick+NJ+08901-2165',
'http://www.njnbpa.org/parking-locator/',
);
Commenting on this first, it would be much more efficient and more robust (less fragile) to define the URIs and their respective link text together, rather than having separate arrays which can get mixed up if you ever need to add/remove menu items. For example:

# instead of

$menuItems = array( 'Home','Allan Marain','...etc.' );
$menuLinks = array( 'index','allanqual','...etc.' );

# do this

$menu = array(
array( 'Home','index' )
,array( 'Allan Marain','allanqual' )
,array( '...','etc.' )
);
This would change how you'll need to deal with processing the info, of course, but I don't think that's a bad thing either. Let me know if you want to try this and I'll help you out.


if ( $menuType === 'button' ) echo '<br />'; // adjust vertical start position on left margin
I often advise people to do "PHP First (http://www.dynamicdrive.com/forums/entry.php?267-Every-PHP-Tutorial-Is-Wrong)." In addition to other benefits, it makes your code more readable, because you don't break your program logic into small parts (that don't make sense on their own) with large blocks of content in the middle (as in the next few dozen lines of your script). For example, if you did processing first, and then output the HTML markup, you wouldn't need to keep track of things like 'closing " is in line 61 below' (which, btw, will stop being true next time you edit the file).

...not as important, but you should be using CSS for tasks like adjusting positioning, not more HTML markup.


$menuCount = count( $menuItems) ;

for ( $i = 0; $i < $menuCount; $i++ ) {
if ( $menuItems[$i] ) {
echo '<a ';
if ( $here === $menuLinks[$i] ) echo 'class="here" ';
else echo 'class="' . $menuType . '" ';
logical blocks (like if and else ) should always be surrounded by brackets ( {} ). PHP allows you to omit them if the condition only applies to one line of code (as is the case above), but this is A Bad Thing. It saves you two characters of typing, and costs you readability ("oh, wait, that had an "if" in front of it") and makes your code fragile ("oh, wait, there's no brackets so the line I added always happens").


# NEVER DO THIS
if( something ) do something else;

# ALWAYS DO THIS
if( something ){
do something else;
}:)

************************

Does fixing that typo solve your problem?

marain
05-28-2013, 12:03 AM
Addressing your last question first, fixing the type DOES solve the problem, for which I thank you. I forgot to consider the case sensitivity/camelback issue.

Concerning the rest, well, firstly (as you have perhaps gathered), I maintain and (try to) enhance the site, but I did not write it. I fully agree that logical blocks should be in braces. I've already implemented that in a number of places, and will continue to do so, as I encounter them. I am inclined to not implement your other suggestions. The time I am able to devote to this is limited. I appreciate the wisdom of your suggestions and the generosity of your offer, but the "payback" here would not justify the work required for what is largely a hobby for me. Especially after I've devoted as much time as I have to figuring out what it's all about in the first place ;-) I also very much want to not trespass on your good nature (as well as that of djr33, jscheuer1, Beverly, and the others here who are so incredibly giving--and patient).

A.

traq
05-28-2013, 12:52 AM
Addressing your last question first, fixing the type[sic: *typo] DOES solve the problem, for which I thank you. I forgot to consider the case sensitivity/camelback issue.
great; glad to hear it.


Concerning the rest, well, firstly (as you have perhaps gathered), I maintain and (try to) enhance the site, but I did not write it... the "payback" here would not justify the work required for what is largely a hobby for me.
Of course. Not an unexpected answer - that's just "how it is" in many cases.
When you start something new, however, the answer is very different. Don't forget to ask, if you ever find yourself in that situation. :)


I also very much want to not trespass on your good nature (as well as that of djr33, jscheuer1, Beverly, and the others here who are so incredibly giving--and patient).
No worries! And thank you - we're happy to help!