Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 02-28-2007, 10:27 AM   #16 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,693
redhead is on a distinguished road
1) The javascript still remains, I've just decided to alter it, so it would fit the namingconvention of the checkboxes, which is needed, in order to access them as an array instead of single variables for each chekbox, since we have no idear how many will be checked, or how many will be provided from how many items there resides in the database, thats why it's easier to use an array structure for this.

2) The ID I'm refering to, is the uniq ID which the "categories" database-table has, which is the indent of which the checkboxes are collected into. And the uniq ID which the "items" database-table has, which is the value of the checckbox, so when the submit button get's pressed I know which category the checked checkboxes resides within, since thats the indent of the returned checkboxes array which holds any values, and I know exactly which items, since the said value it will hold is the uniq ID of the said item. So it's just a matter of fetching that item with a match in ID from the database and I have every bit of info stored according to that item, and the only parsed value is it's ID, whic is exactly what a checkbox would be able to hold as a value.

Quote:
I assume you are calling the "checkbox page" what I call my Order page.
You can call it whatever you like, My page resides in one single file, the info provided from it will dynamicaly change according to it beeing fetched without any submit button pressed, or it containing the form submission result, if it was called with a press of the submit button.
Thats the beauty of PHP, you can make the pages display different contence dictated by the way it is called.
Quote:
enter 001 into the value box in the checkbox properties on the Order page.

That way when the checkbox is checked it will be passed to the Confirmation page which will make a query based on all checkboxes that are checked and return those values?
It seems as if you're getting the picture, the info parsed between your "Order page" and "Confirmation page" is something which is uniq, therefor you will be able to query the database once more, with that uniq request, and expect to get exactly what the viewer wanted in return, since the "Order page" was orriginaly build with that uniq info in mind.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 02-28-2007, 07:03 PM   #17 (permalink)
JMareel
Recruit
 
Join Date: Feb 2007
Posts: 20
JMareel is on a distinguished road
OK where do i try out/insert the two most recent blocks of code you have written in the last reply? Do I insert the first block on the Order page (checkbox page) and the second block of code on the Confirmation page?

I am going to try my hand at writing the code for creating the SQL database. Do I write this code on the Order page or do I have to make a seperate page? Again thanks for your help.

Thanks,
JM
JMareel is offline   Reply With Quote
Old 03-04-2007, 04:59 PM   #18 (permalink)
JMareel
Recruit
 
Join Date: Feb 2007
Posts: 20
JMareel is on a distinguished road
Question

