Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13

Thread: array help

  1. #1
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post

    array help

    ok I have the following structure of data that I want to store in a array:

    t_id,name,b_id_blog for each tag how can I store these 3 pieces data together in a array? so when I edit them I can do a Udate SQL statement?

  • #2
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    post your simple code of editing one type. maybe you can do something with associative array, but it all depends on what you need eg

    $t_id_code array (
    "t_id" => "sql statement id",
    "name" => "sql statement name",
    "b_id_blog" => "sql statement b_id"
    )

    Then use it in your function, with foreach or just crude array selection, something like

    $t_id_code['t_id'], yould then use the sql statement you have for id

    Btw, if you set your ID to auto_increment, it will be stored as 1,2,3.. etc, without the need to set it in any way...

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Ideally(at least to me) it would be in an array that looked like
    PHP Code:
    $array = array(
                
    '123' => 'tag',
                
    '456' => 'othertag'
            
    );

    // This is so you can 
    foreach($array as $id => $tag)
    {
        
    // update


  • #4
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post
    Yeah, t_id is automatic, this is for figuring out updating of tags for the editing of a post.

  • #5
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    well for editing posts you can only use ID to reach the post. eg, if you see on forums something like showthread.php?t=122259, t=122259 it's the id of a post. if you ever moderated forum (rg vbulletin) you have select option near post.

    when you select post you want to move/delete/lock/stick, you reach it by id.

    i can't say more couse i just started learning SQL, but if you have some code you started, i guess ppl here could help you more

  • #6
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post
    Here is the code I have so far
    PHP Code:
    /*
        *    Function Update POst 
        *    This handles the changes to the post, With out updating the POST date
        */
        
    function updatePost($postID,$title,$author,$bdate,$body,$tags){
            
    $sql ="UPDATE blog SET title='$title',body='$body',author='$author',date='$bdate' WHERE id='$postID' ";
            
    $results connect($sql);
            if(
    $results == false){
                echo 
    "<div class=\"error_msg\">Sorry Couldn't Update the Blog Post</div>";
            }
            else{
                
    $rmTags "DELETE tags.* FROM tags WHERE tags.b_id_blog = '$postID'";
                
    connect($rmTags);
                
    $tags explode(",",$tags);
                foreach(
    $tags as $tag){
                       
    $mktags "INSERT INTO tags VALUES ('','$tag','$postID')";
                    
    $results connect($mktags);
                } 
                if(
    $results == false){
                    echo 
    '<div class="error_msg">Sorry Couldn\'t Update the Blog Post due to the Tags.</div>';
                }
                else{
                    echo 
    '<div class="ok_msg">Blog Post Updated Successfully.</div>';
                }
            }
        } 
    I'm gotta figure out still is storing html in side the post I'm thinking about using html_encode and then when getting the post html_decode. This is a inefficient way to handle the updating the post tags. Suggestions?

  • #7
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post
    when I go to use the function I get the following error

    Unable to query local database Unknown column 'id' in 'where clause'
    UPDATE blog SET title='HTML encoding test',body='moos3',author='<p>This is <b>A test of HTML Storing</b> in the Database.</p><p>Old tags: php,site,test New tags: admin,functions,eskimo,maine',date='1188151333' WHERE id=''

  • #8
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    $postID is apparently empty, and you don't have an "id" column.

  • #9
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post
    ok, fixed that but now its deleting the post on update.

  • #10
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post
    ok, fixed everything but now I'm having a date issue, when I use the unix timestamp and then push it back into the database it ****s the bed and makes the post be in 1969. Suggestion? if I use the date function and then push it back to the data its not going to change it is ?

  • #11
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Check the database to make sure the timestamp is there. As long as you don't overwrite the timestamp when you use date() it shouldn't change.

  • #12
    Regular Coder
    Join Date
    Aug 2007
    Location
    maine,usa
    Posts
    151
    Thanks
    2
    Thanked 1 Time in 1 Post
    Unable to query local database You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE b_id='20'' at line 1
    UPDATE blog SET title='test post',body='this is a test that will be updated with content. This is new content. old tags php,site,tes new tags beer,i,rock,php,world',author='moos3', WHERE b_id='20'

    I removed the date and now get the above error.

  • #13
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Remove the comma after author='moos3'.


  •  

    Posting Permissions

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