Jump to content

www.mysite.com/index.php?action= question


Jodha

Recommended Posts

Hi All,

 

I want to reference different sections within my index.php file.

 

I know there is a way of doing this but I dont have this clearly explained in my PHP book.

 

I's like to know two things which will help me solve a problem I've been puzzling over. Should be easier to answer than my previous posted question which seemed to cause confusion on all sides.

 

I have a link, lets call it

 

<a href="index.php?action=sectionX>Click me for Section X</a>

 

1) What code to I need to place at the top of the block of code which executes displaying "Section X"?

 

2) Do I use "break;" to end that part of the code before the next section (say index.php?action=sectionY for argument's sake)

 

 

This seems to be something to do with the Switch command, but honestly, the example Switch code and explanation in my book just aint giving me results.

 

Many thanks :)

Link to comment
Share on other sites

dennismonsewicz: Thanks but your link is broken :(

 

Sudden: Great but thats not answering. I have a book which is supposed to give me this info, they even have example code to cut and paste, it doesn't seem to work, but a lot of other functions I have learned from the book do.

 

Can somebody please just tell me:

 

If you want your php webpage link to navigate to a particular section you need to code:

 

Such and Such PHP statement.

 

Many many many thanks :)

Link to comment
Share on other sites

Well, sorry, all I want to know is a line of standard code.

 

I've been banging my head against a book which is suppose to tell me what to do and it isn't, I get supplied a link which doesn't work.

 

The title of this forum is PHP Help.

 

I'm a newbie, I need help. I'm not code illiterate but PHP is a new language for me, my background is HTML.

 

I'm trying to progress my skills, I know what I want to achieve and I know the answer should be quite simple.

 

Whats wrong with a:

 

"Hey, just start your block with XXXXXXX and you'll be away.

The link to that will by filename.php?action=XXXXXXX"

 

 

To be honest, if I knew the answer and somebody asked me the question, I'd give them the answer straight up, no "go look at this link" and supply a broken link.

 

I gave up on the other thread cos that was going nowhere. There seemed to be a dialogue start, a dialogue needs to continue for a solution to be found. If you cannot take time to talk to newbies and guide them through, how is the PHP community going to grow?

 

All in all, many thanks PHP Help forum for your Help, it has helped me kill half a day on the internet getting nowhere much.

 

 

kittrellbj, I'll take another look at your post, I'm trying to solve my problem from a different angle here so hopefully I'll see how your original suggestion fits in. The problem was first time round, it didn't look like it would fit into the menu script I need to use.

 

Sorry and best regards to those I am not offending.

Link to comment
Share on other sites

Right.

 

lordshoa and kittrellbj are supplying useful info again on my other thread.

 

Respect to you two, and thanks for your patients and ongoing suggestions. This is what good passing of knowledge is about, and its the way you inspire people learning from you.

 

:) 

Link to comment
Share on other sites

All in all, many thanks PHP Help forum for your Help, it has helped me kill half a day on the internet getting nowhere much.

 

wow... if writing code makes you this mad, you may want to try something else...

 

As for your original question, it was answered twice on the other post. The link from Dennis works fine.

 

Last but not least, I would bet 100 dollars that the code in the book works just fine. I have read hundreds of coding books and have yet to come across an app that the author wouldn't have verified as working before it was published.

Link to comment
Share on other sites

Last but not least, I would bet 100 dollars that the code in the book works just fine. I have read hundreds of coding books and have yet to come across an app that the author wouldn't have verified as working before it was published.

 

I actually have tried code from a book and it not work LOL... can't remember the name of the book, but the code was very misleading.

Link to comment
Share on other sites

The Link:

 

Well, dunno, just tried it again... does BB code work here? Lets try

 

 

Address Not Found

 

us3.php.net could not be found. Please check the name and try again.

 

The browser could not find the host server for the provided address.

 

    *  Did you make a mistake when typing the domain? (e.g. "ww.mozilla.org" instead of

 

        "www.mozilla.org")

 

    *  Are you certain this domain address exists?  Its registration may have expired.

 

    *  Are you unable to browse other sites?  Check your network connection and DNS server settings.

 

    *  Is your computer or network protected by a firewall or proxy?  Incorrect settings can interfere with Web browsing.

 

Could it be my version of FireFox? Could it be the route through the net my computer takes to get to this particular server?

 

1) Coding dont make me mad, I enjoy it otherwise I wouldn't be trying to advance onto more than HTML. Back in '82 when the speccy came out, me bro would play Horrace Goes Skiing and Chequered Flag, I picked up the manual and taught myself Basic. Lost interest in computers when Sinclair took the commands off the keys and you had to type everything, got a bike instead and took up mountain biking. Then discoverd clubbing, got into DJing, from there into music production, and from music production using CuBase (kinda programming but with organising sounds and signal routing) found myself back at playing with other sorts of media including basic website production.

 

