SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jun 2000
    Location
    Netherlands
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    I want to make a table on the searchresults of an sql string which pakkets the customer can deliver. ("SELECT * FROM customer, products WHERE customer_id=productcustomer_id AND customer_id=$customer_id"
    'Normally' if you have multiple rows as output you put them horizontal:
    ---------------
    while ($myrow = mysql_fetch_array($result)){

    echo "<table border=1>";
    echo "<tr>";
    echo "<td>$pakket</td>";
    echo "</tr></table>";
    ---------------
    But now i want to make an output table where the selectes rows are printed out as colums.
    Like:
    pakket 1 | pakket 2 | pakket 3
    option 1 j n j
    option 2 n n j
    option 3 6 j n
    option 4 $25 $30 $10

    Is this possible and how can i do this in php? I think i have to use another 'while' string but i can't figure it out.
    Greetings,

    Joep

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Location
    Cork, Ireland
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First do a count of the number of records returned by SQL, then create a for loop with the while loop inside it.
    Before the while in the for loop run the SQL query again, then you can print the same value of each record each iteration of the while loop. It would go somrthing like this:

    count on your sql query

    for (count on your SQL query from above)
    { run SQL query;
    while (($myrow = mysql_fetch_array($result))
    { print each similar item in a horizontal row;
    }
    }

    This should work. The only problem is that your running the query as many times as there are fields in your records. Maybe someone with more php knowledge has a better solution.


Bookmarks

Posting Permissions

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