Jump to content

spenceddd

Members
  • Posts

    107
  • Joined

  • Last visited

    Never

Posts posted by spenceddd

  1. Do you know of any json manipulation functions that you mentioned above?

     

    Something that is equivalent to :

     

    var jsArrays = json_encode(multidimensionalArray);

     

    but that will allow me to store the multidimensional array in such a way that it can be successfully passed via post and held in a form element.

     

    Thanks

     

    Spencer

  2. Ah, sorry I keep replying but others keep beating me to it before I submit.

     

    Thanks for all the suggestions but djlee may have a point with posting the array, that sounds even simpler than using json....so to confirm can a post variable hold a multidimesional array?..and can a form item hold a js multidimesional array?

     

    thanks a million!

     

    Spence

     

     

  3. Hi,

     

    I've been stuck on this for a while now and I keep coming back to it only to hit another wall.

     

    What I am trying to do is allow a user to modify a table on a page then submit the changes by refreshing the page.

     

    I have setup the javascript to allow the user to alter the values of the table cells. These values then get passed to a hidden form element that keeps track of the updated rows information in the form of a multidimensional array. This array has all the information needed to update the mysql tables if only I could pass the array back to php when the table reloads.

     

    I have had success in passing a php array to javascript using json.

     

    I have already posted a thread about this thinking that a jquery ajax function would work but I'm not sure that's necessary plus the thread was moved to the ajax forum where nobody seems to post.

     

    Could anyone please help me with this?

     

    Any help much appreciated...

     

    Spencer

  4. Just to elaborate on what I am trying to achieve here (incase I have overcomplicated it in the first place).

     

    I am updating a mysql database with information on the page which ultimiately ends up in a multidimensional js array. So when the page reloads it needs to update the mysql table before the same page then creates the table in html further down in the code.

     

    I have used JSON encode to pass info from php to js with great success but through my research I am coming up with mainly this ajax jquery function to pass from js to php via POST.

     

    Hope that makes sense.

     

    Please let me know if there is a simpler way to achieve this.

     

    Thanks for any advice here.

     

    Spencer

  5. Thanks for your help Crayon.

     

    I have tried to test your code but the php echo doesn't seem to echo.

     

    I also had to add the submit button on the page so I could trigger and test that php was picking up the array on reloading the page:

     

    <?php  // check if something is posted
    if ($_POST) {  
    // dump out what is posted.  This is what is going to be output for the AJAX call  
    echo "<pre>";print_r($_POST); echo "</pre>";  
    // exit the script so that it doesn't output the rest of the stuff in the script  
    exit();}
    ?>
    <html> 
    <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
    <script src="jquery.js"></script>
    <script type="text/javascript"> 
    var a = {};
    a['test'] = 1;
    a['test2'] = 2;
    $.ajax({    
    url: "test.php",    
    data: a,    
    type: 'post', 
    // this is your callback function   
    success: function(data) {          
    // update the contents of a div with the results of the ajax call    
    $('#someDiv').html(data);	  
    }
    });
    </script>
    </head>
    <body>
    <form action="test.php" method="post">
    <input name="" type="submit"></form>
    <!-- div to update with AJAX results -->
    <div id='someDiv'>
    </div>
    </body>
    </html>

     

     

    Sorry if I'm missing something obvious here...

     

    Thanks again for any help on this!

  6. Hi Guys,

     

    I've been doing some research and this to be a popular way to tackle this but for some reason it's not working for me:

     

    <?php  
    
    $test01=$_POST['test'];
    $test02=$_POST['test2'];
    echo($test01);
    
    ?>
    <html> 
    <head>
    <title>Portfolio item logger</title>
    <script src="AC_RunActiveContent.js" language="javascript"></script>
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
    <script type="text/javascript"> 
    //var existingPortfolioItems = new Array();
    alert(<? $_POST['test']; ?>);
    
    var a = {};
    a['test'] = 1;
    a['test2'] = 2;
    
    $.ajax({  url: "http://www.spencercarpenter.co.uk/portfolioAppFiles/jsArrayToPhpTest.php",  data: a,  type: 'post',  success: function(data) {      }});
    
    </script>
    <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
    </head>
    <body>
    <form action="jsArrayToPhpTest.php" method="post">
    <input name="" type="submit">
    </form>
    </body>
    </html>

     

     

    If anyone could help me I would be very grateful.

     

    I think I'm missing something fundamental here...

     

    Thanks

     

    Spencer

     

  7. Thanks for your suggestion maca but I don't really understand how that works. How would I then be able to access the whole array in js?

     

    The reason I am doing this is because I want to only query the db when the page is loaded. After that I would like to be able to manipulate the data clientside with out having to go back to the server...

  8. Hi,

     

    I am trying to work out how to populate a multi-dimensioanl array in javascript with php.

     

    The php array $rows looks like this:

     

    Array (

    [0] => Array (

    [id] => 105 [name] => Golf 3d model [creationDate] => 04/10/07 [dateCreated] => 31/01/2010 21:03 [dateModified] => [shortDesc] => This Golf was modelled as an experimental project to work on my experience using Maya. [longDesc] => [relatedItem01] => 0 [relatedItem02] => 0 [relatedItem03] => 0 [img01] => Golf_3d_model.jpg [img02] => -1 [img03] => -1 [img04] => -1 [img05] => -1 [download] => => -1 [logo] => -1 [keywords] => )

    [1] => Array (

    [id] => 103 [name] => AM Awards Pitch Visual 2010 [creationDate] => 04/12/2009 [dateCreated] => 20/01/2010 17:40 [dateModified] => [shortDesc] => Visuals created for a pitch to win an Awards night event. [longDesc] => Visuals created for a pitch to win an Awards night event. [relatedItem01] => 0 [relatedItem02] => 0 [relatedItem03] => 0 [img01] => AMAwardsCloseUp.jpg [img02] => AMAwardsWide01.jpg [img03] => -1 [img04] => AMAwardsCloseUp02.jpg [img05] => -1 [download] => => CrossrailTrainingVideo.flv [logo] => -1 [keywords] => awards evening visualisation visualization )

    [2] => Array (

    [id] => 104 [name] => ARM 2010 pre-visualisation [creationDate] => dd/mm/yy [dateCreated] => 26/01/2010 17:18 [dateModified] => [shortDesc] => These visuals were part of a large set of visuals at an early stage of the project. [longDesc] => These visuals were part of a large set of visuals at an early stage of the project. [relatedItem01] => 0 [relatedItem02] => 0 [relatedItem03] => 0 [img01] => ARM2010_OutsideOfMarquee01.jpg [img02] => ARM2010InsideMarquee01.jpg [img03] => ARM2010_Marquee_Lid_off01.jpg [img04] => ARM2010InsideMarquee02.jpg [img05] => -1 [download] => => -1 [logo] => -1 [keywords] => )

    [3] => Array (

    [id] => 100 [name] => Triangulus Logo [creationDate] => 04/12/10 [dateCreated] => 02/01/2010 13:08 [dateModified] => [shortDesc] => This is the Triangulus logo, a new Vendor Management Consultancy. Concept to Completion. [longDesc] => [relatedItem01] => 103 [relatedItem02] => 100 [relatedItem03] => 100 [img01] => Triangulus-Final-Logo.jpg [img02] => Trianulgus Logo Initial Concept.jpg [img03] => -1 [img04] => -1 [img05] => -1 [download] => => TriangulusLogo.flv [logo] => -1 [keywords] =>

    )

    )

     

    and so far my code to transfer to js looks like this:

     

    <?
    foreach($rows as $key => $value)
    {
    echo "js_array[$key] = $value;\n";
    foreach($rows[$value] as $key => $value)
    {
    	echo "js_array[$key] = $value;\n";
    }
    
    }
    ?>
    

     

    Could anyone please help me to complete the code I need to get this working?

     

     

    Thanks for any help on this.

     

    Spencer

  9. Okay I have used the json object here (I think succesfully as it prints ok):

     

    
    //Request all info from database
    $query = "SELECT * FROM PortfolioItems ";   
    $wholePortfolioArray = mysql_query($query) or die(mysql_error()); 
       // iterate over every row
        while ($row = mysql_fetch_assoc($wholePortfolioArray)) {
            // for every field in the result..
            for ($i=0; $i < mysql_num_fields($wholePortfolioArray); $i++) {
                $info = mysql_fetch_field($wholePortfolioArray, $i);
                $type = $info->type;
    
                // cast for real
                if ($type == 'real')
                    $row[$info->name] = doubleval($row[$info->name]);
                // cast for int
                if ($type == 'int')
                    $row[$info->name] = intval($row[$info->name]);
            }
    
            $rows[] = $row;
        }
    
        // JSON-ify all rows together as one big array
        echo json_encode($rows);
        
       
    

     

    Now I am trying to recall the info in javascript.

     

    Could anyone help me print the array in javascript?

     

    Thanks again for any help on this.

     

    Spence

  10. Hello,

     

    Could anyone please show me how to access specific items from the array returned from this request:

     

    //Request all info from table
    $query = "SELECT * FROM PortfolioItems ";   
    $wholePortfolioArray = mysql_query($query) or die(mysql_error()); 
    

     

    ...where the table looks like:

     

    ID MN OX DD

    01 YY NN XX

    02 YY MM XX

    03 NN MM XX

    04 NN MN XO

     

    For instance I would like to return just the 'ID' and 'OX' colomns of each row.

     

    I would also like to know how to return the value at ID = 03, colomn 'MN'.

     

    The reason I am doing it like this is because I only want to make the request to the server before the page loads. After that I want to use javascript to sort through the information.

     

    Maybe there is a way to convert the entire array to a javascript array for client side access...?

     

    Thanks very mcuh for any help.

     

    Spencer

     

     

     

     

  11. Hi,

     

    I cannot work out how to append my php variable ($username) onto the following code:

     

    
    if (($_POST['username'] == $usernameCheck) && ($_POST['password'] == $passwordCheck)){
    	session_start(); 
      		session_register('username'); 
    	//load simpleForm.php page using javascript
    	echo ("<script>
    	<!--
    	location.replace(\"DevelopmentFiles/JobAdmin/JobAdmin.php\");
    	-->
    	</script>");
    	$failureMessage="";
    }
    
    

     

    I am just trying to pass a username to the next page using the url (the  location replace bit) so I can retrieve using a get command on the target page. Struggling really to get the exact syntax right...

     

     

    Sorry I am still a php novice!

     

    Thanks for any help on this.

     

    Spencer

     

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