TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-18-2010, 12:16 AM   #1 (permalink)
The Visitor
Newcomer 
 
Join Date: Aug 2010
Location: Pahrump, NV
Posts: 1
Thanks: 0
Seal is on a distinguished road
Default Switch Command Problems

Before I ask my question, let me say that I am an old dbase programmer (and I do mean (OLD!) so, while I am not a absolute beginner, PHP is another languange (though the syntax is somewhat related).

Here is what I want to do:

Without using frames I want to use the switch command to replace the majority of the screen on a rotating basis. Several years ago (maybe 4 or 5) I had the switch command working like this but some idiot newbie programmer at the webhost overwrote it and I didn't have it backed up.

If you go to www.stevenwjohnson.com you will see what I have now. What I want to do is add a left hand menu (easy enough to do in HTML) and have each individual book display on the majority of the page, incrementing the variable +1 for every view so people don't see the same book every time they visit the site. And every refresh will bring up a new book.

My problem is that for every 'sample' switch/case code I download I get nothing but the logo and the top and bottom menus.

Here is the code I have been playing with...

<?php
switch ($x) {
case 0:
echo "x equals 0";
break;
case 1:
echo "x equals 1";
break;
case 2:
echo "x equals 2";
break;
default:
echo "x is not equal to 0, 1 or 2";
}
?>

I realize somewhere I should increment x but I can't even get the default to echo.

HELP!!!

Seal
Seal is offline  
Reply With Quote
Old 08-18-2010, 12:46 PM   #2 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

Ok, so you want to have a different layout and you only want to show 1 book and when they refresh the page you show another book, randomly. I don't think refreshing is a good way to navigate through the books if anything I would say instead of displaying 1, display them all downwards and just select randomly which is going to be at the top. Or am I understanding it badly?

About the switch code you posted, I tried it out and it work for me:
php Code:
<?php
$x = 5;
switch ($x) {
case 0:
echo "x equals 0";
break;
case 1:
echo "x equals 1";
break;
case 2:
echo "x equals 2";
break;
default:
echo "x is not equal to 0, 1 or 2";
}
?>

I am wondering if the way you get the value of $x returns you a string because a string in a loose comparison (which is what the switch statement does) would be equal to 0.

P.S. It would be better if you are sharing code to wrap it in highlight tags.
tony is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
The most inventive way to switch 2 values Wildhoney Tips & Tricks 32 08-10-2010 05:10 AM
Cant u switch with the use of cat=1 cat=2 etc? [!Read!] codefreek Absolute Beginners 2 06-29-2008 10:30 PM


All times are GMT. The time now is 03:36 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design