Thread: PHP and arrays

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    England
    Posts
    1
    Rep Power
    0
    I am fairly new to PHP and becoming a bit frustrated with arrays.

    Is their any good stuff on the net anywhere about arrays?

    Can someone tell me if you can open a resultset within MySQL and bang it straight into an array without navigating through the resultset and adding the rows into the array?

    Any help please!!!!!
  2. #2
  3. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    I'm not entirely sure I follow your question, but I'll give it a shot anyway.

    As for resources, there are tons of em' and the best ones are matter of opinion, I'd recommend php.net and hotwired.lycos.com/webmonkey/

    check their section on PHP.

    as for the last one.. there are several ways to get your info from mysql, and in the bulk of the methods the information is "always" in an array..

    fe:
    $sql="SELECT * FROM whatever";
    $result = mysql_query($sql);
    $myrow = mysql_fetch_array($result);

    naturally this is only an example, if you were truly pulling data from the mysql_fetch_array() you'd be running that from a while or for loop.

    but you can also run mysql_fetch_row(), assuming that you're only pulling back one row of data, in which you'd reference the values from an associative array..

    $myrow = mysql_fetch_row($result);
    $myitem1 = $myrow["item1"];
    $myitem2 = $myrow["item2"];

    etc...

    I don't know if that answers the question, but I hope it helps.

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  4. #3
  5. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4476
    I think you pretty much have to step through the result set one row at a time, and assign that row to an array. you can make a loop to put the whole result into an array, then use that array later on to print your page. or you can make a loop to get a row, print out the data for that row, then loop to the next row. here's how i usually output data from mysql.
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $query=mysql_db_query($database,"select id,fname,lname from contactinfo",$link_id);
    while (list ($id,$firstname,$lastname) = mysql_fetch_row($query))
    {
    echo "ID: $id, First Name: $firstname, Last Name: $lastname<br>n";
    }
    [/code]

    that might not help, but it's my $0.02...

    ---John Holmes...

Similar Threads

  1. Arrays with register globals off
    By mejohn in forum PHP Development
    Replies: 1
    Last Post: February 15th, 2004, 06:49 AM
  2. multiple searches using php
    By lizzy_b100 in forum PHP Development
    Replies: 14
    Last Post: February 10th, 2004, 11:26 AM
  3. Combining arrays
    By getting_there in forum PHP Development
    Replies: 5
    Last Post: January 23rd, 2004, 04:07 PM
  4. Javascript and PHP: urgent
    By tanvirgaus in forum JavaScript Development
    Replies: 3
    Last Post: January 20th, 2004, 12:53 PM
  5. URGENT multiple selections in list ,processed with PHP & MYSQL
    By jt-developer in forum PHP Development
    Replies: 1
    Last Post: January 15th, 2004, 06:37 AM

IMN logo majestic logo threadwatch logo seochat tools logo