I like creativity, website coding is creative. What makes me mad is when there is a simple thing which alludes me which I would be happy to pass on to another, but find it hard for the reverse to happen. Knowledge is there to be shared, not horded ;)

 

2) Maybe it was answered twice in the other post, but in a way I am not understanding. Just as my book (PHP & MySQL for Dummies) assumes you already know HTML and doesn't explain it there, I may be right in thinking you beleive my level of PHP knowledge is higher than it actually is. Its not that I dont have the capacity, I just aint had enough of the experience innit.

 

3) Amazon reviews of the book are mixed actually, take a look:

 

http://www.amazon.com/review/product/0470096004/ref=cm_cr_dp_all_helpful?_encoding=UTF8&coliid=&showViewpoints=1&colid=&sortBy=bySubmissionDateDescending

 

I'll hightlight: "p.s.: Janet Valade has written several beginner books on PHP/MySQL. Maybe, eventually, she will get it right. She is so close... "

 

I've also read somewhere, she likes to throw in little 'mistakes' to test the reader. Personally, if I buy a text book I want the whole and actual truth of the text which it is about, especially if I am learning something new of which I have no prior knowledge. I'm sure you would all concur. If I where to write a text book to teach others, this is the approach I would take too. Why write a text book if you are only going to throw your students off what they should be learning by leaving in mistakes? Bad practice.

 

Found all this out after the book was bought.

 

I might be up for that 100 dollar bet ;)

Link to comment
Share on other sites

To be honest, the idea of using a switch for this seems pointless to me anyway. That would meen you would need to add more code to your script for each new section. Not exactly the point of building dynamic webpages.

 

Depending on your site, you could simply use the $_GET['action'] variable (this is passed by ?action=whatever in the url) to include a file. eg;

 

<?php

if (isset($_GET['action'])) {
  $action = basename($_GET['action'], '.php');
  if (file_exists($action)) {
    include_once $action;
  }
}

?>

 

Given a the url ?action=sectionX this would include sectionX.php into your page.

 

However, for a more robust solution you may opt to go the database route instead of including files. eg;

 

<?php

  if (isset($_GET['action'])) {
    $action = mysql_real_escape_string($_GET['action']);
    $sql = "SELECT title, data FROM tbl WHERE page = '$action' LIMIT 1";
    mysql_connect();
    mysql_select_db('example');
    if ($result = mysql_query($sql)) {
      if (mysql_num_rows($result)) {
        $row = mysql_fetch_assoc($result);
        echo "<html>"
        echo "  <head><title>{$row['title']}</title></head>";
        echo "  <body>";
        echo "    <p>" . nl2br($row['data']) . "</p>";
        echo "  </body>";
        echo "</html>";
      } else {
        echo "Page not found";
      }
    }
  }

?>

 

Obviously this is VERY much simplified but I hope it helps you some.

Link to comment
Share on other sites

Hmmm, it will I'm sure, but I dont think I still have an answer to what I am actually trying to achieve right here right now. However, before saying any more I would like to thank everybody who has provided advice and guidance thus far.

 

Now, let me try and provide a full rundown of my project, which should show why the good advice so far doesn't actually help me that much. Or at least, why I am not interpreting is correctly.

 

1) I want an index.php file which is the website portal. I've done this with HTML and framesets where the frameset is the portal. I dont like sites which fill the address bar with loads of stuff, I like to keep what it shows simple. I.E. "http://www.thewebsite.com". I find any "/index.php" or "/index.html" gets truncated the way I do this, which I also like. I think this may be browser dependent, but thats by the by ;)

 

2) At the top I want a header.

 

3) On the left side I want the navigation function. My 'client' (friend in need to website) has specified a particular menu system I have in HTML code using CSS and JS.

 

4) To the right of the menu I want the content to be displayed. This changes as per menu item selection.

 

5) At the bottom I want the footer.

 

 

 

My index.php (template) is currently coded thus:

 

<?php

 

echo

      "<table width='100%'>

      <tr>

      <td colspan='2'>";

 

include('header.inc');

 

echo

      "</td>

      </tr>

      <tr>

      <td>";

 

include('navigation.inc');

 

echo

      "</td>

      <td>";

 

echo $content;

 

echo

      "</td>

      <tr>

      <td colspan='2'>;

 

include(footer.inc);

 

echo

      "</td>

      </tr>

      </table>

 

?>

 

header.inc and footer.inc you dont need to know about. They contain details of my client's business and we are both satisfied with the way these display and their content.

 

$content is a variable I wish to use for selecting what is displayed in the main part of the site. As the variable changes, different pages are displayed, (ahem) obviously! :)

 

I know how I can combine aspects within a variable from other variables or just plain adding in extra bits of string to turn say

 

$content = home

 

to

 

$content = home.inc

 

or

 

$content = content/home.inc

 

etc.

 

The issue is with these dam <a href=content.html>Content</a> aspects in the menu script.

 

The menu script (disregarding the CSS and JS) looks like this:

 

<d1 id="menu">

                <dt onclick="javascript:menu();"><a href="#">Home</a></dt>

 

        <dt onclick="javascript:menu('');"><a href="#">Section #2</a></dt>

     

      <dt onclick="javascript:menu('smenu1');">Section #3</dt>

      <dd id="smenu1"><ul>

            <li><a href="#">Section #3.1</a></li>

            <li><a href="#">Section #3.2</a></li>

            <li><a href="#">Section #3.3</a></li>

            <li><a href="#">Section #3.4</a></li>

            <li><a href="#">Section #3.5</a></li>

            <li><a href="#">Section #3.6</a></li>

            <li><a href="#">Section #3.7</a></li>

            <li><a href="#">Section #3.8</a></li>

            <li><a href="#">Section #3.9</a></li>

            <li><a href="#">Section #3.10</a></li>

            <li><a href="#">District Councils Conferences</a></li></ul></dd>

 

      <dt onclick="javascript:menu('smenu2');">Section #4</dt>

      <dd id="smenu2"><ul>

            <li><a href="#">Section #4.1</a></li>

            <li><a href="#">Section #4.2</a></li>

            <li><a href="#">Section #4.3</a></li>

            <li><a href="#">Section #4.4</a></li></ul></dd>

 

                <dt onclick="javascript:menu();"><a href="#">Section #5</a></dt>

 

                <dt onclick="javascript:menu();"><a href="#">Section #6</a></dt>

</d1>

 

Now, what is the PHP statement which needs to follow "<a href=" to change this from a normal HTML link tag to a statement which changes the value of $content?

 

That is my one and only question I want an answer to. I dont want links to websites where I have to wade through a bunch of text to try and find the answer, I've been doing this to no avail, which is WHY I come to a forum of PHP heads to directly ask people who know this language better than me.

 

Lets assume somebody knows, please tell me :)

 

Assuming there is no statement for this (I am happy to accept this as a possibility), the other way I figure I can do this is:

 

- repeat the script I have already described but in a way which sections index.php into its (what will be about 50) sections of content and the

 

<a href=content.html>Content</a>

 

statements take you to each section. Something like -

 

<a href=index.php?action=content>Content</a>

 

Using this, for each section I'll use an "include(content.inc)" statement instead of the $content variable. Seems longer winded but I still get what I want. It'll mostly be a cut'n'paste operation anyway.

 

For this option, I need to know two statements:

 

1) The statement which starts each block of code for each section

2) The statement which ends each block of code for each section

 

I'm sorry if this has already been answered, but I cannot see the answer clearly in what has been returned so far if this is the case.

 

As for connecting to a database, for the above I dont want to get into that. I will be using a database for displaying sections of content such as the CVs and the information guides my client needs to display on his site. I am already versed enough with such database interaction to achieve this happily -> one of my personal projects was building an events listing application for my website which is database driven, I've got it referencing flyer images and formatting dates, times and prices plus a "publish this event" option and an update information function.

 

My stumbling blocks are taking my previously used library of HTML menus and implementing them in PHP script, similar to how I describe above.

 

If no advice can be provided to answer this (hopefully simple issue) I'll just have to jump back to using framesets in HTML to get the site presentation how it has been briefed.

 

Many thanks in advance for further help, I dearly hope somebody understands what I am trying to do and provides the right guidance.

 

Best regards all :)

Link to comment
Share on other sites

Now, what is the PHP statement which needs to follow "<a href=" to change this from a normal HTML link tag to a statement which changes the value of $content?

 

Anchor tags are html. Whatever goes in them is html. If you use php to output that html so be it, but its still html. Here is a simple example of what I think your getting at. I don't see how however you didn't see this in my previous examples.

 

<a href="?action=foo">foo</a>
<a href="?action=bar">bar</a>
<a href="?action=bob">bob</a>
<?php

if (isset($_GET['action'])) {
  $content = $_GET['action'];
}

echo $content;

?>

 

 

 

html is simply used to output html (and other things but thats besides the point). So, if you had a method that works how you want it in html, then have your php output that html. I don't see much point in using php at all though if that be the case and really, I think your missing much of the point.

 

