Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   PHP (https://www.askmehelpdesk.com/forumdisplay.php?f=454)
-   -   Create a shopping cart and a log book in php with mysql (https://www.askmehelpdesk.com/showthread.php?t=100281)

  • Jun 11, 2007, 05:33 AM
    memory
    Create a shopping cart and a log book in php with mysql
    Please help!


    I am in a dilema. I have just started learning php; I am developing a website for an IT firm and I nid to add a shopping cart and a log book but I am not sure how. I have never done that in any other language, so am so blank. I can do the tables in mysql, but how do I link it with php?

    What I really need is at least a simple but working script/ code which I can understand.

    I will really appreciate.
  • Aug 7, 2007, 07:27 AM
    retsoksirhc
    I prefer to use arrays to interact with a mysql database from PHP.

    Once you have the tables created, you can do all the logging and editing from the php script


    <?php
    //First you need to connect
    mysql_connect("hostname","username","password");

    //Then, select the database you want to use
    mysql_select_db("mydatabasename");

    //Then the queries. Here's one to add
    mysql_query("INSERT INTO tablename ('fieldname1','fieldname2') VALUES ('value1','value2')");

    //Or you can gather information. This gets a bit tricky
    $query=mysql_query("SELECT * FROM tablename");
    while($row=mysql_fetch_row($mysql_query)){
    echo($row['fieldname1'] . " is the value of field1. The value of field2 is " . $row['fieldname2'] . "<br>");
    }
    ?>

    In that last part, we use the variable $query to store out query, and then we use the while loop to get each row that coem out of the query. This works because we use while($row=mysql_query($query)), and as long as there is more information we haven't seen yet in the query, it returns a value. Once we've gotten all the information, the mysql_fetch_row function will return FALSE, and the while loop will end. So, getting each row one at a time in a loop, we can do whatever we want with the data. Whatever the names of your fields are, you can use in the $row array.
  • Oct 31, 2007, 10:49 AM
    vingogly
    There's a full-blown shopping cart example with all the code needed in PHP and MySQL Web Development. Don't recall if there's anything in there like a logbook, but if you can master the shopping cart I suspect the logbook will be a piece of cake. :-)

    Vasily
  • Jan 4, 2008, 02:46 PM
    interinfinity
    Go to barnes and noble. They have entire books full of ecommerce applications for php. I just recently bought 2 myself. Also Google search open source versions for php shopping carts, or entire ecommerce solutions. You can get a lot of ideas and tweak code to be custom for the site you are building

  • All times are GMT -7. The time now is 07:41 PM.