LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   MySQL results to html forms using PHP (https://www.linuxquestions.org/questions/programming-9/mysql-results-to-html-forms-using-php-353399/)

xemous 08-15-2005 07:09 AM

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 !

xemous 08-15-2005 08:19 AM

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.

xemous 08-15-2005 09:09 AM

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

eddiebaby1023 08-15-2005 03:27 PM

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!


All times are GMT -5. The time now is 12:02 AM.