I dont like sites which fill the address bar with loads of stuff, I like to keep what it shows simple. I.E. "http://www.thewebsite.com". I find any "/index.php" or "/index.html" gets truncated the way I do this, which I also like.

 

So you don't like people to actually being able to bookmark/navigate pages on your site? The Stuff in the Address bar is just that. The address of the page in question. Without it your site is not indexed and users cannot go directly to pages.

 

Anyway, if thats what your trying to do it has nothing at all to do with php. As I said above, php outputs html, thats it.

 

Assuming there is no statement for this (I am happy to accept this as a possibility), the other way I figure I can do this is:

 

- repeat the script I have already described but in a way which sections index.php into its (what will be about 50) sections of content and the

 

<a href=content.html>Content</a>

 

statements take you to each section. Something like -

 

<a href=index.php?action=content>Content</a>

 

Using this, for each section I'll use an "include(content.inc)" statement instead of the $content variable. Seems longer winded but I still get what I want. It'll mostly be a cut'n'paste operation anyway.

 

For this option, I need to know two statements:

 

1) The statement which starts each block of code for each section

2) The statement which ends each block of code for each section

 

That was all covered in my last post.

Link to comment
Share on other sites

Last but not least, I would bet 100 dollars that the code in the book works just fine. I have read hundreds of coding books and have yet to come across an app that the author wouldn't have verified as working before it was published.

 

I actually have tried code from a book and it not work LOL... can't remember the name of the book, but the code was very misleading.

 

I agree, I have run across a few that had defunct code in them.  The reason, though, I think is that the publisher misprints, not necessarily the author overlooking things in the code.  Of course, I'm sure it has happened before.

 

And sorry, not attempting to hijack, just saw this in here and wanted to put in about $0.02.

Link to comment
Share on other sites

if you're looking to include a bunch of different pages in a single php file, navigating through them with POST data, try something like this...

 

<p>Go to <a href="yourPage.php?section=x">Section X</a>, <a href="yourPage.php?section=y">Section Y</a>, or <a href="yourPage.php?section=z">Section Z</a></p>

switch($section){	// loads different sections, depending on what section is set to
case X:
	echo "Section X";
	break;

case Y:
	echo "Section Y";
	break;

case Z:
	echo "Section Z";
	break;
}	// end switch($section)

 

If this doesn't work, try switch($_POST['section']){ instead, but feel free to correct me if I'm wrong, I'm no guru

Link to comment
Share on other sites

Errant_Shadow and thorpe, I do believe you have provided me with my holy grail, thank yee both very muchly :)

 

Looks like I have both options to work with, so my day looks like I should get it rolling and get coding  ;D

 

Thorpe, if I missed your previous reference it's probably because I have been looking out for <a href... and I dont think you have mentioned that in your previous post, you spoke of other code statements. I would imagine my lesser knowledge stops me from connecting the two. Sorry for making you type things out again, however, your second post is very clear to me. I take my hat off to you for that ;)

 

I also see your point about bookmarks, however I was more thinking about it from site security... if the viewer is getting less info on how you have your directories (etc) it'll be harder for them to hack. Although I suspect a serious hacker would still find it kids play.

 

I normally like to produce sites so the navigation side of things means you dont 'have' to book mark a page as such, you just go to the site and all pages are so easy to get to you can ask the question, why bookmark this single page when it is one click from your menu? ...guess I'm not thinking as if I had a photo album with hundreds of sub pages however. Maybe I'll revise my practises.

 

Anyways, many thanks again. Hopefully I'll not need come back for more help on this, but assuming wind is now in sail I'll let you know successful I've been :)

 

Cheer!  :D

 

 

Link to comment
Share on other sites

I'm pretty sure you can only acquire $POST variables through use of a submitted form by action Post.  $GET acquires it from the URL.

 

Also, it is a good practice to watch case sensitivity in all things.  Uniformity is important to a solid application.

 

I am semi-familiar with $POST but not yet used $GET, there is a bunch of text the contraversally writing Janet Valade has in her book, I shall reread shortly.

 

I'm well aware of case sensitivity, but thanks for the double check ;) I like uniformity in code otherwise its easy to loose yourself innit! ;)

Link to comment
Share on other sites

SUCCESS

 

Applying the code which thorpe provided in the his last post has solved all my current problems with this site design.

 

I can use my expanding menu, use the linking and variable value adjusting code as suggested, and my provisional template if giving my correct test results.

 

All I need to do now is get the frick on with the job :D

 

Thorpe, I am very grateful. If you where local I'd take you out for a pint. In absence of this, I hope this will do until a such time when I can buy you a pint:

 

430565837_b1bb5d4763.jpg?v=0

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.