WEB php guys... mysql_data_seek question (indexed -> associative)

Discussion in 'OT Technology' started by brds, Nov 9, 2009.

  1. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,647
    Likes Received:
    15
    Location:
    Atlanta
    for an assignment, i need to run two queries and display the information in an indexed and assoc. array (query 1 for indexed, and query2 for assoc.). However, we get EC if we use the same query for both outputs. The teacher said "hint, research how to use mysql_data_seek"... got any ideas?

    Here's what i got so far:

    Code:
    <?php
        $all = $connection->runQuery("SHOW TABLE STATUS;");
        $numrows = $all[0]['Rows'];
        $numcols = count($connection->runQuery("SHOW COLUMNS FROM flightsessions;"));
        
        $indexed = $connection->runQuery("SELECT * FROM flightsessions;");
        
        echo "Your query returned " . $numrows . " rows and " . $numcols . " fields:<br /><br />";
        
        echo "<h2>Indexed Array:</h2>
        <table width='100%' cellspacing='2' cellpadding='5'>
            <tr class='header'>
                <td class='border'>Flight Date:</td>
                <td class='border'>Flight Time:</td>
                <td class='border'>Origin:</td>
                <td class='border'>Destination:</td>
                <td class='border'>Weather:</td>
                <td class='border'>Winds:</td>
                <td class='border'>Temp:</td>
            </tr>";    
        foreach ($indexed as $thisflight)
        {
            echo "
            <tr class='content'>
                <td class='border'>" . $thisflight['flight_date'] . "</td>
                <td class='border'>" . $thisflight['flight_time'] . "</td>
                <td class='border'>" . $thisflight['origin'] . "</td>
                <td class='border'>" . $thisflight['destination'] . "</td>
                <td class='border'>" . $thisflight['weather'] . "</td>
                <td class='border'>" . $thisflight['winds'] . "</td>
                <td class='border'>" . $thisflight['temp'] . "</td>
            </tr>";
        }
        echo "</table>";
            
    ?>
    
     
  2. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,647
    Likes Received:
    15
    Location:
    Atlanta
    That just kinda pushed the first element of each array piece... instead of being:

    Array:
    0:
    ---date:2007-02-15
    ---flight time:01:50:00
    ---ect...

    it's now:
    array:
    ---2007-02-15
    ---flight time:01:50:00
    ---ect...


    In other words, it took array the first level index and renamed it to the value that used to in the first spot.

    Let me explain a little bit more what the assignment was.


    We created a db, with a table that had the seven following columns:
    Flight Date, Flight Time, Origin, Destination, Weather, Winds, and Temp.

    we then had to enter some ficticious data into the table (six records to be exact). Now we have to print the results using an indexed array and an associative array. I got the index array no problem, but this fucking assoc. array is making me scratch my head. I'm sure as soon as i see the solution i'll wonder why i didn't realize the solution before... but for now, i'm drawing a blank.
     
  3. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,647
    Likes Received:
    15
    Location:
    Atlanta
    I got it... duh moment.
     

Share This Page