Jump to content

c_pattle

Members
  • Posts

    295
  • Joined

  • Last visited

Posts posted by c_pattle

  1. I have a .sql file that has the following in it

     

    DROP TABLE IF EXISTS `flights`;
    /*!40101 SET @saved_cs_client	 = @@character_set_client */;
    /*!40101 SET character_set_client = utf8 */;
    CREATE TABLE `flights` (
     `flight_id` int(11) NOT NULL AUTO_INCREMENT,
     `flight_icon` int(11) NOT NULL,
     `flight_path` int(11) NOT NULL,
     `flight_from` int(11) NOT NULL,
     `flight_to` int(11) NOT NULL,
     PRIMARY KEY (`flight_id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
    /*!40101 SET character_set_client = @saved_cs_client */;
    /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
    

     

    I have read the contents of the file using file_get_contents. I was wondering what is the best way to strip out everything before "CREATE TABLE" and everything after "CHARSET=latin1"? Does anyone have any suggestions on the best way to do it?

     

    Thanks

  2. I was just wondering if anyone knows what the most efficient way of checking to see if two tables contain matching records.

     

    So for example I have a table called 'orders' which have a primary key of order_id.

     

    Then I have a table called 'order_comments' which also has a field called order_id and I want to run a query that will check which orders don't have entries in order_comments.

     

    Thanks for any help

  3. I have a php script that needs to replace trademark symbols in a string. At the moment it works by doing

     

    str_replace(™, '', $string);

     

    This works when I have tested it on Windows but is this a bad way of doing it? I'm guessing it is. Does anyone know a better way.

     

    I know I could convert the string to html entities and then replace the html code but I don't want to do this as there are other things in the string I don't want to convert to html entities.

     

    Thanks

  4. I have a .sql file that has lots of sql commands in it.  What I want to do is then run all of these commands on a database.  I was just wondering what the best approach would be.  Is there a way to import the file or am I best opening the file, reading each line and then performing that query?

     

    Thanks for any help. 

  5. I have a checkout section of my website where the user can apply coupons code to certain items in the cart.  When the user enters a coupon code it changes the price of the item in the cart.  Because you can't just update the price I am deleting the old cart item and then re inserting it.  However when I do this some of the items don't seem to get re-inserted.  I think it's the items with things like brackets in the product name.  My code is below

     

    //Create an array of product details
    $newItem = array(
        'id' => $items['id'],
        'name' => $items['name'],
        'qty' => $items['qty'],
        'price' => number_format($newPrice, 2),
        'supplier' => $items['supplier'],
        'coupon' => $coupon,
        'full_price' => $items['price'],
         'type' => $items['type']
    );
    
    //Create an array to remove the item from the cart
    $data = array(
        'rowid' => $items['rowid'],
        'qty'   => '0'
    );
                                        
    $this->cart->product_name_rules = '[:print:]';
    
    //Remove the item then re-insert it
    $this->cart->insert($newItem);
    $this->cart->update($data);
    

     

    Can anyone see what I'm doing wrong?  Thanks for any help

  6. In my core controller I'm trying to create an array of the user's history.  I am creating an array and then setting the key as the time and the value as the page URL.  However the problem that I'm having is that the previous array seems to get overwritten so there is only ever one key and value pair in the array. 

     

    How can I do it so that instead each page will get appended to the array

     

    $history = array(
        time() => curPageURL()
    );
    
    $this->session->set_userdata('history', $history);
    

     

    Thanks for any help

  7. I have the following form the just has one field. 

     

    <html>
        <head>
            <title>Post</title>
        </head>
        <body>
            <form action="worldpay_callback.php" method="post">
                <input type="text" name="username" id="username" />
                <input type="submit" name="submit" id="submit" value="send" />
            </form>
        </body>
    </html>
    

     

    I am then posting the form to the following page that is meant to loop through all of the post values and save them to a text file.  For some reason my foreach loop doesn't seem to be working as done of the post values are getting written to the text file.  Can anyone see anything I'm doing wrong?

     

    $myFile ="notifications.txt";
    $fh = fopen($myFile, 'w+') or die("can't open file");
    
    foreach($_POST as $k=>$v)
    {
       $data = 'POST: Key:'.$k.' - Value:'.$v ." \n";
       fwrite($fh, $data);
    }
       
    fclose($fh);
    
    return "[OK]";
    

     

    Thanks for any help

  8. So for example I want to run a query that performs a full text on a field orders by relevance and returns the results. 

     

    Then on the results I've got from that query I want to perform another query to order the results by price. 

     

    I tried doing 2 orders by on the first query but that didn't work because althought it did order them by price I got not very relevant results

  9. I was just wondering if it's possible to run a query on data that has been returned from a previous query?  For example, if I do

     

    $sql = 'My query';
    $rs = mysql_query($sql, $mysql_conn); 
    

     

    Is it then possible to run a second query on this data such as

     

    $sql = 'My query';
    $secondrs = mysql_query($sql, $rs, $mysql_conn); 
    

     

    Thanks for any help

  10. I have an image uploader that works well and stores the name of the file uploaded in a session.  Once the files has been uploaded how do I then rename that file? 

     

    I would rename it during the uploaded but I need to rename it to an order number and I only get that order number after the image has been uploaded. 

     

    Thanks for any help. 

  11. I'm in the process of building an e-commerce website but am unsure on the best way to accept payments.  I've looked into Paypal and using their IPN system but I think thats only paypal to paypal payments.  Does anyone have any experience of accepting credit card payments online and can recommend a certain path to go down?

     

    Thanks

  12. I'm currently developing an e-commerce website and I've been asked to integrate a live chat tool into the website.  I was just wondering if anyone here has done something similar and would reccomend a certain path go down?

     

    Thanks for any help. 

  13. I have a form with a file input field to allow users to upload image files. 

     

    <input id="petPhoto" type="file" value="photo" name="petPhoto">
    

     

    The problem I'm having is that I can't get the value in this field when the form is submitted (e.g images/fileimage.jpg). 

     

    In my controller I have the following line to try to get the value but when I do a var dump on it, it just returns false. 

     

    $petPhoto = $this->input->post('petPhoto');
    

     

    Does anyone know what I'm doing wrong?

  14. I have a section in one of my scripts that checks for a value in array and the value doesn't exist in the array then it add it.  This works fine for single array but not for mulit-dimensional arrays.  Has anyone had a similar problem and knows a good solution?

     

    if(in_array($words[$i], $searchWords)){
        //Do nothing
    }else{
        $searchWords[] = $words[$i];
    }
    

  15. Sorry.  So for example if I do

     

    class Homepage extends CI_Controller
    {
        
        function Homepage()
        {
            parent::__construct();
            
            $this->load->library('layout');
        }
    }
    

     

    The library doesn't seem to load because I can't access any of the method in that libary.  But if I was to load the library in another function that wasn't the contoller it works fine

  16. I have a problem where in a controller constructor I can load the codeigniter libraries such as session and cart but I can never load any libraries that I've written.  Everytime I do it says that it is undefined.  Does anyone know what might be causing this?  Thanks

  17. I have the following code

     

    <? $i=1; ?>
            <? foreach ($query4->result_array() as $row4): ?>
            
            <? $next = $query4->next_row('array'); ?>
            <? $prev = $query4->previous_row('array'); ?>
    
    <? $i++; ?>
    <? endforeach; ?>
    

     

    However when I run this the next_row() and previous_row() functions only work on the first loop.  So on the first run through they get the next row or previous row but then they seem to stop. 

     

    Then whenever I do a var_dump on the $next and $prev variables they still contain the data for the second row. 

     

    Does anyone know what I'm doing wrong? 

     

    Thanks

  18. I have an array of data from a mysql result.  The problem I have is that I want to find out what the next row is going to be in advanced.  At the moment I have

     

    while($row = mysql_fetch_assoc($rs) {
    
        echo 'Order ID: ' . $row['order_id'];
    
    }
    

     

    This just echo's out the order_id of the current row.  However I want to find out if the order_id on the next row is going to be the same or different.  If it's different I will want to echo out something else.

     

    while($row = mysql_fetch_assoc($rs) {
    
        echo 'Order ID: ' . $row['order_id'];
    
        //If order_id + 1 is different then echo
       echo 'Total: ' . $row['total']
    
    }
    

     

    Does anyone know a way round this problem?

     

    Thanks

  19. I was just wondering if there is a way to get the next row in advanced when looping through a mysql results.  At the moment I have

     

    <? $i=1; ?>
    <? foreach ($query->result() as $row): ?>
        
        <?= $row->order_id ?>
    
    <? $i++; ?>
    <? endforeach; ?>
    

     

    At the moment this just echo's the order_id in the row its currently looping through but is there a way to get the order_id of the next row in advance?

     

    The reason I want to do this is because if I know the order_id is going to change on the next row then I will want to echo something different. 

     

    Thanks

  20. Thanks, this was the results

     

    id select_type table type possible_keys key key_len ref rows Extra

    1 SIMPLE product_data ALL NULL NULL NULL NULL 12432 Using temporary; Using filesort

    1 SIMPLE product_pricing ALL NULL NULL NULL NULL 5558 Using where

    1 SIMPLE products eq_ref PRIMARY PRIMARY 4 animed.product_data.product_id 1 Using where

     

    So I guess I need to add some indexes?

  21. I have the following query that takes 69 seconds, which I reckon is going to be a tad bit too slow to use on a public facing website  :P .  I was wondering if anyone knows how I can speed up the query. 

     

    SELECT product_data.*, products.supplier_ref, product_pricing.sales_price_inc_vat, products.type_id, MATCH(product_data.product_name) AGAINST ("Metacam") AS score FROM product_data, products, product_pricing WHERE products.type_id = 1 AND product_data.product_id=products.product_id AND product_data.product_id=product_pricing.product_id  AND products.type_id = 1 ORDER BY score DESC LIMIT 20

     

    Let me know if you want me to put the table structures on here but they are quite big!

     

    Thanks

×
×
  • 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.