Jump to content

cinek

Members
  • Posts

    53
  • Joined

  • Last visited

Everything posted by cinek

  1. I'm trying to update the total price every time a user adds a new item to the basket or adds an existing item which increases the quantity. This is what I have right now: for($i = 1; $i <= $size2; $i++){ //echo table $get_product_name = 'SELECT * FROM products WHERE product_id = "'. $_SESSION['cart'][$i]['productID'] . '"'; $get_name_query = mysql_query($get_product_name); while ($row = mysql_fetch_array($get_name_query)){ if($check_page != "basket"){ echo "<tr>"; echo "<td class='left'>" . $_SESSION['cart'][$i]['qty'] . "x <a href='index.php?category=" .$row['type_id'] . "&product_id= " . $row['product_id'] . "'>" . $row['product_name_short'] . "</a></td>"; echo "<td class='right'><h4> £" . $row['product_price'] . "</h4></td>"; echo "</tr>"; } else { echo '<tr>'; echo '<td>'; echo '<img src="pictures/' . $row['product_id'] . '/thumb1.jpg" alt="product"/>'; echo '<a href="index.php?category'. $row['type_id'] . '&product_id=' . $row["product_id"] . '"><h4>' . $row["product_name_short"] . '</h4></a>'; echo '<form action="' . $current_url . '" method="post">'; echo '<label>£'. $row["product_price"] . '</label>'; echo '<input type="text" value="1" maxlength="2" name="quantity"/>'; echo '<input type="hidden" value="' . $row["product_id"] . '" name="product"/>'; echo '<input type="hidden" value="' . $row["product_price"] . '" name="product_price"/>'; echo '<input type="submit" value="Update"/>'; echo '</form>'; echo '</td>'; echo '</tr>'; } if(!isset($total)){ $total = $row['product_price']; } else { $total += ($row['product_price'] * $_SESSION['cart'][$i]['qty']); } } it only works for the last item that was added to the basket edit: nvm sorted
  2. thanks, I'm using your loop now, this is what I have: if(isset($_SESSION['cart'])){ if($get_product_id == ""){ echo "nothing here <br />"; } else { $idx = -1; foreach($_SESSION['cart'] as $i => $cartItems) { if($cartItems['productID'] == $get_product_id) { $idx = $i; break; } } if ($idx == -1) { // not found $_SESSION['cart'][] = array( "qty" => $get_product_quantity, "price" => $get_product_price, "productID" => $get_product_id ); echo "new item <br />"; } else { // found at $_SESSION[$idx] $_SESSION['cart']['qty'][$idx] =+1; } } } else { //create new session $_SESSION['cart'][] = array( "qty" => $get_product_quantity, "price" => $get_product_price, "productID" => $get_product_id ); echo "new session <br />"; } but the quantity still doesn't increase adding a new product: Array ( [0] => Array ( [qty] => [price] => [productID] => ) [1] => Array ( [qty] => 1 [price] => 10 [productID] => 2 ) ) adding the same product again: Array ( [0] => Array ( [qty] => [price] => [productID] => ) [1] => Array ( [qty] => 1 [price] => 10 [productID] => 2 ) [qty] => Array ( [1] => 1 ) ) and when I add another product to the basket I get this error: [b]Notice[/b]: Undefined index: productID on line 126 which is: if($cartItems['productID'] == $get_product_id) nvm fixed it: if(isset($_SESSION['cart'])){ if($get_product_id == ""){ echo "nothing here <br />"; } else { $idx = -1; foreach($_SESSION['cart'] as $i => $cartItems) { if($cartItems['productID'] == $get_product_id) { $idx = $i; break; } } if ($idx == -1) { // not found $_SESSION['cart'][] = array( "qty" => $get_product_quantity, "price" => $get_product_price, "productID" => $get_product_id ); echo "new item <br />"; } else { // found at $_SESSION[$idx] $_SESSION['cart'][$idx]['qty']++; //$_SESSION['cart']['qty'] + 1;; echo $idx . "<br />"; echo "trying to increase value <br />"; } } } else { //create new session $_SESSION['cart'][] = array( "qty" => $get_product_quantity, "price" => $get_product_price, "productID" => $get_product_id ); echo "new session <br />"; }
  3. this is what I have right now $i = $_COOKIE['someCount']; echo "value of cookies " . $i . "<br />"; if(isset($_SESSION['cart'])){ //check if product exists $arrayLength = count($_SESSION['cart']); //check if anything is passed if($get_product_quantity == ""){ echo "nothing here <br />"; echo $get_product_quantity; } else { while ($i <= $arrayLength){ //check if product exists if($_SESSION['cart'][$i] == $get_product_id){ $_SESSION['cart'][$i]['qty'] +=1; echo "<br />trying to increase value <br />"; //break; } else { //else create new array entry $_SESSION['cart'][$get_product_id] = array( "qty" => $get_product_quantity, "price" => $get_product_price ); echo "new item <br />"; } //increase cookie value setcookie("someCount", $_COOKIE['someCount']+1, time()+3600); echo $arrayLength ." arr"; if($i > $arrayLength) break; } } } else { //create new session $_SESSION['cart'][$get_product_id] = array( "qty" => $get_product_quantity, "price" => $get_product_price ); echo "new item <br />"; } //ammend //setcookie("someCount", $_COOKIE['someCount']+1, time()+3600); print_r($_SESSION['cart']); nothing is added to the array and it keeps going through the loop adding stuff like mad - not sure where the issue is edit: I've added a break statement which seems to have fixed it. The only issue now is that the quantity is not increased if the item already exists in the array $i = $_COOKIE['someCount']; echo "value of cookies " . $i . "<br />"; if(isset($_SESSION['cart'])){ //check if product exists $arrayLength = count($_SESSION['cart']); //check if anything is passed if($get_product_quantity == ""){ echo "nothing here <br />"; echo $get_product_quantity; } else { while ($i <= $arrayLength){ //check if product exists if($_SESSION['cart'][$i] == $get_product_id){ $_SESSION['cart'][$i]['qty'] +=1; echo "<br />trying to increase value <br />"; break; } else { //else create new array entry $_SESSION['cart'][$get_product_id] = array( "qty" => $get_product_quantity, "price" => $get_product_price ); echo "new item <br />"; break; } //increase cookie value //setcookie("someCount", $_COOKIE['someCount']+1, time()+3600); echo $arrayLength ." arr"; if($i > $arrayLength) break; } } } else { //create new session $_SESSION['cart'][$get_product_id] = array( "qty" => $get_product_quantity, "price" => $get_product_price ); echo "new item <br />"; }
  4. I'm trying to store data with sessions. Every time a user clicks add to cart button the session should be updated with the quantity, price and product id this is what I have right now <?php//manage basket $get_product_id = @$_POST['product']; $get_product_price = @$_POST['product_price']; $get_product_quantity = @$_POST['quantity']; session_start(); //check if session exists if(isset($_SESSION['cart'])){ //scan all session values foreach($_SESSION['cart'] as $cartItems){ //check if product is already in the basket echo "scanning <br />"; if(@$cartItems['productID'] == $get_product_id){ //if product exists increase quantity $cartItems['qty']++; echo "increased <br />"; break; } else { //no duplicates - new item added $_SESSION['cart'][] = array( "qty" => $get_product_quantity, "productID" => $get_product_id, "price" => $get_product_price ); echo "new item <br />"; } break; } } else { //if session doesn't exist - create one $_SESSION['cart'][] = array( "qty" => $get_product_quantity, "productID" => $get_product_id, "price" => $get_product_price ); echo "new session <br />"; } print_r($_SESSION); // session_destroy(); can someone help me out with checking if the product is already in the array?
  5. I'm trying to save 3 values in 1 field in a text file. Each line in the textfile corresponds to a different div (different information). The data in the last field looks like this " 0 3 8". This should correspond to the image name (0.jpg etc). I'm trying to explode this by using: //Explode slider array $sliderContents[] = explode(" ", $sliderArray); I then try to echo it so that every loop itteration has the correct value - from the text file foreach ($sliderContents as $slider => $value){ echo '<img id="'.$directoryName.'-'.$slider.'" src="projects/'.$directoryName.'/'.$directoryName.'-'.$slider.'.jpg" alt="'.$directoryName.'-'.$slider.'" />'; //break; } but this does not work. All it does is, it runs once, twice, 3 times, 4 times, 5 times. It doesn't seem to be using the info from the text fileany ideas what's wrong?I tried using $value instead of slider - but its coming up as "Array" :)edit: if all I put in the field is 0 - to make the image 0.jpg appear - and try to print_r it, this is what I get: Array ( [0] => [1] => 0 ) [3] => Array ( [0] => [1] => 0 ) [4] => Array ( [0] => [1] => 0 ) )
  6. cinek

    combine 2 variables

    thanks a lot got it working
  7. cinek

    combine 2 variables

    basically I need to get an image height of all divs which go through a loop. I count the no of times the loop goes around - and save it to $var2. The height of the image, is set in var $heightnow, to be able to use this, I need to create a 3rd variable $var3 and combine the name $var3 with the data from $var2so e.g. loop goes around once = $imageHeight1 = $heighttwice = $imageHeight2 = $height (new var $imageHeight + data from $var2 =old var $height)etc etc
  8. cinek

    combine 2 variables

    is it possible to combine 2 variables into one?I want a value of 1 variable and a value of 2nd variable, combined into 1 variable name which should contain a 3rd variableI tried this, but it doesn't work ;/$var1.$var2 = $var3
  9. this is what I get:(all warnings) firebug isn't showing any errors
  10. I'm trying to use the simpleslide plugin, but it doesn't seem to work. 1 it doesn't move to the next image at all. It also is not displaying the next & previous arrows. I have no idea what's wronghere's my htmlbtw the a.js file contains the plugin code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script><script type="text/javascript" src="a.js"></script><script type="text/javascript">$(document).ready( function(){ simpleSlide(); });</script></head><body><h1>Gallery 1</h1><div class="simpleSlide-window" rel="1"> <div class="simpleSlide-tray" rel="1"> <div class="simpleSlide-slide" rel="1" alt="1"> <img src="someimage"> </div> <div class="simpleSlide-slide" rel="1" alt="2"> <img src="someimage"> </div> <div class="simpleSlide-slide" rel="1" alt="3"> <img src="someimage"> </div> </div></div> </body></html> I've added the arrow divs, but it still doesn't work. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script><script type="text/javascript" src="a.js"></script><script type="text/javascript">$(document).ready( function(){ simpleSlide(); });</script><style>body { background: black; }.simpleSlide-window { margin: auto; }.left-button {background:url(../garski.net/dodatki/michal/poprzedni-1.png) no-repeat; }.right-button { background:url(../garski.net/dodatki/michal/nastepny-1.png) no-repeat; }</style></head><body><h1>Gallery 1</h1><div class="left-button" rel="group"> </div><div class="simpleSlide-window" rel="1"> <div class="simpleSlide-tray" rel="1"> <div class="simpleSlide-slide" rel="1" alt="1"> <img src="1.jpg"> </div> <div class="simpleSlide-slide" rel="1" alt="2"> <img src="2.jpg"> </div> <div class="simpleSlide-slide" rel="1" alt="3"> <img src="0.jpg"> </div> </div> </div> <div class="right-button" rel="group"></div></body></html> if I put images in the divs, it doesn't help either, the images are not clickable at all
  11. yeah, I've been trying to use the easy slider plugin. Had a few issues. Managed to fix a few
  12. does anyone know if there is a jquery image gallery/slider plugin that can be used multiple time on one page?
  13. cinek

    array/loop/config help

    nvm that - I managed to get the accual values to show up - now I face another problem. The loop doesn't seem to be doing its job. It seems to be increasing with every echo. So if I want to echo 3 images - image 1,2,3 from the first project, I can't - it's showing only one image. It's showing 2 images from project 2 - even tho I only want it to display one. Showing 3 images from project 3 - even tho I only want to display one - etc etc etcany ideas what's wrong?this is what I have now <?php// Get file contents $file = "config.txt"; $lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $contents = array(); foreach($lines as $line) { $contents[] = explode(';', $line); } while($index < $end) { if (isset($contents[$index])) { // declare vars for file fields $no = $contents[$index][0]; $directoryName = $contents[$index][1]; $agencyLink = $contents[$index][2]; $agency = $contents[$index][3]; $siteLink = $contents[$index][4]; $linkName = $contents[$index][5]; $slideImg = $contents[$index][6]; //check if there's more then 1 image in the directory $files = array(); $dir = opendir("projects/$directoryName"); // if dir doesn't exist; break if(!$dir) { echo "Problem opening dir"; break; } // explode slider image config field $slideSettings[] = explode(" ", $slideImg); //scan for multiple files in project folders $n = 0; while(($file = readdir($dir)) !== false) { if($file !== '.' && $file !== '..' && !is_dir($file)) { $files[] = $file; $n++; } } $id = $_GET['id']; if(!isset($id)) { // echo data back to the site - prepare for slider plugin echo '<div class="content">'; echo "\n"; echo '<ul>'; echo "\n"; foreach ($slideSettings as $slide => $value){ echo '<li><img id="'.$directoryName.'-'.$slide.'" src="projects/'.$directoryName.'/'.$directoryName.'-'.$slide.'.jpg" alt="'.$directoryName.'-'.$slide.'" /></li>'; //break; } echo "\n"; echo '</ul>'; echo "\n"; echo '<div class="projectInfo">Agency: <a href="'.$agencyLink.'"><span>'.$agency.'</span></a>'; echo 'WWW: <a href="'.$siteLink.'"><span class="'.$linkName.'">'.$linkName.'</span></a></div>'; // if there's > 1 image display see more if($n > 1) { echo '<a href="?page='.$page.'&id='.$no.'"><img class="more" src="images/see_more.jpg" alt="see more" /></a>'; } echo '<img class="line" src="images/linia.gif" alt="linia" />'; //echo '</div>'; echo '</div>'; closedir($dir); } else { $i = 0; // don't display empty divs if($id === $no) { echo '<div class="subContent">'; while ($id == $no && $i < $n){ echo '<img id="'.$directoryName.'-'.$i.'" src="projects/'.$directoryName.'/'.$directoryName.'-'.$i.'.jpg" alt="'.$directoryName.'" />'; $i++; } if($id === $no) { echo '<div class="projectInfo">Agency: <a href="'.$agencyLink.'"><span>'.$agency.'</span></a></div>'; } echo '</div>'; } } } $index++; echo "\n"; }?> edit: the data file, from which it should read looks like this for the first project - the 0 1 2 - is exploded, and should return images 0, 1 & 2 for one of the projects
  14. cinek

    array/loop/config help

    <ul><li><img id="prima-0" src="projects/prima/prima-Array.jpg" alt="prima" /></li></ul> instead of the Array there should be one of the numbers from the config file
  15. cinek

    array/loop/config help

    I have added another field to the cofiguration file, I'm trying to explode it - which works as it's displaying the array. I have also added the foreach loop which Haris_S suggested. But when I view the code, it's coming up as Array - not the value from the file - and none of the images are displayed ;/here's what the file looks like now any ideas?
  16. cinek

    array/loop/config help

    thanks, but the problem is, I'm showing images from multiple projects on the site, so this info cannot be hard coded. I need to be able to change/add it to any project
  17. I'm trying to create a site, where I list some main images - 5 per page, I scan the folder for more images, if there is more then 1 image, a see more link shows up next to the main image. The configuration file for this looks something like this:idNo;param1;param2;param3;param4;param5what I want to do, is add another option at the end, so that I'm able to specify more then one image to be shown on the main page, so if I add another field to the config text file, and put something like 1,2,3 - that means that images named 1.jpg, 2.jpg & 3.jpg should also be listed on the main page in the following format: <ul><li><img src="1.jpg" alt="asdf"..... /></li><li><img src="2.jpg" alt="asdf"..... /></li><li><img src="3.jpg" alt="asdf"..... /></li></ul> I managed to get it to display just 1 main image from a folder, but I have no idea how to get more then one to show. If you wondering why I need this - I basically want to use a jquery image slider plugin later - this requires the above formatI know I need to add another variable below: $linkName = $contents[$index][5]; - something like $sliderImg = $contents[$index][6]; - but I have no idea where to go from therethis is my data.php file: <?php// Get file contents $file = "config.txt"; $lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $contents = array(); foreach($lines as $line) { $contents[] = explode(';', $line); } while($index < $end) { if (isset($contents[$index])) { $no = $contents[$index][0]; $directoryName = $contents[$index][1]; $agencyLink = $contents[$index][2]; $agency = $contents[$index][3]; $siteLink = $contents[$index][4]; $linkName = $contents[$index][5]; //check if there's more then 1 image in the directory $files = array(); $dir = opendir("projects/$directoryName"); // if dir doesn't exist; break if(!$dir) { echo "Problem opening dir"; break; } $n = 0; while(($file = readdir($dir)) !== false) { if($file !== '.' && $file !== '..' && !is_dir($file)) { $files[] = $file; $n++; } } $id = $_GET['id']; if(!isset($id)) { // echo data back to the site echo '<div class="content">'; echo "\n"; echo '<img id="'.$directoryName.'-0" src="projects/'.$directoryName.'/'.$directoryName.'-0.jpg" alt="'.$directoryName.'" />'; echo "\n"; echo '<div class="projectInfo">Agency: <a href="'.$agencyLink.'"><span>'.$agency.'</span></a>'; echo 'WWW: <a href="'.$siteLink.'"><span class="'.$linkName.'">'.$linkName.'</span></a></div>'; // if there's > 1 image display see more if($n > 1) { echo '<a href="?page='.$page.'&id='.$no.'"><img class="more" src="images/see_more.jpg" alt="see more" /></a>'; } echo '<img class="line" src="images/linia.gif" alt="linia" />'; //echo '</div>'; echo '</div>'; closedir($dir); } else { $i = 0; // don't display empty divs if($id === $no) { echo '<div class="subContent">'; while ($id == $no && $i < $n){ echo '<img id="'.$directoryName.'-'.$i.'" src="projects/'.$directoryName.'/'.$directoryName.'-'.$i.'.jpg" alt="'.$directoryName.'" />'; $i++; } if($id === $no) { echo '<div class="projectInfo">Agency: <a href="'.$agencyLink.'"><span>'.$agency.'</span></a></div>'; } echo '</div>'; } } } $index++; echo "\n"; }?>
  18. this is how the link(s) are generated while($index <= $noOfPages) { $pagination .= '<a '.(($index === $page) ? 'id="this_page"' : '').' href="?page='.$index.'">'.$index.'</a> | '; $index++; } not sure how I'd do this here
  19. I have 4 links, each linking to a page, I'm moving around using a next/back button. When the user ends up on page e.g. 4, I want the link 4 to be a different color. How can I do that?the links are generated using php, so adding class active to a link on a page is not an option
  20. I'm having an issue with pagination. I want the user to be able to move around between pages. If they go to a link ?id=6, I want to display the amount of images located in the folder. Now, it seems to work, but does not.1. It tries to load 21 images every time even tho, there are never 21 images in 1 folder.2. On page 2, no images are being loaded :SEDIT: nvm sorted
  21. cinek

    create a ?id=X page

    I managed to do it. Was over complicating things as always lol
  22. cinek

    create a ?id=X page

    I'm scanning a folder for images, if there's more then 1 image, I want to display a "more" link. (I have done this). Now when you click the link, I want to direct the user to a link like this index.php?id=X ? and how do I fill the page out?how can I do that? I'm not sure what it's called, searching for ?id= on google is not much help
  23. ok, this is more or less this: $i = 0; for($i = 0; $i < $noarr; $i++) { $no = $contents[$i][0]; $a= $contents[$i][1]; $b= $contents[$i][2]; $c= $contents[$i][3]; //$dir = opendir("a/".$a."/"); echo "<img src='a/".$a."/1.jpg' />"; echo "asdf: $b\n"; echo "saf: <a href='$link'>$a</a> <br />"; } now this echos everything out. I think I need to echo it from the pagination file. Problem is, I also need to specify the variables, so echoing the rows, does not help at all :)this is what I came up with (at the end of the pagination file) while($index < $end) { if (isset($rows[$index])) { echo $rows[$index]; } $index++; } it lists the 5 rows(lines from the text file), but since they are not assigned to any variables like below, it's no use $i = 0; for($i = 0; $i < $noarr; $i++) { $no = $contents[$i][0]; $a= $contents[$i][1]; $b= $contents[$i][2]; $c= $contents[$i][3]; //$dir = opendir("a/".$a."/"); echo "<img src='a/".$a."/1.jpg' />"; echo "asdf: $b\n"; echo "saf: <a href='$link'>$a</a> <br />"; } EDIT: nvm, got it
×
×
  • Create New...