redhead are you waiting for me to work on and add to the code and give you something to work with? I am still trying to get a handle on SQL and PHP so that I can maybe write some code and do some work on my own so I can learn also. But in order to work on it a little myself I need to know where each chunk of code that you wrote (the last post you wrote with code) in the post needs to go. Does the first chunk go in the Order page
Quote:
/* select what we have in the database
.
.
and the next chunk go on the Confirmation page?
Quote:
if(isset($_POST['checkbox'])){
.
.
I decided that once I get this Order page/Confirmation page up and running I will publish my website. This problem is the last one left before I publish my website!

So do I also have to pay you $160/hr to reply to this post?!

Thanks Much,
JM
JMareel is offline   Reply With Quote
Old 03-06-2007, 12:56 AM   #19 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,693
redhead is on a distinguished road
Sorry, for beeing abit absence here.. I've had alot to do lately.
First the SQL is a one time activated part, it will setup two database tables within your database. It dosn't need to be part of any of your other code, if you have shell access to where you run your orderpage from, then you can put that in a fiel all by itself, and submit it to your MySQL like:
Quote:
> mysql -u "your user" -p "your database" < "file with sql code"
And it will be setup for you.
Next is to fill it with some usefull info, this is done by using something like:
Code:
INSERT INTO TABLE categories VALUES ('1', 'my first category');
INSERT INTO TABLE items VALUES ('1', '1', 'first item', 'this is first item within first category');
etc.
This can be submitted into yoru database like you did with the creation of the database-tables. Or it could be performed through some web interface where you'd submit it, or through some export function from some third party software, or how ever it will be formed....

Next onto the code snippits I've shown you, the first part is part of your order-page, it will go through every category in your database, selecting every item that has the appropriate category reference set, in short, it will build your order page to display everything you previusly filled into your database.

The second code-snippit is the part that is to be called when the user press submit in your order-form, this is the contence of your "action=blah.php" file setting in the <form> definition.

If you decide to view the source of my order-page, you will notice the javascript is slightly altered to handle the 2D array style of the checkboxes I'm using.
Now in my solution, I decided to just parse on the name of the items as the value to the checkboxes, but since you want to use additional information, like price, name, etc. in your billing to the consumer, you need to alter my orriginal database-tabel setup, and add a "price" container in the items table, aswell as parse the id of the item as the value within the checkboxes in your order page.
However when I decided to show you the PHP code snippits, I had already taken that into calculation, so it will naturaly do just that.

I hope all of this somehow make sence...
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 03-06-2007, 10:37 AM   #20 (permalink)
JMareel
Recruit
 
Join Date: Feb 2007
Posts: 20
JMareel is on a distinguished road
Well, first of all. No problem in waiting. I understand life throws things our direction that makes everything else take second place. I was joking with you about the $160/hr. because I read in one of your replies to the PHP coder thread

OK I have been doing alot of studying and dabbling at writing SQL to set up the database and tables. It seems pretty easy in setting up the database and writing queries based on what you are looking for. Now what I don't understand is where do I write the SQL code to setup the database and tables of information? I know its server side scripting, so is the SQL code contained in a single file on the server or is it contained on the Order page where the database should be? Can I make a database in Access and have the Confirmation page and/or Order page query that to display whatever info I need to show to the customer on the Confirmation page?

Also, it takes a little while to digest your replies because as I read them I am also learning how things are working. So yes your reply does seem understandable but also confusing at the same time. I have been working on this website off and on for the past 6 months. I have many many many more ideas and features I want to add to this website so hopefully it could turn into a side money venture for me. At the moment I just want to finish the Order page talking to the Confirmation page sending me the order information and payment problem so I can publish the website and at least have it running while I add to it the different features I would like.

So again thanks for all your attention and help. I am trying to do my part by learning and writing some code but it has been a slow process.

Thanks,
JM
JMareel is offline   Reply With Quote
Old 03-06-2007, 12:06 PM   #21 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,693
redhead is on a distinguished road
Quote:
I was joking with you about the $160/hr. because I read in one of your replies to the PHP coder thread
heh, I hadn't even noticed that part of your reply..
I read half way through it, befor I started forming my answer
Quote:
Now what I don't understand is where do I write the SQL code to setup the database and tables of information?
I usualy keep it as a text file on my server, that way I have a way of confirming how my tables are formed, when in 6 month, I want to alter something, instead of quering the database to see what is structured I can look at my text file.

But you could write it interactively into the MySQL interface if you wanted to, or you could use something like phpMyadmin.
The thing is, the database-table structuring, is a one time _only_ activation, so it is very unwise to call it from within any activation where you can't control how many times it will be called.
Quote:
Can I make a database in Access and have the Confirmation page and/or Order page query that to display whatever info I need to show to the customer on the Confirmation page?
Sorry, this can not be done, PHP (as of PHP4) only supports the following databases
Quote:
I have many many many more ideas and features I want to add to this website
Naturaly, it is understandable that you want to develop your site, into something you can be proud of. And I'm sure, once you get a feel for how PHP/SQL interacts, you'll realise the beauty of having dynamicaly created pages.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 03-07-2007, 06:37 AM   #22 (permalink)
JMareel
Recruit
 
Join Date: Feb 2007
Posts: 20
JMareel is on a distinguished road
Angry

OK I am really feeling lost now and uneducated in web coding terms.

I have a couple of questions for you.

1) The .txt file that contains my SQL code that creates and fills up my database should be kept on the server. What is considered the server then? my web site file/folder structure? or the host company's computer I publish and host my web site on?

2) I have been working with trial and error on understanding your code on the example web site you made and on the recent code blocks you wrote. I am feeling really lost in where I need to put your snippets of code and what they do ! Where exactly does
Code:
 /* select what we have in the database, and build the form for submitting */
  $categories = @mysql_query("SELECT * FROM categories ORDER BY id", $DB_LINK);
  while($category = @mysql_fetch_array($categories)){
    $item_count = 1;
    $body .= "<td valign='bottom'><font size='+2'><b>".$category['name']."</b></font> <input type='checkbox' name
='allbox".$category['id']."' onclick=\"checkAll('".$category['id']."');\" /> Check All
      <table border='0' cellspacing='0' cellpadding='0' width='100%' style='border: 1px solid rgb(12, 13, 119);'>
       <tr>
       ";
    $items = @mysql_query("SELECT * FROM items WHERE category=\"".$category['id']."\" ORDER BY id", $DB_LINK);
    while($item = @mysql_fetch_array($items)){
      if(!(($item_count++) %2))
        $body .= "</tr><tr><td valign='top'>
        "; /* only two items valigned within a category */
      else
        $body .= "<td valign='top'>";
      $body .= "<input type='checkbox' value='".$item['id']."' name='checkbox[".$category['id']."][]'><b>".$ite
m['name']."</b><br />
        ".$item['description']."</td>
        ";
    }
I have tried putting this after the head and the body of the Order page (page with tables and checkboxes) seperately and it doesn't seem to produce the desired result. Parts of the code end up showing up on the page.

And where exactly does this go?
Code:
if(isset($_POST['checkbox'])){
/* we were called through the 'submit' button
 * so we build the page accordingly
 */
  $categories = @mysql_query("SELECT id FROM categories ORDER BY id", $DB_LINK);
  $checked = $_POST['checkbox'];
  while($category = @mysql_fetch_array($categories)){
     foreach($checked[$category['id']] as $check){
       $res = @mysql_query("SELECT * FROM items WHERE id='$check'", $DB_LINK);
        while($row = @mysql_fetch_array($res)){
            /* do whatever with what is fetched, name, description, price, etc. */
        }
     }
  }
} 
I am not going to pretend to know something I don't so I am going to just ask outright. Can you put it in simple terms as to where exactly the blocks of code need to go? If I understand where to put them, then maybe I can understand how they are talking with each other and exchanging information. I apologize for maybe sounding so ignorant but this is truely baffling me.

The easiest thing so far that I have taught myself is how to write the code to create the database, insert data, and query data depending on my needs. This PHP and java, although not Chinese, is a little more difficult and added to the fact that the code needs to be inputted into a certain place in the source of the page. I hope I can pay you back one way or the other when I get my website published finally! One last question... would you rather continue this via email or keep it to this thread?

Much Appreciated,
-JM
JMareel is offline   Reply With Quote
Old 03-07-2007, 08:17 AM   #23 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,693
redhead is on a distinguished road
As a cheatsheet, you can watch my page source, but I'd much rather talk you through it..
Naturaly I've let the connect/select of the database out of the file, for security reasons.
  1. The server in question here, is the one you're quering through your mysql_connect() call, when you want to fetch anything from your database.
    That can be several if thats the case, you might have a test server and a public server, then you'll use it on the test server untill you want to go live with it.
  2. For ease, I'll tell what each codeline does in your displayed code-snippits.
    1. Just a comment to keep my thoughts straight through it all
    2. Select every info stored in the categories table of the database
    3. For as long as I can fetch a category row from the collected info
    4. set an internal variable so we know we've began, and therefor can balance the <td></td> to create a purdi view of it all
    5. Build the body of the HTML page, holding the category in question, and the checkAll() selection for that category
    6. Start the table which will hold the items found in current category
    7. Select any item that matches the category we have at hand
    8. For as long as we have an item, fill in the body of the table to reflect it, keeping in mind only to show two items valigned, here the $item_count comes in handy
  3. Second portion of your code-snippits explained
    1. Select every category contained within the categories-table
    2. Get an array of the checked selections on the order page
    3. For as long as theres a category in our stored categories info
    4. Go through every selected item from the order page
    5. Select every item from the items-table that matches the selected checkbox from the order page
    6. For as long as theres any info fetched from the match
    7. Build the body of the page, to display the selected items.
Quote:
I have tried putting this after the head and the body of the Order page (page with tables and checkboxes) seperately and it doesn't seem to produce the desired result. Parts of the code end up showing up on the page.
This is PHP code, it should be kept within correct PHP-tags, so teh server knows to call the PHP-engine to parse it through befor showing it to the viewer.
For PHP3
PHP Code:
<!-- start PHP-tag --><?php 
/* all the code here */
?> <!-- End PHP-tag -->
For PHP4+
PHP Code:
<!-- start PHP-tag --><? 
/* all the code here */
?> <!-- End PHP-tag -->
Quote:
And where exactly does this go?
The first portion goes to build the order page, the second portion goes to build the result page.
Quote:
would you rather continue this via email or keep it to this thread?
Given the fact, that this will bennefit from others chipping in, I would like to keep it in a thread like this, but if it turnes into something which is based on exchanging private information, then it would be more appropriate to switch to mail exchange.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 03-07-2007, 06:40 PM   #24 (permalink)
JMareel
Recruit
 
Join Date: Feb 2007
Posts: 20
JMareel is on a distinguished road
Smile

OK the brief explanation of each line of code and what it does is much better. I was able to go back and forth from your line-by-line explanation to the code and back again to comprehend and work out what the code is telling the page to do and so on. Little by little I guess.

Quote:
The first portion goes to build the order page, the second portion goes to build the result page.
What happens to the Javascript code that you wrote to checkall in each appropriate table? I built the Order page already in Frontpage which is about 9 seperate tables (each table has 3 columns and varied amount of rows so far --> NAME PIC CHECKBOX). What basics I have so far on the Order page is the...
<script Javascript 'checkall' code /script>
9 tables (2 data columns and 1 checkbox column)
Submit button


Maybe I'm just not getting what you mean to build the Order page. Would it be easier if I send you the Order page and Confirmation page that I have done so far?

Thanks for sticking through with me on this and I apologize if I might be fustratingly clueless.

-JM
JMareel is offline   Reply With Quote
Old 03-08-2007, 09:33 AM   #25 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,693
redhead is on a distinguished road
It seems to me, that you're not aware of what part the PHP will take care of, and what part should be kept as strict HTML.
Quote:
What happens to the Javascript code that you wrote to checkall in each appropriate table?
It is still there, specific in the order page.
Quote:
built the Order page already in Frontpage which is about 9 seperate tables (each table has 3 columns and varied amount of rows so far --> NAME PIC CHECKBOX)
This is where the PHP/SQL comes in handy, you have several infos to display, and you want to make sure those are parsed onto the confirmation page aswell. But since you can only send one info through the checkbox type, you somehow need to make all three infos combined as one.
Here the ID tag from the SQL stored data is the most complete solution.
Quote:
Maybe I'm just not getting what you mean to build the Order page. Would it be easier if I send you the Order page and Confirmation page that I have done so far?
I've send you a PM with my email, you can send me your order and confirmation page, then I'll alter them to use the PHP/SQL approach, and you can decide if that would be a better solution.
Quote:
Thanks for sticking through with me on this and I apologize if I might be fustratingly clueless.
It's never easy to start out with an entirely new programming language, especialy not with one like PHP, when you at the same time want to combine it as a web solution with SQL activity.
Everything takes time, getting the structure right, is a major step towards understanding the integrity of the language.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
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

BB 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
JavaScript help - printing prices in html page Rocket HTML, XML, Javascript, AJAX 2 06-21-2005 06:43 AM
Referrencing HTML document mid page with ASP variable joehouse MS Technologies ( ASP, VB, C#, .NET ) 3 06-11-2005 01:16 PM
Craigslist Anonymous Email Relay with PHP & MySQL? oc_earthling PHP 11 03-05-2005 08:10 AM


All times are GMT -8. The time now is 11:32 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting