LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-15-2005, 08:09 AM   #1
xemous
Member
 
Registered: Jun 2004
Location: Australia, Melbourne.
Distribution: Ubuntu
Posts: 80

Rep: Reputation: 15
MySQL results to html forms using PHP


Hi,

I have a problem

I have a database filled with books, their ISBN's publishers and titles, and so forth

I use this code to browse the books on my website,

Code:
$query = "select * from books";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result))
{
echo "<hr>";
echo "<br><b>ISBN:</b>$row[0]";
echo "<br><b>Title:</b>$row[1]";
echo "<br><b>Author:</b>$row[2]";
echo "<br><b>Publisher:</b>$row[3]";
echo "<br><b>RRP:</b>$row[4]";
echo "<br><b>Description:</b>$row[5]";
}
That gives me a full list, but what I need to do is enable the user to select books and post his selections to another script, which will of course tally the prices and load the info into a database for checkout

The solution I've come up with (if theres a better and easier way please tell me) is to somehow dynamically take this info and load it into a form (into the <input tages>, and lock all the form attribuates and add a quantity attribute the user can edit, and then post this info over to the checkout.php script

But the problem is I have no idea how to take this information from the databae and load it into a form, and how to somehow get php to dynamically create <input tags> one after the other as they are needed for how ever many books are searched or browsed in the database

So if anyone knows where to look next, (two books on php and sql and a html book plus php.net and a google I cant find anyone with a similar probem) please post some urls or code examples

Cheers !

Last edited by xemous; 08-15-2005 at 08:14 AM.
 
Old 08-15-2005, 09:19 AM   #2
xemous
Member
 
Registered: Jun 2004
Location: Australia, Melbourne.
Distribution: Ubuntu
Posts: 80

Original Poster
Rep: Reputation: 15
Just posting a update to my problem, i manage to get the <input tags> working

I just
Code:
echo "<br><b>Quantity:</b><input name=\"quantity\" size=\"3\" value=\"0\">";
echo "<b>Price:</b><input type=\"text\" name=\"price\" size=\"3\" value=\"$row[4]\">";
I'll write a function or Jscript that will multiple the quantity by the price, but now, when I submit the force to my cart.php, I echo the price to see what was submitted, and of course it only displays the last price. How can I somehow make a dynamically generated unique name in the ``name=\"$thespecialuniquename\"''; per queried book in the database, and also, use the same method to declare those unique dynamically generated variables on my the cart.php page, so I can capture all the data and add them together.

Sorry for any confusion, if you guys know a better way to do this It would be great if you can post it.

Cheers.
 
Old 08-15-2005, 10:09 AM   #3
xemous
Member
 
Registered: Jun 2004
Location: Australia, Melbourne.
Distribution: Ubuntu
Posts: 80

Original Poster
Rep: Reputation: 15
I have found a solution, I'll try using a some javascript to add up the costs of each item, I hope the Jscript will work while its imbedded in a php tags? If not I'm back to square one.

//update

Yes, Jscript is embeddable in php tags

Last edited by xemous; 08-15-2005 at 10:14 AM.
 
Old 08-15-2005, 04:27 PM   #4
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Use PHP all the way through. You can setup a session array with the variable stuff in it and fill your input fields from it. I'd show you my website that does something similar, but it's company-private and password only access.

BTW, in your input tags echo()s use single quotes for the echo()ed string, then you don't have to escape all the inner double-quotes. You'll have to do some fancy quoting if you're trying to embed variables, of course!

Last edited by eddiebaby1023; 08-15-2005 at 04:29 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
passing an array from html-forms to php prabhatsoni Linux - Software 2 06-04-2005 01:11 AM
PHP: changing row color showing mysql results emilioestevezz Programming 15 09-13-2004 07:27 PM
HTML, PHP, forms, submitting data Problem Silent1 Programming 3 08-31-2004 04:03 PM
HTML, PHP, MySQL sets Robert0380 Programming 5 09-03-2003 06:09 PM
PHP & MySQL, working, and yet getting a blank results page linxtc Programming 5 08-24-2003 05:51 PM


All times are GMT -5. The time now is 09:47 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration