Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    69
    Rep Power
    1

    Question How To Add More Than One Entry On A Single Cell/Array Where Each Entry Is Separated B


    Programming buddies,

    I'm back online after nearly 2wks of offline. Gonna be harassing you guys again and more this time. Eeek!

    Anyway, right now, I'm trying to build a script that adds multi entries into same single cell or mysql row.
    The script tries monitoring what you are browsing via the:

    <pre><input type="text" name="browse_url" size="120"></pre>

    and then record your viewed urls into the same row (position: 0), column: browsings like so:

    1.com,2.com and so on.
    So, at first, the mysql array or cell is blank. When you view a url (eg.) 1.com then the array would show like this:

    1.com

    And then afterwards, if you view facebook.com then the cell should get updated by first grabbing the previously viewed urls and then adding the latest url onto the same cell/array like so (each url separated by comma):

    <pre>1.com,facebook.com</pre>

    Throw your precious eyes on line 79 onwards on both sample scripts. I reckon the 1st script is no good but the 2nd should work. Gave you both scripts to show the variety of ways I attempted.


    Sample 1:

    PHP Code:

    <pre><?php 
    session_start
    ();
    require 
    "conn.php";
    require 
    "site_details.php";

    /*Check if user is logged-in or not by checking if session is set or not. 
    If user is not logged-in then redirect to login page. Else, show user's account homepage.php.*/

    if(!isset($_SESSION["user"])) 
    {
        
    header("location:login.php");
    }
    else 
    {
        
    $user $_SESSION["user"];
        
    ?>
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
        <html>
        <head>
        <title>Browse!</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        </head>
        <body>
        <p>
        <p>
        <p>    
        <?php 
        
    //Display 'Browser' ?>
        <iframe src='<?php echo $db_latest_view;?>'></iframe>
        <p>
        <p>
        <p>
        <form method="post" action="">
        <table border="1" width="50%">
        <tr>
        <td width="10">Url: </td>
        <td><input type="text" name="browse_url" size="120"></td>
        </tr>
        <tr>
        <td width="10">Browse: </td>
        <td>
        <select name="browsing_type">
        <OPTION>Anonymous Browsing</OPTION>
        <OPTION>Group Browsing</OPTION>
        </SELECT>
        </td>
        </tr>
        <td></td>
        <td><input type="submit" name="browse" size="50" value="Browse"><input type="submit" name="search_keywords" size="50" value="Search Keywords"></td>
        <tr>
        <td width="10">Message: </td><td><textarea name="message" cols="120" rows="10"></textarea></td>
        </tr>
        <tr>
        <td></td>
        <td width="50"><input type="submit" name="submit_message" size="50" value="Send Message!"></td>
        </tr>
        <p>
        <p>
        </table>
        </form>
        
        <?php 
        
    if(isset($_REQUEST['browse'])) 
        {
            
    $browse_url trim(strip_tags(strtolower(mysqli_real_escape_string($conn,$_POST["browse_url"]))));
            
    $browsing_type trim(strip_tags(strtolower(mysqli_real_escape_string($conn,$_POST["browsing_type"]))));
            
            
    //Grab User details from database.
            
    $sql "SELECT * FROM users WHERE usernames = '".$user."'";    
            
    $result mysqli_query($conn,$sql);
            
    $numrows mysqli_num_rows($result);
            if(
    $numrows
            {    
                while(
    $row mysqli_fetch_assoc($result))
                {
                    
    $db_user_browsings $row["browsings"];                
                }
                
                
    $sql "INSERT INTO users(browsings) VALUES('".$browse_url."''".$db_user_browsings."')";
                
    $result mysqli_query($conn,$sql);
                if(
    $sql)
                {
                    echo 
    "true";            
                }
                
                
    $sql "UPDATE users SET browsings_latest = '".$browse_url."' WHERE usernames = '".$user."'";
                
    $result mysqli_query($conn,$sql);
                if(
    $sql)
                {
                    echo 
    "true";            
                }                
            }
        }
    }

    ?>
    </pre>
    Sample 2

    PHP Code:

    <pre><?php 
    session_start
    ();
    require 
    "conn.php";
    require 
    "site_details.php";

    /*Check if user is logged-in or not by checking if session is set or not. 
    If user is not logged-in then redirect to login page. Else, show user's account homepage.php.*/

    if(!isset($_SESSION["user"])) 
    {
        
    header("location:login.php");
    }
    else 
    {
        
    $user $_SESSION["user"];
        
    ?>
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
        <html>
        <head>
        <title>Browse!</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        </head>
        <body>
        <p>
        <p>
        <p>    
        <?php 
        
    //Display 'Browser' ?>
        <iframe src='<?php echo $db_latest_view;?>'></iframe>
        <p>
        <p>
        <p>
        <form method="post" action="">
        <table border="1" width="50%">
        <tr>
        <td width="10">Url: </td>
        <td><input type="text" name="browse_url" size="120"></td>
        </tr>
        <tr>
        <td width="10">Browse: </td>
        <td>
        <select name="browsing_type">
        <OPTION>Anonymous Browsing</OPTION>
        <OPTION>Group Browsing</OPTION>
        </SELECT>
        </td>
        </tr>
        <td></td>
        <td><input type="submit" name="browse" size="50" value="Browse"><input type="submit" name="search_keywords" size="50" value="Search Keywords"></td>
        <tr>
        <td width="10">Message: </td><td><textarea name="message" cols="120" rows="10"></textarea></td>
        </tr>
        <tr>
        <td></td>
        <td width="50"><input type="submit" name="submit_message" size="50" value="Send Message!"></td>
        </tr>
        <p>
        <p>
        </table>
        </form>
        
        <?php 
        
    if(isset($_REQUEST['browse'])) 
        {
            
    $browse_url trim(strip_tags(strtolower(mysqli_real_escape_string($conn,$_POST["browse_url"]))));
            
    $browsing_type trim(strip_tags(strtolower(mysqli_real_escape_string($conn,$_POST["browsing_type"]))));
            
            
    //Grab User details from database.
            
    $sql "SELECT * FROM users WHERE usernames = '".$user."'";    
            
    $result mysqli_query($conn,$sql);
            
    $numrows mysqli_num_rows($result);
            if(
    $numrows
            {    
                while(
    $row mysqli_fetch_assoc($result))
                {
                    
    $db_user_browsings $row["browsings"];                
                }
                
                
    $sql "UPDATE users SET browsings = '".$browse_url."''".$db_user_browsings."' WHERE usernames = '".$user."'";
                
    $result mysqli_query($conn,$sql);
                if(
    $sql)
                {
                    echo 
    "true";            
                }    
                
                
    $sql "UPDATE users SET browsings_latest = '".$browse_url."' WHERE usernames = '".$user."'";
                
    $result mysqli_query($conn,$sql);
                if(
    $sql)
                {
                    echo 
    "true";            
                }                
            }
        }
    }

    ?>
    </pre>
  2. #2
  3. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,109
    Rep Power
    2010
    Having "multi entries into same single cell" should be avoided.

    Why don't you have a table with three columns: userid, url, visited, where 'visited' tells the time stamp on which the url was last seen?
    Adding userid and url as a combined unique index, you can then update 'visited' with current time-stamp if the combination of those two columns already exists.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    69
    Rep Power
    1

    Question


    Originally Posted by MrFujin
    Having "multi entries into same single cell" should be avoided.

    Why don't you have a table with three columns: userid, url, visited, where 'visited' tells the time stamp on which the url was last seen?
    Adding userid and url as a combined unique index, you can then update 'visited' with current time-stamp if the combination of those two columns already exists.
    Thanks for your suggestion but I have reasons for doing it the way I am. I need to learn how to add multi entries into same cell/array (position: 0).

    I first did add a comma and coded a variety of different ways and they all throwed error. The only 2 that didn't throw error is what I listed in this thread but as you can see the entries are not being separated by commas. I get no error with these 2 codes, though.
    Yes, you have figured correctly what I want to do. But, I'll explain again and you can be kind enough to show a few example codes.

    EXAMPLE
    Imagine you viewed 1.com now on your first session. 1.com would be listed on the following columns:

    latest_browsings
    browsings (full history).

    So now, the columns would look like this:

    BROWSINGS | LATEST_BROWSINGS
    1.com | 1.com


    Now, if you move-onto 2nd.com then that would be UPDATED on the latest_browsings column but INSERTED in the browsings column.
    So now, the columns would look like this:

    BROWSINGS|LATEST_BROWSINGS |
    1.com | 2.com
    2.com|


    Note the "Browsings" column show your full browsing history (like your browser shows you when you click CTRL+H. The "latest_browsings" shows you the most current page you viewed (like a Status Update thingy in social network accounts. So, "latest_browsings" only show data from position zero. No other rows get filled).
    Now, how would you code to achieve that ? Where should I make the change ?

    Thanks in advance! :slight_smile:
  6. #4
  7. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,109
    Rep Power
    2010
    I'm really curious why you need to learn it that way.

    You haven't told what happens when you run your current code. Any errors?
    How does your sql look like if you echo it out?

    FYI, You can set several values in one update:
    PHP Code:
    $sql "UPDATE users SET browsings = '".$browse_url."''".$db_user_browsings."',browsings_latest = '".$browse_url."' WHERE usernames = '".$user."'"
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,245
    Rep Power
    602
    I'm curious as well. Why would someone want or need to learn a poor programming practice?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    69
    Rep Power
    1
    I get no error in my 2 sample code mentioned in my original post but I don't get entries dumped in position zero separated by comma either.

    My .exe bot shows data like this:

    username timestamp url
    mr_fujin 2017/04/10 18:00:00 301 Moved Permanently
    ui man 2017/04/10 18:10:00 www.microosft.com
    mr_fujin 2017/04/10 18:15:00 http://forums.devshed.com

    Actually, the columns were:
    TimeStamp|Id|Username|Browsing_Histories|Contact_Details
    (Ofcourse, if any public tries contacting any user (like you) then they'd have to go through filling-in a cpa survey before they see your contact details. Thus earn you $1-20 cpa earning.
    Bear in mind, this is one tbl with many cols and not more than one tbl. "Browsings_History" tbl that shows all users browsing history on a single webpage. It is like a SERP with GO TO NEXT PAGE facility. Imagine a google serp.

    But I NOW want my web version of the bot or member site/social network (sn) to show like this:

    Username | Browsing_Histories |
    mr_fujin | "http://forums.devshed.com, www.microosft.com, www.url.com"
    ui man | "http://forums.devshed.com, www.facebook.com, www.google.com"

    Originally, I wanted the SN to show like this:

    Username | Browsing_Histories | Latest_Viewings
    mr_fujin | "http://forums.devshed.com, www.microosft.com, www.url.com" | 301 Moved Permanently
    ui man | "http://forums.devshed.com, www.facebook.com, www.google.com" | www.google.com

    That way, the left iframe shows you your friends' Latest_Viewings column, row 0.
    And the right iframe shows you all your friends browsing histories (Browsing_Histories) column.

    Anyway, let me experiment and decide how it should display the data to the user. Right now, I need to learn how to add more than one entry on the same cell/array separated by commas. The code I learn might become handy in future on other projects where it is necessary to have more than one entry on a single cell/array and it is right and recommended to do so like that.
    A cell is called array, right ? We say array in php and cell in ms excell. Correct ?
    I did once download a youtube tut that showed how to code to dump many entries into a single cell. I might aswell see if I can find it.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    69
    Rep Power
    1
    I already have an .exe bot that has a TIMESTAMP column. Now trying to build the web version and I would add the TIMESTAMP on that too. But the reason for having 2 columns:

    Browsings
    Latest_View

    Is because as soon as you login to your account, you will see 2 iframes. One on the left and one on the right.
    The left one would show you the latest page you friend viewed. The right iframe would show all row data from the BROWSINGS (full history) column (like google SERP) so you can trace your friends website visits. So, as you can see, to make things easier to deal with the iframe and all, I need 2 columns so each iframe opens to their respective columns (so to speak).

    I have a feeling you are now gonna tell me to just program the left iframe to open to the final row (BROWSINGS) and forget the Latest_View column. Am I right ?

    A programmer told me (another subject) to use the following code to get the script to spit out the final row of the column:

    SELECT * FROM users
    ORDER BY id DESC
    LIMIT 1

    Do you have any suggestions yourself ? Remember, his code suggestion was not related to this thread and so might not be too good (ORDER by id) for this thread's subject.
    I asked for a code sample how to get script to show only final record.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    69
    Rep Power
    1
    Yes, you are correct. My .exe bot shows data like this:

    username timestamp url
    droopsnot 2017/04/10 18:00:00 301 Moved Permanently
    ui man 2017/04/10 18:10:00 www.microosft.com
    droopsnot 2017/04/10 18:15:00 www.sitepoint.com

    Actually, the columns were:
    TimeStamp|Id|Username|Browsing_Histories|Contact_Details
    (Ofcourse, if any public tries contacting any user (like you) then they'd have to go through filling-in a cpa survey before they see your contact details. Thus earn you $1-20 cpa earning.
    Bear in mind, this is one tbl with many cols and not more than one tbl. "Browsings_History" tbl that shows all users browsing history on a single webpage. It is like a SERP with GO TO NEXT PAGE facility. Imagine a google serp.

    But I NOW want my web version of the bot or member site/social network (sn) to show like this:

    Username | Browsing_Histories |
    droopsnot | "www.sitepoint.com, www.microosft.com, www.url.com"
    ui man | "www.sitepoint.com, www.facebook.com, www.google.com"

    Originally, I wanted the SN to show like this:

    Username | Browsing_Histories | Latest_Viewings
    droopsnot | "www.sitepoint.com, www.microosft.com, www.url.com" | 301 Moved Permanently
    ui man | "www.sitepoint.com, www.facebook.com, www.google.com" | www.google.com

    That way, the left iframe shows you your friends' Latest_Viewings column, row 0.
    And the right iframe shows you all your friends browsing histories (Browsing_Histories) column.

    Anyway, let me experiment and decide how it should display the data to the user. Right now, I need to learn how to add more than one entry on the same cell/array separated by commas. The code I learn might become handy in future on other projects where it is necessary to have more than one entry on a single cell/array and it is right and recommended to do so like that.
    A cell is called array, right ? We say array in php and cell in ms excell. Correct ?
    I did once download a youtube tut that showed how to code to dump many entries into a single cell. I might aswell see if I can find it.
  16. #9
  17. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,109
    Rep Power
    2010
    I am not sure if am missing some (missing) posts above?

    An array in PHP is a list of values, which in Excel would be equivalent to a row of cells.
    A cell only have one value.

    Before you go too much deeper into one cell with multiple values, please take a look at this example:
    Example of user browser history in second table
    (you might have to refresh the page if it doesn't work the first time)

    Just ask if there is anything in the example that is not clear.
  18. #10
  19. Not An Expert
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2015
    Posts
    404
    Rep Power
    3
    UniqueIdeaMan - nothing in my post below is about your coding problem. Everything I say below is about posting on our forums only.

    Originally Posted by UniqueIdeaMan
    I am not sure if am missing some (missing) posts above?
    I'm glad I'm not the only one confused...to my knowledge, no posts were removed from this thread. I'm afraid that UniqueIdeaMan, you are just a little hard to understand - are you cross posting these questions in other threads and updating them or something?

    Also, in the future, if you quote someone in a Dev Shed forum post you can use [quote] tags the same way that you use [code] and [php] tags to set that text apart as a quote. If you set the first tag (the one that is placed before the quoted text string) as [quote=name], where "name" is set to the name of the quoting user, you can even mark quotes with their sources.

    This may help our users to understand you better in the future
  20. #11
  21. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,652
    Rep Power
    4495
    You need to learn (accept) to structure the data correctly in the database and then determine the appropriate queries to pull the data you want.

    Until that, we're teaching you to pound a square peg into a round hole and wasting everyone's time.

    -John
    -- Cigars, whiskey and wild, wild women. --
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    69
    Rep Power
    1
    Originally Posted by MrFujin
    I am not sure if am missing some (missing) posts above?

    An array in PHP is a list of values, which in Excel would be equivalent to a row of cells.
    A cell only have one value.

    Before you go too much deeper into one cell with multiple values, please take a look at this example:
    Example of user browser history in second table
    (you might have to refresh the page if it doesn't work the first time)

    Just ask if there is anything in the example that is not clear.
    That is pretty impressive there! How did you manage to make that ?
    SQL Fiddle

    Excellent!
    Yes, originally, I wanted to code to get results like the final/bottom example you showed. But since so many, (actually all) programmers are against me adding more than one value in a mysql cell, then I'm taking their advice.
    They say, I should dump data the traditional way but only display data to however I want.
    So, if you don't mind me asking, what was the exact php codes that allowed you to display data like the last 2 examples in your sample ?
    SQL Fiddle
  24. #13
  25. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,109
    Rep Power
    2010
    The page I linked to allowed me to display my idea for the SQL part. I had no control of the actually displaying.

    If you want to learn to how to display your SQL data in table, I suggest you take a look at this page: How to Select Data from MySQL Database Tables Using PHP - Tutorial Republic.

    For the query itself, you would need to look at this:
    PHP Code:
    $sql "select users.username as username_grouped, GROUP_CONCAT(userhistory.siteurl) as combined_list  from userhistory
    inner join users on users.userid = userhistory.userid
    group by users.userid"

    Alternative add a where clause when you want to select result for a specific user only:
    PHP Code:
    $sql "select users.username as username_grouped, GROUP_CONCAT(userhistory.siteurl) as combined_list  from userhistory
    inner join users on users.userid = userhistory.userid
    where users.username = "
    $user ."
    group by users.userid"

  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    69
    Rep Power
    1

    Question


    Originally Posted by markroberts

    Originally Posted by UniqueIdeaMan
    I am not sure if am missing some (missing) posts above?


    Mark Roberts, I never made such a comment. Don't know why this forum quoted that in your post.
    Seems like Mr Fujin said that. Not me. You edited the name from his to mine in that quote.
    Last edited by UniqueIdeaMan; April 17th, 2017 at 06:50 AM.
  28. #15
  29. Not An Expert
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2015
    Posts
    404
    Rep Power
    3
    Then perhaps there was a misunderstanding. You should have the ability to edit your posts - you may need to refresh the page after making a post in order to get the "edit" button to appear.

    But let's return to the topic of your coding. Evidently my comments were off-topic and not worth discussing. Please ignore them.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo