Jump to content

dilby

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Posts posted by dilby

  1. Hi all -

     

    I am parsing info from mysql into a php table but the date being returned is in YYYY-MM-DD format and I want it DD-MM-YYYY. How would I do this?

     

    Code at the moment is:

     

    $link = connect();
    
    function get_user_posts(){
    
    $getPosts = mysql_query('SELECT a.id as id,a.post as question, a.answer as answer, a.created as created, a.updated as updated, b.vclogin as admin
     FROM user_posts as a, admin as b WHERE a.admin_id=b.adminid',connect());
    return $getPosts;
    }
    
    

     

    <table class="list">
    <tr>
    	<th><?php echo getlocal("upost.post") ?></th>
    	<th><?php echo getlocal("upost.answer") ?></th>
    	<th><?php echo getlocal("upost.admin") ?></th>
    	<th><?php echo getlocal("upost.created") ?></th>
    	<th><?php echo getlocal("upost.updated") ?></th>
    	<th></th>
    	<th></th>
    </tr>
    <?php 
    $all_questions = get_user_posts();
    
    while ($question = mysql_fetch_assoc($all_posts)):
    ?>
    
    <tr>
    	<td><?php echo $post['post']?></td>
    	<td><?php echo $post['answer']?></td>
    	<td><?php echo $post['admin']?></td>
    	<td><?php echo $post['created']?></td>
    	<td><?php echo $post['updated']?></td>
    	<td><a href="javascript:user_post('<?php echo $post['id']?>')">edit</a></td>
    	<td><a href="javascript:delete_post('<?php echo $post['id']?>')">delete</a></td>
    </tr>
    
    

     

    THANKS!

     

  2. Hi all - new here so please be gentle!

     

    I have a html table generated from php and am using a script I found on the net to export it to csv. The problem is, the exported csv file stops at the 2nd column and never starts a new row, plus has an empty column at the end. Obviously i want several rows (depending on the mysql query used to populate the table, it could be tens of rows long.) Is any one please able to help me shed some light as to what's going wrong?

     

    Thanks

     

    <table class="statistics">
    <thead>
    <tr><th>
    Name
    </th><th>
    Email
    </th><th>
    Date
    </th></tr>
    </thead>
    <tbody>
    <?php if( $page['reportByDate'] ) { ?>
            <?php foreach( $page['reportByDate'] as $row ) { ?>
            <tr>
                    <td><?php echo $row['name'] ?></td>
                    <td><?php echo $row['email'] ?></td>
                    <td><?php echo $row['date'] ?></td>
            </tr>
            <?php } ?>
    
    <?php } else { ?>
    <?php } ?>
    </tbody>
    </table>
    
    <?php } ?>
    
    <?
    
        $csv_hdr = "Name, Email, Date";
        $csv_output .= $row['name'] . ", ";
        $csv_output .= $row['email'] . ", ";
        $csv_output .= $row['date'] . ", ";
    
        $csv_output .= $row['value'] . "\n"; //ensure the last column entry starts a new line ?>
    
    <?
    
    ?>
    <br />
    <center>
    <form name="export" action="export.php" method="post">
        <input type="submit" value="Save as CSV">
        <input type="hidden" value="<? echo $csv_hdr; ?>" name="csv_hdr">
        <input type="hidden" value="<? echo $csv_output; ?>" name="csv_output">
    </form>
    </center>
    
    

     

    <?php
    /*
    This file will generate our CSV table. There is nothing to display on this page, it is simply used
    to generate our CSV file and then exit. That way we won't be re-directed after pressing the export
    to CSV button on the previous page.
    */
    
    //First we'll generate an output variable called out. It'll have all of our text for the CSV file.
    $out = '';
    
    //Next we'll check to see if our variables posted and if they did we'll simply append them to out.
    if (isset($_POST['csv_hdr'])) {
    $out .= $_POST['csv_hdr'];
    $out .= "\n";
    }
    
    if (isset($_POST['csv_output'])) {
    $out .= $_POST['csv_output'];
    }
    
    //Now we're ready to create a file. This method generates a filename based on the current date & time.
    $filename = $file."_".date("Y-m-d_H-i",time());
    
    //Generate the CSV file header
    header("Content-type: application/vnd.ms-excel");
    header("Content-disposition: csv" . date("Y-m-d") . ".csv");
    header("Content-disposition: filename=".$filename.".csv");
    
    //Print the contents of out to the generated file.
    print $out;
    
    //Exit the script
    exit;
    ?>
    

     

    [attachment deleted by admin]

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