Jump to content

digibucc

Members
  • Posts

    142
  • Joined

  • Last visited

Posts posted by digibucc

  1. i am the type that learned without books and it's a double-edged sword.

    I immerse myself in things i like, and figure out how they work. i did it with html, css, php, etc. doesn't work so wel once you get out of those languages though ;)

     

    that being said, i KNOW that i don't have as complete an understanding as someone who read and comprehended those books - though many people will read and not comprehend ;)

     

    but once i get to the point where my own experience gives me a solid base (where i am now with php), it makes it much easier to expand my knowledge. i tend to only really ever use the PHP man pages, as that is exactly the kind of info i want. concise, to the point, etc. books and tuts are longwinded and tend to explain concepts i already understand, when i just want one specific piece of information.

     

    that being said, from time to time i go through all levels of tuts, just to be sure it falls in line with my experience, because if something very basic is different from how i'd do it, i have to reconsider :)

  2. Welcome, i'm new here myself :) from US, but a fan of down under :) luckily, that's pretty basic what you want to do.

     

    you would create an html form and style it with css as you know how, then make it's action "submit.php" or whatever you name the php file.

     

    then you make the php script, it would get all of the submitted info via POST and put it in a mysql insert statement.

    something like:

    <?php 
    
    $con = mysql_connect("address","username","password"); // connect to mysql
    if (!$con)
      {
      die('Could not connect: ' . mysql_error()); // or die
      }
    mysql_select_db("dbname", $con); // select database to work with
    
    foreach ($_POST as $key=>$value){ // for EACH posted variable
    if ($value != '' && $value != 'Submit'){ // if it's not empty OR the submit button
    $cols .= mysql_real_escape_string($key). ', '; // escape the key and add it to the cols string
    $vals .= '\''. mysql_real_escape_string($value). '\', '; //escape the value and add it to the vals string
    }
    
    $columns = substr($cols,0,-2); // clean trailing chars
    $values = substr($vals,0,-2); // clean trailing chars
    
    $sql="INSERT INTO table ( $columns )VALUES ( $values )"; // prepare the sql statement, table is your table name
    
    if (!mysql_query($sql,$con)) // attempt to insert
      {
      die('Error: ' . mysql_error()); // if it fails, the script dies, otherwise it continues after the bracket.
      }
    ?>
    
    

     

    that will handle saving it to the mysql db.

     

    then i would make a separate page called view.php, to pull the db entries and display them, like:

     

    <?php
    $con = mysql_connect("address","username","password"); // connect to mysql
    if (!$con)
      {
      die('Could not connect: ' . mysql_error()); // or die
      }
    mysql_select_db("dbname", $con); // select database to work with
    
    $qry = "SELECT * FROM table"; // select everything from the "table" table
    $data = mysql_query($qry) or die(mysql_error()); // save the table into $data, or die
    $entries = mysql_num_rows( $data ); // count the number of rows , if you need to know for display purposes
    
    while ($info = mysql_fetch_assoc( $data )) {  // this is a loop, that takes each row and saves it to the info variable. so you can call your field names (eg 'address') as $info['address']
    //whatever you put here will happen for each row. so you can echo out each column, you can make an html table and lay them out, etc. up to you.
    }
    ?>
    

  3. you have nothing in there to check whether the $latest_projects is in the category you want. i assumed it was only calling posts from that category.

     

    so you have a foreach category loop, which runs twice for the two categories.

    and then you have a foreach post loop, which loads all the  $latest_projects, regardless of whether they match the category you are on in the foreach category loop.

     

    i'ts late so im done for the night, but if you want i'll help some more tomorrow.

     

    basically you need to write in if statement that checks to be sure the current post(image) is in the current category.

     

     

    so with:

    <ul id="portfolio-list">
    <?php 
    $categories = get_terms('gallery_cats');
    foreach ($categories as $cat ) :  
    foreach($latest_projects as $post) :
    // get the about post's category/taxonomy, and make sure it matches the current category in $cat, from your foreach loop above.
    setup_postdata($post);
    $recent_project_thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'recent-work');
    ?>
    
    <li><a href="https://ivyvintage.com/gallery-category/<?php echo $cat->slug; ?>" title="<?php the_title(); ?>"><img src="<?php echo $recent_project_thumb[0]; ?>" alt="<?php the_title(); ?>" width="162" height="100" class="imgstyle" /></a></li>
    
    <?php endforeach; ?>
    <?php endforeach; ?> 
    
    </ul>

     

    right now it's running the category loop twice as there is two categories, and putting the pic twice because there are two products total. you need it to only show a pic if it matches the current category in your foreach category as cat loop.

  4. because the session is only setting one products info

     

    that will only pass one products info to the next page

    <?php
    foreach($_POST["product"] AS $key => $val) {
    $_SESSION['product'] = $val;
    $_SESSION['month'] = $_POST['month'][$key];
    $_SESSION['day'] = $_POST['day'][$key];
    $_SESSION['year'] = $_POST['year'][$key];
    $_SESSION['date'] = $_POST['date'][$key];
    $_SESSION['price'] = $_POST['price'][$key];
    $_SESSION['qty'] = $_POST['qty'][$key];
    $_SESSION['id'] = $_POST['id'][$key];
    $_SESSION['total'] = $_POST['total'][$key];
    $_SESSION['academy'] = $_POST['academy'][$key];
    $_SESSION['priceunit'] = $price * $qty;
    }
    ?>
    

     

    you'd need a counter ans something like

     

    <?php
    $x = 1;
    foreach($_POST["product"] AS $key => $val) {
    $_SESSION[$x]['product'] = $val;
    $_SESSION[$x]['month'] = $_POST['month'][$key];
    $_SESSION[$x]['day'] = $_POST['day'][$key];
    $_SESSION[$x]['year'] = $_POST['year'][$key];
    $_SESSION[$x]['date'] = $_POST['date'][$key];
    $_SESSION[$x]['price'] = $_POST['price'][$key];
    $_SESSION[$x]['qty'] = $_POST['qty'][$key];
    $_SESSION[$x]['id'] = $_POST['id'][$key];
    $_SESSION[$x]['total'] = $_POST['total'][$key];
    $_SESSION[$x]['academy'] = $_POST['academy'][$key];
    $_SESSION[$x]['priceunit'] = $price * $qty;
    $x++;
    }
    ?>
    

     

    then session will save a multidimensional array, which will hold all the relevant info for each product counted in the foreach loop. right now they are being overwritten because they are all being saved to same session variable. ie when it processes product 3 it overwrites what it had for 2, as there is only one 'academy" variable in that session array. adding $x and a counter adds another dimension to the array, so it can save those individually

  5. this?

     

    <ul id="portfolio-list">
    <?php 
    $categories = get_terms('gallery_cats');
    foreach ($categories as $cat ) :  
    foreach($latest_projects as $post) : 
    setup_postdata($post);
    $recent_project_thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'recent-work');
    ?>
    
    <li><a href="https://ivyvintage.com/gallery-category/<?php echo $cat->slug; ?>" title="<?php the_title(); ?>"><img src="<?php echo $recent_project_thumb[0]; ?>" alt="<?php the_title(); ?>" width="162" height="100" class="imgstyle" /></a></li>
    
    <?php endforeach; ?>
    <?php endforeach; ?> 
    
    </ul>

  6.            

    <form name="pay" class="pay" method="POST" action="collect.php">
        <p>
            <?php if ($total == ""){$total = "0";} ?>
            <?php echo "$".$total.""; ?>
            <?php
    // Query member data from the database and ready it for display
            $sql = mysql_query("SELECT * FROM cart where cart_id = ".$_SESSION['cart_id']." && product123 !=''");
            while($row = mysql_fetch_array($sql)){
                $product = $row["product123"];
                $price1 = $row["price"];
                $id = $row["product_id"];
                $qty = $row["quantity"];
    
    
    
                $month = date("F Y");
                $day = date("d");
                $year = date("Y");
                $date = date("Y-m-d");
                ?>
    <input name="product[]" type="hidden" value="<?php echo $product; ?>" />
    <input name="academy[]" type="hidden" value="<?php echo $academy; ?>" />
    <input name="month[]" type="hidden" value="<?php echo $month; ?>" />
    <input name="day[]" type="hidden" value="<?php echo $day; ?>" />
    <input name="year[]" type="hidden" value="<?php echo $year; ?>" />
    <input name="date[]" type="hidden" value="<?php echo $date; ?>" />
    <input name="price[]" type="hidden" value="<?php echo $price1; ?>" />
    <input name="id[]" type="hidden" value="<?php echo $id; ?>" />
    <input name="qty[]" type="hidden" value="<?php echo $qty; ?>" />
    <input name="total" type="hidden" value="<?php echo $total; ?>" />
    
    <?php
            }
            ?>
            <?php if ($total == " "){$total = "0";} ?><input type="submit" name="pay" id="pay" class="pay1" value="" />
        </p>
    </form>
    
    

     

    simply setting your name to academy[], wont add it to an array. you are still in html code.

     

    something like:

     

    <form name="pay" class="pay" method="POST" action="collect.php">
        <p>
            <?php if ($total == ""){$total = "0";} ?>
            <?php echo "$".$total.""; ?>
            <?php
    // Query member data from the database and ready it for display
            $sql = mysql_query("SELECT * FROM cart where cart_id = ".$_SESSION['cart_id']." && product123 !=''");
            $productnumber = 1; // set a counter for the products
            while($row = mysql_fetch_array($sql)){
                $product = $row["product123"];
                $price1 = $row["price"];
                $id = $row["product_id"];
                $qty = $row["quantity"];
    
    
    
                $month = date("F Y");
                $day = date("d");
                $year = date("Y");
                $date = date("Y-m-d");
                ?>
    
                <input name="product<?php echo $productnumber; ?>" type="hidden" value="<?php echo $product; ?>" />
                <input name="academy<?php echo $productnumber; ?>" type="hidden" value="<?php echo $academy; ?>" />
                <input name="month<?php echo $productnumber; ?>" type="hidden" value="<?php echo $month; ?>" />
                <input name="day<?php echo $productnumber; ?>" type="hidden" value="<?php echo $day; ?>" />
                <input name="year<?php echo $productnumber; ?>" type="hidden" value="<?php echo $year; ?>" />
                <input name="date<?php echo $productnumber; ?>" type="hidden" value="<?php echo $date; ?>" />
                <input name="price1<?php echo $productnumber; ?>" type="hidden" value="<?php echo $price1; ?>" />
                <input name="id<?php echo $productnumber; ?>" type="hidden" value="<?php echo $id; ?>" />
                <input name="qty<?php echo $productnumber; ?>" type="hidden" value="<?php echo $qty; ?>" />
                <input name="total" type="hidden" value="<?php echo $total; ?>" />
    
                <?php
                $productnumber ++; //increase the product number counter
            }
            ?>
            <?php if ($total == " "){$total = "0";} ?><input type="submit" name="pay" id="pay" class="pay1" value="" />
        </p>
    </form>
    

     

    that way you'll have multiple hidden boxes for EACH product, whereas no you only have one set, which gets overwritten with additional products.

     

    but then you'll  receive a bunch of names like product1, product2, product3 etc . that can be dealth with but you want it dynamic so it will scale. in one of my more recent posts i walked someone through something similar. it involved counting all the session elements, dividing that by the number in each set (ie 9 for you, or 10 if you count total for each product - otherwise subtract 1 for total)

     

    and using that number of sets you now have, you can insert multiple values into mysql at once

     

    like:

    INSERT into table (product,academy, month) VALUES ('product1', 'academy1' 'month1'), ('product2', 'academy2' 'month2').

     

    and using a counter you can have that done automatically. as i said it's in one of my recent posts.

     

    it's late so im done for the nite, ill check back on it tomorrow though. good luck.

  7. try this:

    <ul id="portfolio-list">
    <?php 
    foreach($latest_projects as $post) : setup_postdata($post);
    $recent_project_thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'recent-work');
    ?>
    
    <?php $categories = get_terms('gallery_cats'); foreach ($categories as $cat ) : ?>   
    
    <li><a href="https://ivyvintage.com/gallery-category/<?php echo $cat->slug; ?>" title="<?php the_title(); ?>"><img src="<?php echo $recent_project_thumb[0]; ?>" alt="<?php the_title(); ?>" width="162" height="100" class="imgstyle" /></a></li>
    
    <?php endforeach; ?>
    <?php endforeach; ?> 
    
    </ul>
    

  8. are there any more loops in may be inside of?

     

     

    as this stands:

    
    <?php
    include_once("connect.php");
    session_start();
    foreach($_SESSION AS $key => $val) {
        $$key = $val;
    }
    session_destroy();//small change, vars were made so no need to keep it open to to do the insert
    
    
    $sql = "INSERT INTO transactions (price, product, quantity, product_id, priceunit, month, day, year, academy, date) 
    VALUES('$priceunit', '$product', '$qty', '$id', '$price', '$month', '$day', '$year', '$academy', '$date' )";
    $rs = mysql_query($sql) or die ("Problem with the query: $sql <br />" . mysql_error());
    
    
    
    
    $sql = mysql_query("SELECT * FROM cart");
    while($row = mysql_fetch_array($sql)){
        $cid = $row["cart_id"]+1;
        $_SESSION['cart_id'] = $cid;
    
    
    }
    ?>
    

     

     

    it should be performing one insert. i can't tell you why it's inserting so many, and then missing info on some, etc. that is very odd and i'd need additional before and after code to help more.... sorry.

  9. so there are two different things here. something i sup with your syntax, and the session isn't passing the additional products.

     

    the picture shows exactly what it is doing.

    it looks like multiple attempts each with different results, i am just trying to confirm every entry in that picture came from one insert. by that i would mean empty the table, try one insert, and post that result, if that's is what that picture is ... that's way different.

  10. i'm sorry what exactly do you mean upping the number? can i see your next page link code?the foreach doesn't actually track the postition

     

     

    so instead of:

    while($fetch = mysql_fetch_assoc($query)){echo $position++.' '.$fetch['username'];}

    do:

    <?php
    $position = 1 ;
    while($fetch = mysql_fetch_assoc($query)){echo $position.' '.$fetch['username'];
    $position ++;} 
    ?>

     

    that way position will actually keep track of the current position, rather than just echoing it.

  11. not a problem, i did that for a reason though -

            [/color]var_dump[/color]([/color]$recent_project_thumb[/color][[/color]0[/color]]);

    [/color]&

            [/color]var_dump[/color]([/color]$categories[/color]);

    [/color]

    should print out a bunch of text --- but it's inside a ul so it won't do that ;) i missed that part.

     

     

    if you could copy the page source of that, or at least the relevant part where the elements were dumped. that will help me know how to construct the category foreach.

    on a side not, is there a reason you re doing this:

    [/color]$recent_project_thumb[/color][[/color]0[/color]] = [/color]wp_get_attachment_image_src[/color]([/color]get_post_thumbnail_id[/color](), [/color]'recent-work'[/color]);

    instead of this:

    [/color]$recent_project_thumb[/color] = [/color]wp_get_attachment_image_src[/color]([/color]get_post_thumbnail_id[/color](), [/color]'recent-work'[/color]);

    [/color]

    in other words, does $recent_project_thumb need to be an array? the [0] is setting it as the first element in array.

  12. you've got to pass that end position to the new page as it's start

    so on the link to move to the next age, add

     

    ?position=$position

    so that it will put whatever the current position is there, with your link code i can be more specific

     

     

    and then on the subsequent pages, you want to first make sure position isn't being set to 1, but also make sure it is being set to whatever the end position was

     

    so in the beginning

    <?php
    $position = $_GET['position'];
    ?>
    

     

     

    if all you need is the position, that's great. but if you need more info you may consider saving it to a session or a db. or passing a serialized array, which is my preferred quick and dirty method.

  13. so from a blank table, you run that and it inserts it 7 times and then a blank row?

     

     

    and what i'm asking is if that session variable should have info on more than one product.

    regardless of what it is doing, what should it do should it pass the info for one product at a time, exactly what that session var shows when dumped - or should there be more products there?

     

     

  14. i think they mean this:

     

     

    <?php
    $id = 1;
    $query = "SELECT * FROM products WHERE id = mysql_real_escape_string($_POST['id'])"; 
    //or even 
    $query = 'SELECT * FROM products WHERE id = '. mysql_real_escape_string($_POST['id']); 
    ?>
    

     

    the index is the value key in an array you are trying to pull,in this case "id" from the $_POST array

    RIGHT = $_POST['id']

    WRONG = $_POST[id]

     

     

    id - assumed 'id'  says it all, it expected quotes around the word

     

     

  15. what does this return:

     

    <ul id="portfolio-list">
        <?php
        foreach($latest_projects as $post) : 
            setup_postdata($post);
            $recent_project_thumb[0] = wp_get_attachment_image_src(get_post_thumbnail_id(), 'recent-work');
            $categories = get_terms('gallery_cats');   
            var_dump($recent_project_thumb[0]);
            var_dump($categories);
            ?>
                <li><a href="http://wwww.google.com" title="Google"><img src="#" alt="#" width="162" height="100" class="imgstyle" /></a></li>        
            <?php endforeach; ?>
    </ul>
    

  16. you could make a separate include file with an array instead, and just update values in that. then include it, and have it's unique id match the id in the table

     

     

    so in a separate file

    <?php
    
    
    $products = array (
    '432'=>array('price'=>'5', 'description'=> 'more info...') ,
    '433'=>array('price'=>'17', 'description'=> 'less info...')
    );
    ?> 

     

     

    or you could make the option value a serialized array, and then just unserialize it after it's been submitted

  17. they're saying to create a mysql db

    have a table with products in it

     

     

    id    | price  | description | whatever

    432 | 34.00 |  trinket    | extra info..

     

     

    and so your input would just be

     

    <select name="buyit">

    <option value="432">Trinket</option>

    </select>

     

    then before submitting your code, get the price from the database:

     

    <?php
    include('mysqlconnect.php');
    $sql = 'GET * from table WHERE id ='. mysql_real_escape_string($_POST['buyit']);
    ?>
    
    
    <script type="text/javascript">	$(document).ready(function(){		$(".myform1").validate({			debug: false,						submitHandler: function(form) {				// do other stuff for a valid form				$.post('process.php', $(".myform1").serialize(), function(data) {					$("#price").load("index.php #price");$("#total").load("index.php #total");				});			}		});	});	</script>  
    
  18. var dump session before the foreach, like this:

    <?php 
    
    include_once("connect.php");
    session_start();
    
    
    
    
    var_dump($_SESSION);
    
    
    foreach($_SESSION AS $key => $val) {
        $$key = $val;
    }
    ?>

     

     

    do you see all you would expect there, or just one record? copy and past the var_dump result

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.