SitePoint Sponsor

User Tag List

Results 1 to 25 of 25
  1. #1
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying records in two columns (again im sorry)

    Im still stuck with trying to get this to work, i know its been answered before but im not sure how to fit the solutions into what i have already typed. The furthest i got was having the records coming out like this

    record 1 record 2
    record 3

    which is the layout i want, but instead of displaying my fields, it literally only displays numbers, i.e.

    1 2
    3


    This is the code i have now (what i started with) which just displays the 10 records, one under the other, i want 2 colums with 5 records in each.


    ---------------------------------------------------------------
    <?php

    $db = mysql_connect("localhost", "b02mr1", "31541602");
    mysql_select_db("b02mr1_574db",$db);

    $dbQuery="SELECT * FROM thriller";
    $result = mysql_query($dbQuery,$db);
    ?>

    <p>&nbsp;</p>
    <table class=border align=center width=400 cellspacing=0 cellpadding=5>
    <tr><td>
    <table width=100% cellpadding=3 cellspacing=5 border=0>

    <?php

    while ($dvdInfo=mysql_fetch_array($result)) {

    $FilmImage=$dvdInfo["FilmImage"];
    $FilmTitle=$dvdInfo["FilmTitle"];
    $FilmYear=$dvdInfo["FilmYear"];
    $AgeImage=$dvdInfo["AgeImage"];

    echo " <tr><td rowspan='4'><img height=120px width=90px src=$FilmImage></td></tr> " .
    " <tr> <td>$FilmTitle</td></tr> " .
    " <tr><td>$FilmYear</td></tr>".
    " <tr><td><img src=$AgeImage></td></tr> " .
    " <tr><td>&nbsp</td></tr>";

    }
    ?>

    </table>
    </td>
    </tr>
    </table>

    --------------------------------------------------------------------------
    sorry its come out really messy!

  2. #2
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem lies here:

    PHP Code:
     $FilmImage=$dvdInfo["FilmImage"];
    $FilmTitle=$dvdInfo["FilmTitle"];
    $FilmYear=$dvdInfo["FilmYear"];
    $AgeImage=$dvdInfo["AgeImage"]; 
    The $dvdInfo array you are creating using mysql_fetch_array has numbers according to the column number (starting at 0) - Not the actual name of the column like in your code. Assuming the columns are in order, try this:

    PHP Code:
     $FilmImage $dvdInfo[0];
    $FilmTitle $dvdInfo[1];
    $FilmYear $dvdInfo[2];
    $AgeImage $dvdInfo[3]; 
    Hope this works

    -Will

  3. #3
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I changed my code like you said, but it makes no difference, its still working exactly the way it was before by listing the records one below the other. The code i posted earlier works correctly in calling the record from the database and displays each individual record in the format i want it too, but i just don't want the 10 records scrolling the whole way down the page.

    i need

    record 1 record 2
    record 3 record 4



    at the minute its

    record 1
    record 2
    record 3
    record 4

    ???
    ive been at this for hours :-(

  4. #4
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In an HTML table <tr> is for a new column and <td> a new cell. Try this instead:

    PHP Code:
    echo "<tr><td rowspan='4'><img height=120px width=90px src=$FilmImage></td>"; .
    echo 
    "<td>$FilmTitle</td></tr>";
    echo 
    "<tr><td>$FilmYear</td></tr>";
    echo 
    "<tr><td><img src=$AgeImage></td></tr>";
    echo 
    "<tr><td>&nbsp</td></tr>"
    There it is separated onto multiple lines to make it easier to read.

    Hope that works,

    -Will

  5. #5
    SitePoint Addict kirikintha's Avatar
    Join Date
    Nov 2004
    Location
    Boulder, CO
    Posts
    290
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do a search for horizontal looper - if you're using Dreamweaver MX it'll solve your problem. It's an extension that has saved my butt from a lot of wierd coding - outside of that, I've had problems with building tables to loop horizontally - sometimes it works sometimes it does not, the horizontal looper has helped me save alot of time (BTW way I did not develope the looper, no one is paying me it's free)

    The problem is that tables process differently on different browsers, so it may work on firefox, but nothing else... just one man's opinion though....
    myspace.com/tarsus
    Technical Coordinator
    BCMT
    "Not impossible, just hard to do!"

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php

    $db 
    mysql_connect("localhost""b02mr1""31541602");
    mysql_select_db("b02mr1_574db",$db);

    $dbQuery="SELECT * FROM thriller";
    $result mysql_query($dbQuery,$db);
    ?>

    <p>&nbsp;</p>
    <table class=border align=center width=400 cellspacing=0 cellpadding=5>
    <tr><td>
    <table width=100% cellpadding=3 cellspacing=5 border=0>
    <tr>
    <?php 

    while ($dvdInfo=mysql_fetch_array($result)) {

    $FilmImage=$dvdInfo["FilmImage"];
    $FilmTitle=$dvdInfo["FilmTitle"];
    $FilmYear=$dvdInfo["FilmYear"];
    $AgeImage=$dvdInfo["AgeImage"];

    echo 
    "<td>";

    echo 
    " <table><tr><td rowspan='4'><img height=120px width=90px src=$FilmImage></td></tr> " .
    " <tr> <td>$FilmTitle</td></tr> " .
    " <tr><td>$FilmYear</td></tr>".
    " <tr><td><img src=$AgeImage></td></tr> " .
    " <tr><td>&nbsp</td></tr></table>"

    echo 
    "</td>";

    if(
    $i%2==0) echo "</tr><tr>";

    $i++;


    ?> 

    </table>
    </td>
    </tr>
    </table>
    Try like this
    OOP Addict - sorry for my english

  7. #7
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry i think you've misunderstood me. I have it set up so that each record, which has 4 fields (FilmImage, FilmTitle, FilmYear, AgeImage) is displayed,in a table, the way i want it, so that RECORD 1 looks like this


    Film Title
    Film Image Film Year
    Age Image ----->(This is an image like the "18" symbol or "PG"
    you'd see on a video or film)

    and i have this table repeating so that it displays record 2 and record 3 etc in the same way however it is displaying each record one below the other, and i want them in 2 columns. So it should look like this:



    FilmTitle FilmTitle
    FilmImage FilmYear FilmImage FilmYear
    AgeImage AgeImage


    FilmTitle FilmTitle
    FilmImage FilmYear FilmImage FilmYear
    AgeImage Age Image



    etc

    sorry if im confusing you.... :-)

  8. #8
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My example is very simple becouse it makes table for every movie but it should works
    OOP Addict - sorry for my english

  9. #9
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aww crap that wasn't displayed properly

  10. #10
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kirikintha
    do a search for horizontal looper - if you're using Dreamweaver MX it'll solve your problem. It's an extension that has saved my butt from a lot of wierd coding - outside of that, I've had problems with building tables to loop horizontally - sometimes it works sometimes it does not, the horizontal looper has helped me save alot of time (BTW way I did not develope the looper, no one is paying me it's free)

    The problem is that tables process differently on different browsers, so it may work on firefox, but nothing else... just one man's opinion though....

    sorry, we're not allowed to use any software like dreamweaver or anything, it has to be done in phpedit or notepad :-( and we don't have access to dreamweaver to be able to obtain the code and then copy and paste (i.e. cheat :-))

  11. #11
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    what you need is a loop to reset your table celss/rows. Here is a snippet I wrote for a ifferent thread but the principle is the same.
    PHP Code:
    echo '<table width="100%" border="1" cellspacing="0" cellpadding="0">'
        
    $i=0
    while(
    $rows=mysql_fetch_assoc($query)) { 
    if((
    $i++ % 4)==0) { echo '</tr><tr>'; } 
    echo 
    '<td>'$rows['field'] .'</td>';   

    echo 
    '</tr>'
    echo 
    '</table>'
    HTH
    Cheers


    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  12. #12
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php

    $db 
    mysql_connect("localhost""b02mr1""31541602");
    mysql_select_db("b02mr1_574db",$db);

    $dbQuery="SELECT * FROM thriller";
    $result mysql_query($dbQuery,$db);
    ?>

    <p>&nbsp;</p>
    <table class=border align=center width=400 cellspacing=0 cellpadding=5>
    <tr><td>
    <table width=100% cellpadding=3 cellspacing=5 border=0>
    <tr>
    <?php 

    $i
    =1;

    while (
    $dvdInfo=mysql_fetch_array($result)) {

    $FilmImage=$dvdInfo["FilmImage"];
    $FilmTitle=$dvdInfo["FilmTitle"];
    $FilmYear=$dvdInfo["FilmYear"];
    $AgeImage=$dvdInfo["AgeImage"];

    echo 
    "<td>";

    echo 
    " <table>".
    "<tr><td rowspan='4'><img height=120px width=90px src=$FilmImage></td></tr> " .
    " <tr> <td>$FilmTitle</td></tr> " .
    " <tr><td>$FilmYear</td></tr>".
    " <tr><td><img src=$AgeImage></td></tr> " .
    " <tr><td>&nbsp</td></tr></table>"

    echo 
    "</td>";

    if(
    $i%2==0) echo "</tr><tr>";

    $i++;


    ?> 
    </tr>
    </table>
    </td>
    </tr>
    </table>
    There might be a bug in HTML code so check it.
    OOP Addict - sorry for my english

  13. #13
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry Null[pl], it hasn't changed anything, its still working the same way. I know i have to do a loop somewhere i think but not sure how. In the code you gave me should i not initialise $i to 0 somewhere?

  14. #14
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    run this and see what happens...
    PHP Code:
    <?php

    $db 
    mysql_connect("localhost""b02mr1""31541602");
    mysql_select_db("b02mr1_574db",$db);

    $dbQuery="SELECT * FROM thriller";
    $result mysql_query($dbQuery,$db);
    ?>

    <p>&nbsp;</p>
    <table class=border align=center width=400 cellspacing=0 cellpadding=5>
        <tr>
    <?php 
    $i
    =0;
    while (
    $dvdInfo=mysql_fetch_array($result)) {
    if((
    $i++ % 2)==0) { echo '</tr><tr>'; }

    $FilmImage=$dvdInfo["FilmImage"];
    $FilmTitle=$dvdInfo["FilmTitle"];
    $FilmYear=$dvdInfo["FilmYear"];
    $AgeImage=$dvdInfo["AgeImage"];
    $table ='<table width=100% cellpadding=3 cellspacing=5 border=0>';
    $table .= '<tr>
                    <td rowspan="4"><img height=120px width=90px src=$FilmImage></td>
                </tr> '
    ;
    $table .= '<tr> 
                    <td>$FilmTitle</td>
                </tr>'
    ;
    $table .= '<tr>
                    <td>$FilmYear</td>
                </tr>'
    ;
    $table .= '<tr>
                    <td><img src=$AgeImage></td>
                </tr>'
    ;
    $table .= '<tr>
                    <td>&nbsp</td>
                </tr>'
    ;
    $table .= '</table>';

            echo 
    '<td>';
            echo 
    $table;
            echo 
    '</td>';

    ?> 
        </tr>
    </table>
    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  15. #15
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm part of the problem is I don't know exactly how you want your output to look.
    From your code I Think you want something like:

    Image 1 Image 2
    Title 1 Title 2
    Year 1 year 2
    Age 1 age 2

    Image 2 Image 4
    Title 2 Title 4
    Year 2 year 4
    Age 2 age 4

    Where each row is it's own table row (<tr> ... </tr>)
    This is more complicated then if you just needed

    Image 1 title 1 year 1 age 1 Image 2 title 2 year 2 age 2


    While not the most pretty solution my first thought would be something like this.

    PHP Code:
    $toggle 1;  //Used to tell if we are in col 1 or 2, 
    while ($dvdInfo=mysql_fetch_array($result)) {

    $FilmImage=$dvdInfo["FilmImage"];
    $FilmTitle=$dvdInfo["FilmTitle"];
    $FilmYear=$dvdInfo["FilmYear"];
    $AgeImage=$dvdInfo["AgeImage"];
    if(
    $toggle)
    {
    $line1 =" <tr><td rowspan='4'><img height=120px width=90px src=$FilmImage></td>";
    $line2 " <tr> <td>$FilmTitle</td> ";
    $line3 "<tr><td>$FilmYear</td>";
    $line4 "<tr><td><img src=$AgeImage></td>";
    $toggle 0;

    else
    {
    echo 
    $line1 .="<td rowspan='4'><img height=120px width=90px src=$FilmImage></td></tr>";
    echo 
    $line2 .= "<td>$FilmTitle</td></tr> ";
    echo 
    $line3 .= "<td>$FilmYear</td></tr>";
    echo 
    $line4 .= "<td><img src=$AgeImage></td></tr>";
    $toggle 1;

    This way you only echo out everyother line. Be warned this is just an example and will result in not displaying the last record if there are an odd number of records. (it would be easy to check for and correct this).
    line1 - line4 are started on the odd reads, and finished and echoed on the even reads.

  16. #16
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ
    what you need is a loop to reset your table celss/rows. Here is a snippet I wrote for a ifferent thread but the principle is the same.
    PHP Code:
    echo '<table width="100%" border="1" cellspacing="0" cellpadding="0">'
        
    $i=0
    while(
    $rows=mysql_fetch_assoc($query)) { 
    if((
    $i++ % 4)==0) { echo '</tr><tr>'; } 
    echo 
    '<td>'$rows['field'] .'</td>';   

    echo 
    '</tr>'
    echo 
    '</table>'
    HTH
    Cheers


    Spike
    how do i use this with my own code? Im using a mySQL_fetch_array, do i have to change all that? i still want each individual record to be displayed the way i have it working.

  17. #17
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    No use it as is. the reason why you get just the numbers displayed is BECAUSE you are using mysql_fetch_array. This will return an numeric array (unsurprisingly!) of results where as mysql_fetch-assoc will return then numeric key as well as the fields.

    HTH

    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  18. #18
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [QUOTE=Tangent]Hmm part of the problem is I don't know exactly how you want your output to look.
    From your code I Think you want something like:

    Image 1 Image 2
    Title 1 Title 2
    Year 1 year 2
    Age 1 age 2

    Image 2 Image 4
    Title 2 Title 4
    Year 2 year 4
    Age 2 age 4

    no sorry, each record is displayed in a single table, for example record 1 looks like this:

    FilmTitle
    Film Image FilmYear
    AgeImage


    So theres a large picture of the video (FilmImage) and then its details (Title year and age category) are listed down the right hand side of the image.

    and this is the way i want each record to be displayed.

    But when more than one record is displayed,, they come out one below the other, like this:

    Record 1
    Record 2
    Record 3
    etc

    But i want them to be displyed like this:

    Record 1 Record 2
    Record 3 Record 4
    etc

  19. #19
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Rachael
    each record is displayed in a single table
    Which is what my second code post does!!!

    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  20. #20
    SitePoint Member
    Join Date
    Sep 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm I think what I put up should display them the way you want.
    What I needed to know was: is each record limited to one row?


    mysql_fetch_array by default does return a associative array. the second (optional peramater is result_type)

  21. #21
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow spike , thanks!!!! i ran the code you said to try and its almost working except its not actually displaying the images or retrieving the field values from the database, its just displaying a box with an x where the images should be and the field name e.g. $FilmTitle where the other two fields should be. Must be something really small, any ideas?

  22. #22
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    change mysql_fetch_array to mysql_fetch_assoc, didn't actually do that in the code I posted!!!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  23. #23
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ
    change mysql_fetch_array to mysql_fetch_assoc, didn't actually do that in the code I posted!!!
    hmmm, did that, but it still isn't displaying the field values?

  24. #24
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    OK plan B!
    change your values to
    PHP Code:
    $table .= '<tr> 
                    <td>'
    $FilmTitle.' </td> 
                </tr>'

    See if that makes a difference!

    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  25. #25
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great spike!!! it works!!! thanks you soooooo much, theres just one small think,, the first two records are displayed perfectly, but the 2nd two, i.e records 3 and 4 have a bigger space betwenn the FilmImage and the other three fields that the first 2 records? im not sure why


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
  •