Jump to content

Isset1988

Members
  • Posts

    51
  • Joined

  • Last visited

Everything posted by Isset1988

  1. thank you for your help. i mean ide not framework.
  2. Hello! I have two questions for you. Until now, i programmed php with a text editor. Someone, tell me that i'm silly. He use a framework, which help him write clean code, with new php functions. He said me that when my code deprecated, this framework help me (suggest me) replace these specific functions with the new one. Is there any framework to do this? And what framework you proposed me to use? Furthermore, i want to build a php marketplace. I dont want to use any free or paid template - code. What php must use for security? I see in wordpress and joomla code that programmers use pdo. What's your opinion? Thank you my friends!
  3. I underastand, the only thing i want is to retrieve at least one row correctly. Any way... Thank u my friend!
  4. I attached here the thread table. Ca you take a look? Thank you!
  5. Thank you for your help. I tried that localhost. I use the first command on my phpmyadmin and done. When i tried retrieve data, i get the same ungly code. Can i post here the thread table to take a look? Thank you!
  6. Hello all I have a vb mysql database and its collation is "latin_swedish_ci". (i have huge problem on searching greek chars) I'm trying to create a php script to retrieve some data's from a specific table. For example: header('Content-type: text/html; charset=UTF-8'); $connection = mysql_connect('localhost', 'root', ''); mysql_select_db('database', $connection); mysql_query("SET NAMES 'utf8'", $connection); $query = 'SELECT title FROM thread WHERE threadid = 15'; $result = mysql_query($query, $connection); $result = mysql_fetch_assoc($result); print_r($result); But i get code like this: Σκιάθος - ΚουκουναÏιέ In my phpmyadmin i get the same code. The english chars shows perfect. From now, i want to retrieve some data's from the above tables on utf8. Any idea? Thank you! (If i can retrieve the data's correctly, i will create a new table - mirror of the old table as utf8 and i hope my problem fixed that way)
  7. Any idea? Is there any other way to update the quantities and the total price using javascript?
  8. Hello I have two issues with a javascript cart. When i change the quantities, i see updated the total and the subtotal, but ... when i load the page, the total and subtotal is empty by default. Can i print above the subtotal and the total-quantity? Here i attach you my code: <script> var books = {} window.onload=function() { var inputs = document.getElementsByTagName('input'); for (var i=0;i<inputs.length;i++) { if (inputs[i].type=="text" && inputs[i].id.indexOf('quantity')!=-1) { var name = inputs[i].id.replace('quantity',''); books[name] = parseFloat(document.getElementById(name+'price').innerHTML.replace('$','')) inputs[i].onkeyup=function() { var total = 0; for (var book in books) { var q = document.getElementById(book+"quantity").value; total += (isNaN(q) || q=="")?0:parseInt(q)*books[book] } document.getElementById('subtotal').innerHTML="Sub-total: "+total.toFixed(2)+" €"; document.getElementById('grandtotal').innerHTML="Total: "+(total*1.23).toFixed(2)+" €"; } } } } </script> <p id="1price">100 €</p> <input type="text" id="1quantity" value='1' /> <p id="2price">100 €</p> <input type="text" id="2quantity" value='1' /> <div class="total-subtotal"> <p class="totals" id="subtotal">Sub-total:</p> </div> <div class="total-price"> <p class="totals" id="grandtotal">Grand-total:</p> </div> Is there someone who can help? Thank U!
  9. Thank you for your answer requinix. The proper/valid html is: <ul> <li> <a href='#'> Category </a> <ul> <li><a href='#'> Sub Category </a></li> </ul> </li> </ul> Is there any solution without have the subcategory nside the category?
  10. Update all cart quantities... I share it if someone wants to use it with the code above. Front page: (i have it into a while loop. in this way i push things into an array) <input type="text" name="<?='qty'.$key?>" value="<?=$value?>"> The session file: //condition update all If(isset($_POST['update'])){ foreach ($_POST as $key=>$value) { //first i save the post data to an array if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $_SESSION["cart"][$id] = $value; //save the array into my cart session } } }
  11. Hello my friends, I want to create a vertical menu with some categories and some subcategories. My script produses a little strange the unordered list structure. (there is no way to change this) <ul> <li> <a href="#"> Category 1 </a> </li> <li> <a href="#"> Category 2 </a> </li> <ul> <li> <a href="#"> SubCategory 2.1 </a> </li> </ul> <ul> <li> <a href="#"> SubCategory 2.2 </a> </li> </ul> <li> <a href="#"> Category 3 </a> </li> </ul> Can someone help me to create a simple css 3 menu. Thank you !
  12. I'm sorry. I read again your answer carefully. I expand the session script following your logic structure. This is what i need. I post it there if anyone want to copy this. <?php session_start(); if(!isset($_SESSION["cart"])){ // create cart if it doesn't exist $_SESSION["cart"] = array(); } $add2cart = isset($_GET["add2cart"]) ? (int)trim($_GET["add2cart"]) : 0; // condition input if($add2cart > 0){ // a valid value //$query = "select COUNT(*) from products where id=$add2cart"; // run the query using your favorite database library functions, check for errors, and retrieve the COUNT value $count = 1; //i bypass this to check the sessions if($count==0){ echo 'the product is not in our database'; // it is usually cleaner/clearer to handle the error condition up front in the logic } else { if(!isset($_SESSION["cart"][$add2cart])){ // check if id is not already in cart $_SESSION["cart"][$add2cart] = 1; // create item in cart } else { $_SESSION["cart"][$add2cart]++; // increment item in cart } } } $remove = isset($_GET["remove"]) ? (int)trim($_GET["remove"]) : 0; // condition delete if($remove > 0){ unset($_SESSION["cart"][$remove]); } $removeAll = isset($_GET["removeAll"]); // condition delete all if($removeAll > 0){ unset($_SESSION["cart"]); } $update = isset($_GET["update"]) ? (int)trim($_GET["update"]) : 0; // condition update $quantity = isset($_GET["quantity"]) ? (int)trim($_GET["quantity"]) : 0; if($update > 0 && $quantity > 0){ $_SESSION["cart"][$update] = $quantity; } //condition update all ? // display raw cart data for debugging purposes echo '<pre>',print_r($_SESSION['cart'],true),'</pre>'; ?> Now the only function i need to find is to update all the cart quantities with one click. :/ Thank you for your help mac_gyver!
  13. Thank you for your help. But i have to handle and ids in order to proceed an order.
  14. Hello my friends I tried to build a shopping cart system for my website but my knowledge stuck me. Is there any simple (but reliable) php tutorial to build a shopping cart system? To explain you the situation. When the visitor choose a product and press the Buy button, i want to check if its id is on my database. After that the visitor will can choose more products or delete all or update the quanties or delete one of them from basket. I attach you my session code, but has a lot of bugs on add2cart. Maybe i add products wrong and i get wrong results from the other functions (update,delete). :/ <?php //sessions and functions to set or unset product sessions from cart session_start(); If (isset($_GET["add2cart"]) && (int)$_GET["add2cart"]>0) //add product to cart with id=$add2cart { require_once('functions.php'); GetMyConnection(); $add2cart = $_GET["add2cart"]; echo 'max'.max($_SESSION["gids"]); $q = mysql_query("select id from content where id='$add2cart'"); $count=mysql_num_rows($q); If($count==1){ if (!isset($_SESSION["gids"])) { $_SESSION["gids"] = array(); $_SESSION["counts"] = array(); } //check for current product in visitor's shopping cart content $i=0; while ($i<count($_SESSION["gids"]) && $_SESSION["gids"][$i] != $_GET["add2cart"]) $i++; if ($i < count($_SESSION["gids"])) //increase current product's item quantity { $_SESSION["counts"][$i]++; } else //no such product in the cart - add it { $_SESSION["gids"][] = $_GET["add2cart"]; $_SESSION["counts"][] = 1; } }Else{ echo 'the product is not in our database'; } } ?> <?php If (isset($_GET["removeAll"])) {//remove all products from cart unset($_SESSION["gids"]); unset($_SESSION["counts"]); } ?> <?php //remove specific product from cart if (isset($_GET["remove"]) && (int)$_GET["remove"] > 0){ If($_GET["remove"] >0 ){ $i = $_GET["remove"] -1; }Else{ $i = $_GET["remove"]; } unset($_SESSION["gids"]["$i"]); } ?> <?php //update cart If (isset($_GET["update"]) && (int)$_GET["update"] > 0 && $_GET["q"] && (int)$_GET["q"] > 0) //remove product with productID == $remove { $i = $_GET["update"] -1; //i decrease -1 to find the right array row $_SESSION["counts"][$i] = $_GET["q"]; //i update only the quantity } ?> <?php //echo the cart //i copy that in the front page Basket.php $i = max($_SESSION["gids"]); //here i find max entries in this array $i = $i -1; If(isset($i) && $i>=0){ For ($k=0;$k<=$i;$k++){ If($_SESSION["gids"]["$k"]==0 or $_SESSION["counts"]["$k"]==0){//empty array, i dont want to echo this }Else{ echo 'Session_Id: '.$_SESSION["gids"]["$k"].' Quantity: '.$_SESSION["counts"]["$k"].'<br>'; } } } ?> Is there any simple and reliable shopping cart tutorial? Thank you!
  15. Wow, Muddy_Funster i think your code is what i looking for. Your code has the functions page i need to include in my code. Can you post me here a sample of the front page which call these functions? And if you can send me a sample database to adupt this to the structure of my database Many Thanks!!!!
  16. Yes, now i get one good result. <ul> <li>SubCategory 1</li> <li>SubCategory 2</li> <ul> <li>SubCategory 2.1</li> <li>SubCategory 2.2</li> </ul> <li>SubCategory 3</li> </ul> I think that the structure is more right as the code below, but it is difficult to achieve this. . <ul> <li>SubCategory 1</li> <li>SubCategory 2 <ul> <li>SubCategory 2.1</li> <li>SubCategory 2.2</li> </ul> </li> <li>SubCategory 3</li> </ul> In my case i will try to get this code: <ul> <li><a href="#">SubCategory 1</a></li> <li><a href="#">SubCategory 2</a> <ul> <li><a href="#">SubCategory 2.1</a></li> <li><a href="#">SubCategory 2.2</a></li> </ul> </li> <li><a href="#">SubCategory 3</a></li> </ul> Thanks again for the help!
  17. Thank you for all the help. The results is perfect for the first option, but i dont get the right structure on ul li. Thank you Muddy_Fuster. I will try to get something from this code
  18. Thank you again for your time, to solve my problem When i use your first answer: <? $sql = "SELECT id, title, parent_id FROM table WHERE language='en-GB' and level>=3"; $res = mysql_query($sql, GetMyConnection()); while (list($id, $title, $parent_id) = mysql_fetch_row($res)) { $data[$parent_id][] = array('id'=>$id, 'title'=>$title); } // call the recursive function displayHierarchy($data, 10); //function to print a category then its child categories function displayHierarchy(&$arr, $parent_id, $indent=0) { $ind = $indent * 50; if (isset($arr[$parent_id])) echo "<ul>\n"; foreach($arr[$parent_id] as $rec) { echo "<li>{$rec['title']}</li>"; echo "<ul>\n"; if (isset($arr[$rec['id']])) displayHierarchy($arr, $rec['id'], $indent+1); echo "</ul>\n"; } echo "</ul>\n"; } ?> I get this fault result: <ul> <li>SubCategory 1</li><ul> </ul> <li>SubCategory 2</li><ul> <ul> <li>SubCategory 2.1</li><ul> </ul> <li>SubCategory 2.2</li><ul> </ul> </ul> </ul> <li>SubCategory 3</li><ul> </ul> </ul> When i use the second: $sql = "SELECT id, title, parent_id FROM table WHERE language='en-GB' and level>=3"; $res = mysql_query($sql, GetMyConnection()); $minParent = 999; while (list($id, $title, $parent_id) = $res->fetch_row()) { $data[$parent_id][] = array('id'=>$id, 'title'=>$title); $minParent = min($minParent,$parent_id); } // call the recursive function displayHierarchy($data, $minParent); I get an server error. :/
  19. Ok. thank you for the advice, but is not too simple for me. :/ I will wait if anyone has any idea, I have this database: id parent_id level title language 1 0 0 ROOT * 2 1 1 Uncategorised * 3 1 1 Uncategorised * 4 1 1 Uncategorised * 5 1 1 Uncategorised * 6 1 1 Uncategorised * 7 1 1 Uncategorised * 8 1 1 English en-GB 9 1 1 Greek el-GR 10 8 2 Category 1 en-GB 11 9 2 Category 1 el-GR 12 10 3 SubCategory 1 en-GB 13 10 3 SubCategory 2 en-GB 14 13 4 SubCategory 2.1 en-GB 15 13 4 SubCategory 2.2 en-GB 16 10 3 SubCategory 3 en-GB 17 11 3 SubCategory 1 el-GR 18 11 3 SubCategory 2 el-GR 19 18 4 SubCategory 2.1 el-GR 20 18 4 SubCategory 2.2 el-GR 21 11 3 SubCategory 3 el-GR I want to print into ul li all the categories and subcategories with the above select: SELECT id, title, parent_id FROM conf_categories WHERE level>=3 and language='en-GB'
  20. Can i remove this and display the unordered list of that i have inside the select? Thank you again for your help!
  21. Barand, i'm back to you with a new question. I some other columns on my table, like levels. Every category has a level, maybe the level is the same. I tried this $sql = "SELECT category_id, name, parent FROM category WHERE level=1"; $res = mysql_query($sql); while (list($id, $name, $parent) = mysql_fetch_row($res)) { $data[$parent][] = array('id'=>$id, 'name'=>$name); } Everything works perfect when there is only one entrie with level =1. When i have 2 fields with the same level, i get a blank page :/ Any idea?
  22. Thank you for your quick reply. Everything Works perfect! Many thanks! (i'm not so good on functions and i want some time to understood your thoughts, but works perfect )
  23. Thank you for your answer But this works fine only with tables. Can i replace the tables with li ul?
×
×
  • 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.