SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2007
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Array and mysql

    Hi all,

    I have the following code but not sure how to insert into the array from a mySQL database.

    Can anyone please advise

    PHP Code:
    <?php
        
    require("../../connection/config.php");

        
    $year date('Y');
        
    $month date('m');

        echo 
    json_encode(array(
        
            array(
                
    'id' => 1,
                
    'title' => "Tenants Conference 2009",
                
    'start' => "$year-$month-10",
                
    'url' => "http://yahoo.com/",
                
    'description' => 'xxxxx'
            
    ),
            
            array(
                
    'id' => 2,
                
    'title' => "Event2",
                
    'start' => "$year-$month-10",
                
    'end' => "$year-$month-10",
                
    'url' => "http://yahoo.com/",
                
    'description' => 'cccccc'
            
    )
        
        ));
        
    ?>

  2. #2
    SitePoint Zealot
    Join Date
    Oct 2007
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay I have now figured out this but it will only insert 1 record into the array however when echo $count to see how many records should be there $count brings back 6

    Can anyone advise
    PHP Code:
    <?php

        
    require("../../connection/config.php");
        
    $events = array();
        
    $sql="SELECT * FROM events ORDER BY eventStartTime";
        
    $result=mysql_query($sql);    
        
    $count=mysql_num_rows($result);
        echo 
    $count;
        while(
    $row mysql_fetch_array($result))
        {
            
    $events'id'] = $row['eventId'];
            
    $events'title'] = $row['eventName'];
            
    $events'start'] = $row['eventStartDate'];
            
    $events'url'] ="http://yahoo.com/";
        }
        
        echo 
    json_encode(array($events));

    ?>

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php

        
    require("../../connection/config.php");
        
    $events = array();
        
    $sql="SELECT * FROM events ORDER BY eventStartTime";
        
    $result=mysql_query($sql);    
        
    $count=mysql_num_rows($result);
        echo 
    $count;
        while(
    $row mysql_fetch_array($result))
        {
            
    $events[] = array('id'    => $row['eventId'],
                              
    'title' => $row['eventName'],
                              
    'start' => $row['eventStartDate'],
                              
    'url'   => "http://yahoo.com/"
                             
    );
        }
        
        echo 
    json_encode(array($events));

    ?>
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •