Welcome Guest, Not a member yet? Register   Sign In
Possible to produce a javascript function from PHP?
#6

[eluser]Robb__[/eluser]
Ok, this is the whole flow.
in header.php
Code:
function get_clicklist(){
        
    var myAjax4 = new Ajax.Request('myweb/www/index.php/application/getclicklist/'  + sessionid ,{onComplete:show_get_clicklist_response});    //sessionid is a global variable.
        }
controller application.php
Code:
function getclicklist($sessionid)
    {
    $this->load->model('Load');
    $result['photolist'] = $this->Load->getclicklist($sessionid);      
    $noRows = $result['photolist']->num_rows();
    $result['NrRows'] = $noRows;
    $products['productlist'] = array();    
for($i=0; $i<$result['NrRows']; $i++){            
             $resultrow[$i] = $result['photolist']->row($i);
             $products['productlist'][$i] = $resultrow[$i]->Image;
    //echo $products['productlist'][$i];
    }

$this->load->view('result', $products)
        
        }

in the model load.php
Code:
function getclicklist ($sessionid)
        {
        $this->load->database();
        $sql = "SELECT J.Image FROM Jewellery J INNER JOIN Choice C ON J.ProductID = C.ProductID WHERE C.Nickname LIKE '" .$sessionid ."'";
        $query = $this->db->query($sql);
        
        return $query;
        }

The show_get_clicklist_response should be created by the $this->load->view('result', $products) call in controller application.php, function getclicklist.

result.php now looks like
Code:
function show_get_clicklist_response(response) {
    eval(response.responseText)    

YAHOO.example.container.photobox = new YAHOO.widget.PhotoBox("photobox",
                {
                    effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.45},
                    fixedcenter:true,
                    constraintoviewport:true,
                    underlay:"none",
                    close:true,
                    visible:false,
                    draggable:true,
                    modal:true,
                    photos:[
&lt;?php foreach ($productlist as $i => $photo ): ?&gt;
                       {src:"&lt;?= $photo; ?&gt;",caption:"test"},
&lt;?php endforeach; ?&gt;
{src:"http://static.flickr.com/8/12669712_be928a0d97.jpg",caption:"Dobb's Ferry, NY"}                          
],
                    width:"500px"
                } );
                YAHOO.example.container.photobox.render();
                
                YAHOO.util.Event.addListener("show", "click", YAHOO.example.container.photobox.show, YAHOO.example.container.photobox, true);
    }


So, hopefully I will have a response function to handle my call to the database, that delivers the clicklist images. The response function created from my call initiates the YUI-stuff needed to create my photobox.
I'm a bit confused now and have to lay down for a while :gulp:


Messages In This Thread
Possible to produce a javascript function from PHP? - by El Forum - 09-04-2007, 12:47 PM
Possible to produce a javascript function from PHP? - by El Forum - 09-04-2007, 01:50 PM
Possible to produce a javascript function from PHP? - by El Forum - 09-05-2007, 07:21 AM
Possible to produce a javascript function from PHP? - by El Forum - 09-05-2007, 11:04 AM
Possible to produce a javascript function from PHP? - by El Forum - 09-05-2007, 11:43 AM
Possible to produce a javascript function from PHP? - by El Forum - 09-06-2007, 04:30 AM
Possible to produce a javascript function from PHP? - by El Forum - 09-07-2007, 08:52 AM
Possible to produce a javascript function from PHP? - by El Forum - 09-07-2007, 09:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB