Jump to content

Nodral

Members
  • Posts

    397
  • Joined

  • Last visited

Posts posted by Nodral

  1. I've not posted any code as I haven't got any yet.  I just need a pseudo-code theory on how to do this.

     

    I have 2 DB tables

     

    One is the field names and information about them, the other is the content.

    I pull an array from the field table which gives me the headings then pull several arrays from the content table which correspond to each individual entry. (against the field names), however the order in which the data comes out of the DB tables into the arrays is not the correct order for the output file.

  2. Hi

     

    I have an array which pull data from a DB (which I didn't create nor can modify)  I need to be able to export it to an excel sheet with the data in a specified order.  how do I do this?

     

    eg run sql queries and end up with array which would be

    [0] - a

    [1] - b

    [2] - c

    [3] - d

    [4] - e

     

    how would I be able to specify the order  eg d , a, c, e, b.  to match it up with the column headers on the excel sheet?

     

    To make it more of a challenge, I can't amend the column headers either.  I can only manipulate the array.

     

    I will be pulling multiple arrays out and not all have all the value is them!!!  Deep Deep Joy!!!

  3. You'd need a lot more than that.

     

    <?php
    // create sql statement to get information from DB
    $sql="SELECT columnName FROM articles ORDER BY date DESC LIMIT 5";
    
    //run the query against the DB
    $sql=mysql_query;
    
    //set variable to count the items
    $a=0;
    
    //create array containing all data pulled from DB anc cycle through it to do what you want
    while($row=mysql_fetch_array($sql){
    
    //create array of 5 variables containing individual items
    $mailContent['$a']=$row['columnName'];
    
    //increment your counter
    $a++;
    }
    

     

    Regarding mailing it out, I personally use Rmail.  Do a google for it, it'll save you loads of time.

    Then all you do is create your mail it include items

    (You can get them out of the array easily using a foreach loop)

     

    Regarding sending periodic emails, you need to look into cron jobs and have a reference in your DB table as to when the last one was sent out.

     

  4. Hi

     

    I'm using php to create URL's for Google Maps API from a massive database of locations so that each one appears on the web page with the details and a map of the immediate area.

     

    I've got 90% of this working, however I have an issue with the French (lol).  Where they have a name such as Cotes d'zure, the apostrophe makes the URL fail and no map show.  Does anyone know of a work around for this?  Would urlencode solve this issue?

  5. You can set up a session variable to be either red or blue.  For example $_SESSION['colour']="red";

     

    Then you can use all the same site.  Instead of having a sentence as "this is a red pen"  use "this is a $colour pen"  This will then change the text within the site depending on what the user has done. 

     

    Possibly the best way would be to just have one site called "Pens" with a form on the opening page asking if the user wants blue or red pens.  Then POST their reply back to the Session Variable.

     

    This way you only use 1 URL and you are cusomizing the site on the fly for the user.  It also gives you scope to run IF statements against the SESSION variable to change pictures, prices etc without having to write 2 complete sites.  The session variable will also stay in place as they move from page to page

  6. Hi

     

    I'v a script that generates a CSV file which the user then downloads in Excel.  Is there a way of setting column widths in the excel.csv file prior to opening?  Some of the data generated is longer than the standard column width and the user is expected to print the file.  I can't rely on the user having enough 'grey matter' to realise they will have to increase the width prior to printing!!

  7. Hi

     

    You need to be a little more specific

     

    From what you've said, you need to run a select within a select.

     

    eg

    $sql='SELECT Firstname, Surname, Year, Sex, Credits FROM table WHERE SCHOOL = (SELECT school FROM table WHERE id='.$_POST['id'].')'
    

     

    Obviously you need to put your table name in and change the $_POST variable to be what triggers the search

     

     

  8. Hi

     

    I have created an online test which assesses user input speed and then dynamically produces a graph of their results.  However, I have an issue with caching in that, if the assessment is run on the same system more than once the previous results and graphs are ched and displayed upon completion of the assessment.  One way around this is a Ctrl + F5 which will clear and refresh and show the correct results.  However, I canot rely on the users to do this, or realise they are not looking at their own results.  Is there a way around this?

  9. Why not use ORDER BY in your SELECT statement to ensure they come out alphabetically.

     

    Then run a test on the 1st letter of the result.  If it is the same as the previous one, just echo out the result, if not then echo out the letter to show a new group, then any entries for this group.

     

    
    $sql="SELECT producttitle FROM table ORDER BY producttitle ASC";
    $sql=mysql_query($sql);
    while($row=mysql_fetch_array($sql)){
    
    if(substr($row['producttitle'],0,1)==$letter){
    echo $row['producttitle'];
    $letter=substr($row['producttitle'],0,1);
    }
    else {
    $letter=substr($row['producttitle'],0,1);
    echo $letter;
    echo $row['producttitle'];
    }
    
    

     

    This way if a letter doesn't exist it will skip it.

     

  10. That's sorted that out, however my $price is being output to the csv file as £30.12 for example.

     

    How do I remove the 'Â' sign?  I know it's something to do with the encoding but I'm not sure how to change this.

     

  11. Hi All

     

    I have a script which creates a csv file with random entries.

     

    It should pick a country from an array (this is defined in countries.php), pick 4 letters, create a random price and a random 8 digit number then write each one to a line in the file.

     

    This works apart from one exception.  When the country is chosing $country[0] it appends it to the previous line of the file.

     

    any ideas?

     

    $handle = fopen($file, 'a') or die("can't open file");
    
    for ($i=1; $i<=500; $i++){
       
       //get country
       include ('countries.php');
       $countries=$country[array_rand($country)];
    
       // create ACCRISS code
       $first=array ("C", "E", "F", "G", "I", "L", "M", "O", "P", "S", "T", "U", "V");
       $second = array ("C", "D", "E", "F", "G", "M", "P", "V", "W", "X");
       $third = array ("A", "M");
       $fourth = array("N", "R");
       $accriss= $first[array_rand($first)].$second[array_rand($second)].$third[array_rand($third)].$fourth[array_rand($fourth)];
    
       //create price
       $pounds= rand(1,99);
       $pence=rand(0,99);
       $price="$pounds.$pence";	   
       $price="£".number_format($price,2);
       
       //create account numbers
       $number = rand(10000000,99999999);
    
    
       // add new row to output
       fwrite($handle,"$countries,$accriss,$price,$number");
    
       $place[]=$countries;
       $car[]=$accriss;
       $cost[]=$price;
       $account[]=$number;
       }
       
    //echo $output;
    fclose($handle);
    

     

    <?php
    //countries.php
    $country= array("Albania","
    Antigua","
    Argentina","
    Aruba","
    Australia","
    Austria","
    Bahamas","
    Bahrain","
    Belgium","
    Benin","
    Bosnia","
    Botswana","
    Bulgaria","
    Burkina Faso","
    Cameroon","
    Chile","
    Colombia","
    Croatia","
    

    This file goes on for about 150 countries but only Albania gets added to the current line instead of starting a new line.

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