TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   view.php?=4aFA3a (http://www.talkphp.com/advanced-php-programming/5284-view-php-4afa3a.html)

Randy 02-24-2010 04:07 AM

view.php?=4aFA3a
 
Alright so I am working on a project (still/again) and I am stuck here again.. It is sort of like pagination but not exactly.

I want to allow the user to go to the url with a string, the string is then checked in the mysql database if it exists it pulls data from the database of the row with that info, and then have the information in the database displayed to the user on that page.

Cheers,
Randy

delayedinsanity 02-24-2010 10:14 AM

Where in your code are you getting stuck?

Randy 02-24-2010 11:22 PM

I am unsure about how to create the url and then how to get the code from that url.

delayedinsanity 02-25-2010 12:36 AM

This page would be a good starting point for reviewing the material you need to understand for this type of situation. In particular read the section immediately following Example #2.

Just to summarize, your query string is based on key->value pairs, and is considered a GET request. PHP automatically stores all values it finds in either a POST or GET request in similarily named superglobals, such as in your case $_GET.

To apply a GET query string, you're going append a question mark, followed by the key->value pairs, such as http://mydomain.com/mypage.php?key=value&this=that (multiple key->value pairs are appended with an ampersand). From within PHP you can access these with $_GET['key'], which would for the previous example return 'value', or $_GET['this'] would return 'that'.

From there, your options are wide open to interpret the values and act upon them.

Randy 02-25-2010 04:44 AM

That looks like it will work for getting the data but then how do i create that url.

I am unsure how to create the url:
http://mydomain.com/view.php?view=3fa5D

delayedinsanity 02-25-2010 05:10 AM

Well I can't code the whole thing for you, so you're going to have to help us by explaining the sequence of events that you're planning for, and what you've accomplished so far codewise.

Hightower 02-25-2010 04:11 PM

Surely it's just a case of creating a random string using the relevant function, and then quickly checking if that string exists in the database. If it does the random function runs again and checks. If it doesn't already exist in the database then you have your random string to insert into for that record?

EHJamie 07-25-2010 08:19 PM

Hey

You've probably solved this by now, but anybody else looking for the solution, just thought I'd post what I'd do..

Code:

<?php

        /*
                Examples of how to access these pages:
               
                Call pages by url.php?action=new
                Call pages by url.php?action=edit
                Call pages by url.php?action=delete
        */

        $page = htmlentities(trim($_GET['action']), ENT_QUOTES);

        switch($page){
               
                // What shows by default if not ?action chosen
                default:
               
                        // HTML or code in here to view...
               
                break;
               
                case "new":
               
                        // HTML or code in here to view...
               
                break;
               
                case "edit":
               
                        // HTML or code in here to view...
               
                break;
               
                case "delete":
               
                        // HTML or code in here to view...
               
                break;
               
        }

?>



All times are GMT. The time now is 02:58 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0