Jump to content

gongpex

Members
  • Posts

    360
  • Joined

  • Last visited

Posts posted by gongpex

  1. Hi, This to reply :

    If $_SESSION['buy'] contains only those three items, and $count is 3, and assuming $x starts at 0, then you're going to end up with the same 3 values from $_SESSION['buy'] duplicated in $product['title'][0], $product['title'][1], and $product['title'][2]. I don't know why you need the same values in all 3 of those titles. You're not changing the indexes for $_SESSION['buy'], so it's always copying the values from $_SESSION['buy'][0], $_SESSION['buy'][1], and $_...
    This is my fix code :
    <?if($_SESSION['buy']){$count = count($_SESSION['buy']);for($x=0;$x<$count;$x++){$product_title = $_SESSION['buy'][$x][0];$product_price = $_SESSION['buy'][$x][1];$product_img = $_SESSION['buy'][$x][2];$product_id = $_SESSION['buy'][$x][3];$product_qty = $_SESSION['buy'][$x][4]; echo"$product_title<br />$product_price<br />$product_img<br />$product_qty<br /><br/>";}}else{echo"fail";}?>

    I had try new code, this my code :

    <?$product = array();$product[0] = $_SESSION['buy'][0];$product[1] = $_SESSION['buy'][1];$product[2] = $_SESSION['buy'][2];$product[3] = $_SESSION['buy'][3];$product[4] = $_SESSION['buy'][4];  $product = array_unique($product);  if($_SESSION['buy']){$count = count($_SESSION['buy']);for($x=0;$x<$count;$x++){  $product_title = $product[$x][0];  $product_price = $product[$x][1];  $product_img = $product[$x][2];echo $product_title."<br />".$product_price."<br />".$product_img."<br /><br />";}}else{echo"fail";} 

    Now I put array inside array, so that array_unique can be work, but if I delete code :

    $product = array_unique($product);

    It would be back like image on above (duplicated), But if I using this code , it's only show one product,and the other product cannot be shown. + About new code : Q : What's mistake from my code? + About fix code : This is still duplicated Q : from both of this code, which code that possible to be use so that when user buy product , it would be not duplicated? please help me Thanks

  2. Sorry, I forgot to post something here, please see this code :

    <form method="post" action="buy.php">	    <input type="text" value="<?$id1 = $product_id?>" style="display:none" name="test" /></div>						 <div class="pr" style="height:15px"><b style="font-size:14px"><?echo"$product_name";?></b></div>						 <div class="pr"><input type="submit" value="BUY NOW" /></div></form>   //this is product 1<form method="post" action="buy.php">	    <input type="text" value="<?$id2 = $product_id2;?>" style="display:none" name="test" /></div>						 <div class="pr" style="height:15px"><b style="font-size:14px"><?echo"$product_name2";?></b></div>						 <div class="pr"><input type="submit" value="BUY NOW" /></div></form>   //this is product 2

    When I click "BUY NOW" for every product (only once) it will shown like this : expect.png And if click "BUY NOW" twice or more , it will occurs like image on above. I will try your suggestion to remove $product['title'][$x], If I got stuck I will post here Thanks________________________________________________________________________________________ OFFQ : My friend told to me if better I learn java rather than PHP, he told me because in the future java is the best to build web, rather than PHP, is that correct ? please explain me (if not objection) Thanks again

  3. Thanks for reply,

    Why are you filling up the product array with the first 3 entries in $_SESSION?
    A : I think I need 3 entries to show product at user. I 'll to remove some entries of $_SESSION array, if I get stuck please help me Thanks
  4. I think I need to the point, please see this image : unique.jpg code on above :

    $count = count($_SESSION['buy']);  while($x<$count){$product['title'][$x] = $_SESSION['buy'][0];$product['price'][$x] = $_SESSION['buy'][1];$product['img'][$x] = $_SESSION['buy'][2];}

    Q : Can I using array_unique to avoid duplicate array value like image on above? Q : If array_unique not possible, what I must do so that array value not duplicated ? please help me thanks

  5. Hello everyone please see this code :

    <?$data = array();$data[0] = "test";$data[1] = "price";$data[2] = "img";$data[3] = "img";echo(array_unique($data));?>

    if I wrote code like on above it won't show anything, but if I using print_r it can displayed Q : Actually can I display it using echo ? So that the result shown like this :

    testpriceimg
    please answer Thanks
  6. Hi everyone, please see this code :

    while($x<2){$product['title'][$x] = $_SESSION['buy'][0];$product['price'][$x] = $_SESSION['buy'][1];$product['img'][$x] = $_SESSION['buy'][2];}

    it's now result like this : expect.png it's can be shown because : (while($x<2)), Q : if product more than 2, of course I cannot using $x<2 it should be : $x<$count or $etc, how to create so that $count can be shown automatically based on ordered product ? please help me Thanks

  7. Hi, You right, thanks for answer. But I didn't found tutorial about :

    $_SESSION['buy'][] = $data;

    Q : What the meaning of this code? on : http://w3schools.com.../php_arrays.asp On this tutorial it's not written : array should be initialized first , then you create arrays. (please see on numeric arrays example) and this the code

    <?php$cars[0]="Saab";$cars[1]="Volvo";$cars[2]="BMW";$cars[3]="Toyota";echo $cars[0] . " and " . $cars[1] . " are Swedish cars.";?>

    This is made me thought , if not necessary to initialize array ($data=array(); then , $data[0] =... and etc) please tell me Thanks

  8. Did you forget to initialize $_SESSION['buy'] as an array?$_SESSION['buy'] = array();
    I think to initialize session as an array no need to add "array()" on session Q : So, it's must be written before I made another array? please help me Thanks
  9. Hello,

    You keep overwriting $_SESSION['$s'] with the new product. You should make an array in the session and keep adding products to the array instead of replacing the existing one.
    Q : Sorry, I rather don't understand can you explain me more? This my new code : Code II (buy.php) :
    <?require("database.php");$s = $_POST['test'];$product_db = mysql_query("select * from product where p_id='$s'");$p_list = mysql_fetch_array($product_db);$p_title = $p_list['p_title'];$p_price = $p_list['p_price'];$p_img = $p_list['p_image']; session_start();$_SESSION['pid'] = $s;$_SESSION['buy'][0] = $p_title;$_SESSION['buy'][1] = $p_price;$_SESSION['buy'][2] = $p_img;header("location: index.php?p=shop");?>

    This is code III (content_shop.php) :

    <?if($_SESSION['pid']){$x=0;while($x<2){$product['title'][$x] = $_SESSION['buy'][0];$product['price'][$x] = $_SESSION['buy'][1];$product['img'][$x] = $_SESSION['buy'][2];echo"".$product['title'][$x]."<br />".$product['price'][$x]."<br />".$product['img'][$x]."<br /><br />";$x++;}}else{echo"fail";}?>

    This is result from my code : problem.jpg And this is my expectation (this result from image modification using photoshop tool): expect.pngQ : What's mistake on my code? please help me Thanks

  10. Hello everyone, if I using this session code it cannot add product when user buy other product : Code I :

     <form method="post" action="buy.php">	<input type="text" value="<?$id1 = $product_id?>" style="display:none" name="test" /></div>			 <div class="pr" style="height:15px"><b style="font-size:14px"><?echo"$product_name";?></b></div>			 <div class="pr"><input type="submit" value="BUY NOW" /></div></form>	//this is product 1 <form method="post" action="buy.php">	<input type="text" value="<?$id2 = $product_id2;?>" style="display:none" name="test" /></div>			 <div class="pr" style="height:15px"><b style="font-size:14px"><?echo"$product_name2";?></b></div>			 <div class="pr"><input type="submit" value="BUY NOW" /></div></form>	//this is product 2 

    Code II (buy.php)

    <?require("database.php");$s = $_POST['test'];session_start();$_SESSION['$s']= $s;header("location: index.php?p=shop");?>

    Code III (this is page where the cart is shown content_shop.php) :

    <?if($_SESSION['$s']){$product_db = mysql_query("select * from product where p_id='".$_SESSION['$s']."'");$product_list = mysql_fetch_array($product_db);$product_title = $product_list['p_title'];$product_price = $product_list['p_price'];$product_img = $product_list['p_image'];echo"$product_title<br />$product_price<br />$product_img<br />".$_SESSION['total']."<br />";}else{echo"fail";}?>

    When I click "BUY NOW" it can added to basket cart, but when I buy other product, it changes to last product (product that last to be clicked) Q : How to display using session, all product that I had bought (on shopping cart)? please help me Thanks :

  11. Hello everyone, I think all of you know about shopping cart, I had tried to create shopping cart on my site into localhost, using firefox It works, but when I open on other browser and open my localhost using it, cause my cart on firefox lost or deleted (I open two browser and test my site). Q : Is if I open my site on localhost using two different browser simultaneously it can cause session_destroy? Q : Should I upload my site to web hosting so that when I open using 2 browser simultaneously it cannot cause session_destroy? please answer Thanks

  12. (the so called "grey hat" hackers)
    Actually I want learn about hack site, just for protect my site from hack. But I don't know where I can found source to learn about hack site Q : Can you tell me where I can found material or source to learn hack site ? Thanks
  13. Are you looking into getting into the hacking business?
    Of course NOT!! , I ask about this because I astonished with something, But because your information I become understand now Thanks for information____________________________________________________________________________________ BTW : I am not corrupted man who do something that can harm other people , in short I never want to hurt someone. -_- Sometimes I ask off topic just to make conversation so that not stiff. But I think lately people not like if I ask about off topic (my thought), then I seldom to ask about off topic except it's important for me. So, don't worry with me...
  14. Without a form
    I didn't said without form, just if <input> or button change to <a> I ask this question because this tag won't work on IE6 :
    <a href="/../"><input type="button" value="cancel" /></a>

    I can use

    <input type="image" src="" />

    but I should create image for it, But alright this okay . Thanks for answer

  15. Hello everyone, Please read this simple code :

    <form name="" action="" method="post"><input type="submit" value="submit" /> //or<button>SUBMIT</button></form>

    Usually people using <input > tag to create "SUBMIT" button or using <button></button> to create it, like on above. Q : If I using tag : <a href=""></a> can I create submit button ? Please answer Thanks

  16. My question really not about on array, but it's about how to display session, this :

    <?if($_SESSION['user'][0][1][2][3][4]){echo"that's good";}else{echo"hello";}?>

    and this :

    <?if($_SESSION['user']){echo"that's good";}else{echo"hello";} //then if($_SESSION['user'][0]){echo"that's good";}else{echo"hello";}  if($_SESSION['user'][1]){echo"that's good";}else{echo"hello";} //etc...?>

    from both on above, which one is correct? (that's my question). I know, of course the second option is the answer, if I using array Q : But if I using array in session repeatedly (like on second option), it's can be run or it's just redundant?

  17. Everything needs to be given a value before it can be used.
    Q : if the session had given value, still it can given array? For example :
    <?$_SESSION['user'] = $user; // then I give it array -----> (1)$_SESSION['user'] = array();$_SESSION['user'][0] = $member;$_SESSION['user'][1] = $another_ thing;$_SESSION['user'][2] = 'hello';$_SESSION['user'][3] = 'cookie';$_SESSION['user'][4] = 'please_help_me'; // and finally, to display session : -----> (2) if($_SESSION['user'][0][1][2][3][4]){echo"that's good";}else{echo"hello";} //or  -----> (3) if($_SESSION['user']){echo"that's good";}else{echo"hello";} //then if($_SESSION['user'][0]){echo"that's good";}else{echo"hello";}  if($_SESSION['user'][1]){echo"that's good";}else{echo"hello";} //etc...?>

    Q : Code on above which is correct? Q : Number : -----> (2) or -----> (3) ?? thanks

  18. Hello everyone, Yesterday when I'am online at about 11.45 pm (this forum time). I can't access this forum suddenly, why?Till I can't post my thread I had try to check my connection and reopen this site but it can't connect. please tell me thanks

  19. it's just an array, so you can just put as much data in it as you want, in whatever members you want.
    Q : Array? did you mean I can use array more than 1 like this code :
    <?php$_SESSION['v1'][1] = 'cake'; //or if($_SESSION['test']['member']){//some php code...}?>

    Note : I got this example from : http://php.net/manua...les.session.php please tell me Thanks

×
×
  • Create New...