Results 1 to 32 of 32

Thread: [RESOLVED] arrays

  1. #1

    Thread Starter
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Resolved [RESOLVED] arrays

    im making an array that works off a form. i have a text box where i type the info and i want that info taken and added to the array and to bew included in my foreach loop. i also want the script to check to make sure wat im adding hasnt been added already. how would i do this?
    Last edited by ninjanutz; Oct 6th, 2005 at 10:09 PM.

  2. #2

    Thread Starter
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: arrays

    also how could i get the information added to be organized into colums?

  3. #3
    Lively Member {yak}'s Avatar
    Join Date
    Aug 2005
    Posts
    119

    Re: arrays

    $_POST[] is an array. Maybe you can explain a little more? To check to see if a value is allready in an array, you can use in_array()
    {yak}

  4. #4

    Thread Starter
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: arrays

    its like $movies = array ();
    movies[1] = harold and kumar go to white castle;
    movies[2] = blah...;

    and so on

  5. #5

    Thread Starter
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: arrays

    also i couldnt find an example of the in array function that finds the value enter all the examples find a set value.

  6. #6
    Lively Member {yak}'s Avatar
    Join Date
    Aug 2005
    Posts
    119

    Re: arrays

    You couldn't find an example of in_array()?
    PHP Code:
    if(!in_array($_POST['blah']))
    {
        
    //add your value

    Or I don't think I get what you mean
    {yak}

  7. #7
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: arrays

    he wants to look thru an array, see if an element is in it, if not add it to the array. I only know because i spoke to him on AIM..i know..he speaks in gibberish :P

  8. #8
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: arrays

    [REMOVED BY MOD] ....
    Last edited by visualAd; Sep 22nd, 2005 at 12:17 AM. Reason: insult
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  9. #9

    Thread Starter
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: arrays

    [REMOVED BY MOD]





    jk
    Last edited by visualAd; Sep 22nd, 2005 at 12:17 AM. Reason: language

  10. #10

    Thread Starter
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: arrays

    does anyone know?

  11. #11
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: arrays

    Oi - stoppit - if you arn't going to help then don't post and if you have nothing polite to say then don't bother either.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  12. #12
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: arrays

    Yes, you need the in_array function:
    PHP Code:
    /* test if value is in the array */
    if (! in_array($_POST['value'], $array)) {
        
    $array[] = $_POST['value']; // add the value to the array

    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  13. #13
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: arrays

    uhh....wut did i say...lol....
    I thought i was helpful.... i dont even remember posting to this... wierd...


    Im just asking this... cuz i was away from computer and had this site open.
    And i found my sister in here...

    She likes to "make me say" "stupid" 'things'

    if it was hurtful... i am sorry... and she will be punished(no net for a 3 weeks ^_^)
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  14. #14

    Thread Starter
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: arrays

    its ok lol and its not impolite if u say jk i love you visual add and plagues my hero

  15. #15

    Thread Starter
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: arrays

    wat can i add though to make sure it does it right adding the value atribute makes that malue appear in the box on startup

  16. #16
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: arrays

    The post index corresponds to the name attributes of the form elements. Therefore, the following HTML will cause the $_POST array to have a value1 index and a value2 index:
    HTML Code:
    <input name="value1" />
    <input name="value2" />
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  17. #17

    Thread Starter
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: arrays

    um...

  18. #18
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: arrays

    well if your questions made sense maybe we would understand...

  19. #19
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: arrays

    Maybe um is his way of saying thanks for the help
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  20. #20

    Thread Starter
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: arrays

    i dun understan d visual ads post and my quiestion does make sense...even if it didnt remix u clarified it for me

  21. #21
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: arrays

    Quote Originally Posted by ninjanutz
    wat can i add though to make sure it does it right adding the value atribute makes that malue appear in the box on startup
    Could you elaborate a bit. I am not sure I understand what you mean.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  22. #22

    Thread Starter
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: arrays

    ok lol i have a text input and i want it to take that value.. add it to the array called movies...and make sure that the value being added doesnt already exist in the array

  23. #23
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: arrays

    PHP Code:
    if (! in_array($_POST['value'], $array)) {
        
    $array[] = $_POST['value']; // add the value to the array

    what dont you get??

  24. #24

    Thread Starter
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: arrays

    thje fact that wen i add a value atribute the name of that lets say value="movies" the word movies will show up in thew text box before anyone types anything in and i dont want that

  25. #25
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: arrays

    I see why you are confused now. Forget about the value attribute in HTML, this sets the default value for the field. You need to use the name attribute - the nam,e you give a field in the name attribute will be the name you use to access it in your PHP.
    HTML Code:
    <input type="text" name="music" />
    PHP Code:
    if (! in_array($_POST['music'], $array)) {
        
    $array[] = $_POST['music']; // add the value to the array

    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  26. #26

    Thread Starter
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: arrays

    its still not workin for some reason

    heres the code this might help alot more

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
    
    <html xmlms='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
    
    <html>
    <head>
    
    <title>Movie List</title>
    
    </head>
    <body>
    
    <div id = "movies" align = "center">
    <?php
    
    if (isset ($_POST ['submit']))
    {
    	if (! in_array($_POST['movies[]'], $movies))     
    	{
    		$array[] = $_POST['movies[]']; 
        		echo "<p>Your movie has been added!<br />
        		<form action = 'movielist.php' method = 'post'>
               	<input type = 'text' name = 'movies[]' value = 'movie' size = '50' />
                	<input type = 'submit' name = 'submit' value = 'Enter Movie' />
                	</form>";
    	} else {
    			echo "<p>This movie has already been entered</p>
        			<form action = 'movielist.php' method = 'post'>
               	        <input type = 'text' name = 'movies[]' value = 'movie'  size = '50' />
                		<input type = 'submit' name = 'submit' value = 'Enter Movie' />
                		</form>";
    	}
    
    } else {
    
               echo "<form action = 'movielist.php' method = 'post'>
                <input type = 'text' name = 'movies[]' value = 'movie'  size = '50' /><br />
                <input type = 'submit' name = 'submit' value = 'Enter Movie' />
                </form>";
    
    }
    
    $movies = array ();
    $movies[1] = blah;
    $movies[2] = argh;
    
    asort ($movies);
    
    foreach ($movies as $movies => $movie)
    {
      echo "$movie<br />\n";
    }
    
    ?>
    </div>
    
    </body>
    </html>

  27. #27

    Thread Starter
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: arrays

    i no some of the code is "bad coding" but i really dun care as long as it worx its fine for wat i need it to do

  28. #28
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: arrays

    shouldnt it be
    PHP Code:
    if ((in_array($_POST['music'], $array))!=true) {
        
    $array[] = $_POST['music']; // add the value to the array


  29. #29

    Thread Starter
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: arrays

    that doesnt work either...y is something so simple so complicated lol

  30. #30
    Lively Member {yak}'s Avatar
    Join Date
    Aug 2005
    Posts
    119

    Re: arrays

    Quote Originally Posted by |2eM!x
    shouldnt it be
    PHP Code:
    if ((in_array($_POST['music'], $array))!=true) {
        
    $array[] = $_POST['music']; // add the value to the array

    in_array() returns boolean, therefore:
    PHP Code:
    //this would say if not true, so false
    if(!in_array($_POST['music'], $array))

    //this would say if true
    if(in_array($_POST['music'], $array)) 
    See, there's no need for the == true or whatever, becuase either way it'll evaluate to true or false. I see I forgot the second parameter of in_array() in my post, good thing I posted the link to it though, right?
    But...this line here:
    Code:
     <input type = 'text' name = 'movies[]' value = 'movie'  size = '50' /><br />
    Shouldn't have the [] on movies, that would tell us it's an array, but that doesn't make much sense does it? And this line:
    Code:
    if (! in_array($_POST['movies[]'], $movies))
    Wouldn't work, the first parameter is expecting a value, that would return Array. But anways, take the brackets off of movies, and out of that if statement, and see what happends.
    {yak}

  31. #31
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: arrays

    Quote Originally Posted by visualAd
    I see why you are confused now. Forget about the value attribute in HTML, this sets the default value for the field. You need to use the name attribute - the nam,e you give a field in the name attribute will be the name you use to access it in your PHP.
    HTML Code:
    <input type="text" name="music" />
    PHP Code:
    if (! in_array($_POST['music'], $array)) {
        
    $array[] = $_POST['music']; // add the value to the array

    ....
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  32. #32

    Thread Starter
    Hyperactive Member ninjanutz's Avatar
    Join Date
    Jun 2005
    Location
    Bayside
    Posts
    256

    Re: arrays

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
    
    <html xmlms='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
    
    <html>
    <head>
    
    <title>Movie List</title>
    
    </head>
    <body>
    
    <div id = "movies" align = "center">
    <?php
    
    if (isset ($_POST ['submit']))
    {
    	if (! in_array($_POST['movies'], $array))
    	{
    		$array[] = $_POST['movies']; 
        		echo "<p>Your movie has been added!<br />
        		<form action = 'movielist.php' method = 'post'>
               	<input type = 'text' name = 'movies' size = '50' />
                	<input type = 'submit' name = 'submit' value = 'Enter Movie' />
                	</form>";
    	} else {
    			echo "<p>This movie has already been entered.</p>
        			<form action = 'movielist.php' method = 'post'>
               	        <input type = 'text' name = 'movies' size = '50' />
                		<input type = 'submit' name = 'submit' value = 'Enter Movie' />
                		</form>";
    	}
    
    } else {
    
               echo "<form action = 'movielist.php' method = 'post'>
                <input type = 'text' name = 'movies' size = '50' /><br />
                <input type = 'submit' name = 'submit' value = 'Enter Movie' />
                </form>";
    
    }
    
    $movies = array ();
    $movies[1] = blah;
    $movies[2] = argh;
    
    asort ($movies);
    
    foreach ($movies as $movies => $movie)
    {
      echo "$movie<br />\n";
    }
    
    ?>
    </div>
    
    </body>
    </html>
    k now i have this and when i type something in nothing happens except the page refresdhes with no changes

Posting Permissions

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



Click Here to Expand Forum to Full Width