Wrox Programmer Forums
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 10th, 2003, 05:38 AM
Authorized User
 
Join Date: Oct 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to code

I have a html file that will ask user
1.what type of graph they would like to view (either bar, line or pie graph)
2.what they would like to view (either sales by category or sales by product)

My question is how am i going to code the php file?Should i put everything about bar, line, pie in a file and use whatever info provided by the user to generate it. or should i code every combination(bar and sales by category, line and sales by category and etc) in different file and link to it according to the option choosen?

could anyone give me suggestion?

 
Old November 10th, 2003, 03:05 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

At the risk of being too high-level, you should generate your database query based on the user input (category or product), and generate the graph chosen by the user.

[code]
<?pseudo-php

// assume that 'graph_by' and 'graph_type' are submitted via GET

if($_GET['graph_by'] == 'category')
{
   $query = "SELECT stuff by category";

   $data = data returned by your select query,
           and in the form that JPGraph expects.
}
else if ($_GET['graph_by'] == 'product')
{
   same as above, only the query returns data by product
}

// now just select the type of graph you want JPGraph to generate
// based on $_GET['graph_type']

?>


Take care,

Nik
http://www.bigaction.org/
 
Old November 12th, 2003, 08:59 AM
Authorized User
 
Join Date: Oct 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks! I follow your advice. But i would like to go a different page for different $_GET['graph_type']. For example
if ($_GET['graph_type']=='barGraph')
      go to page1
else if ($_GET['graph_type']=='lineGraph)
       go to page2
else if ($_GET['graph_type']=='pieGraph)
       go to page3
How am i going to direct user to that particular page without using the <a href="page1.php"> and so on?



 
Old November 12th, 2003, 03:54 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

There are a couple of ways of doing that:

You can include the page directly from the script with the include command. If you want to redirect to a new page you can do that with the header() function.

if ($_GET['graph_type']=='barGraph')
      # go to page1
      header("Location: http://www.somesite.com/some_path/some_page.php");

else if ($_GET['graph_type']=='lineGraph)
      # go to page2
      include("some_page2.php");

else if ($_GET['graph_type']=='pieGraph)
      # go to page3
      include("some_page3.php");

Including a page will bring it into the current script's execution, if the included page contains PHP, which must be delimited with <?php ?>, its variables and the variables of the currently executing script will be as one, mingled and contained in the same namespace and any output from the included file will follow output from the script including it, if any. If you redirect using header() an entirely new request will be made.

http://www.php.net/header
http://www.php.net/include

: )
Rich


:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::





Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent:hard disk serial code and vb code ivanlaw Pro VB 6 0 July 25th, 2007 04:05 AM
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 05:44 AM
code clinic - Why wont example asp code work? jardbf Classic ASP Basics 3 April 27th, 2006 06:22 PM
Writing Client Side Script from Code-Behind code sajid_pk Classic ASP Databases 1 January 18th, 2005 12:53 AM
disable forum code within [code] blocks? nikolai Forum and Wrox.com Feedback 0 October 23rd, 2003 07:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.