Results 1 to 3 of 3

Thread: How to start a new row in PHP and Mysql with next page

  1. #1
    Join Date
    May 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to start a new row in PHP and Mysql with next page

    Hi All.

    I am pulling my images from database and showing it on the page. It is working fine but I want to limit 5 or 3 pictures in 1 row and then start a new row with 3 or 5 pictures. (3 or 5 once someone tell me the code we can set easily). It will continue for almost 6 rows then the link for next page comes where again it will show more pictures.

    Here is my code please help me. Please

    <?php
    include("includes/config.php");
    include("includes/affiliates.php");
    include("classes/search.class.php");
    $search=new search;

    $sql="select * from meta_tags";
    $result=mysql_query($sql);
    $data_set=mysql_fetch_array($result);
    ?>
    <html>
    <head>
    <title><?=$data_set["main_title"]?></title>
    <link href="css/style.css" rel=stylesheet>
    <!-- The site discusses these topics: free community site, community, communitys, indian community, muslim, india, sikh, indian bride, matrimonals -->
    </head>

    <?php
    include("includes/top.php");
    include("includes/left.php");
    ?>
    <!-- middle_content -->
    <td width="58%" bgcolor='#FFFFFF' valign='top'>
    <?php
    if ($_SESSION[session_user]!='')
    {
    echo "<table width=98% cellpadding=2 cellspacing=2>";
    ?>
    <?php
    $sql="select * from members_contacted where mem_contact_id = $_SESSION[user_id] and accepted = '1'";
    $res=mysql_query($sql);
    //print $sql;
    $num_rows=mysql_num_rows($res);
    if($num_rows==0)
    {
    $aa=1;
    }
    else
    {
    $aa=0;
    }
    ?>
    <!-- CENTER STARTS HERE -->
    <tr>
    <td colspan=2>
    <table width="100%" border="0" cellspacing="0" cellpadding="4">
    <tr>
    <td width="350" height="7"><spacer type="block" width="350" height="7"></td>
    <td width="220"><spacer type="block" width="220"></td>
    </tr>
    <tr>
    <td align="left" class='myClass'><b>Members who contacted me</b></td>
    </tr>
    <?php
    if($aa==1)
    {
    ?>
    </table>



    <table cellspacing="0" cellpadding="4" border="0" width="100%">
    <tr valign=top>
    <td colspan="2" class="mediumblackbold">
    You have not been contacted by any one yet.
    </td></tr>
    </table>
    <?php
    }
    else
    {
    ?>

    <!-- CENTER STARTS HERE -->


    <table cellspacing="0" cellpadding="2" border="0" width="100%">
    <tr valign=top>
    <td colspan="2" class="mediumblackbold">
    You are browsing profiles of: <font class="mediumblack">members whom you contacted</font>
    </td>
    </tr>
    </table>
    </div>
    <tr>
    <td colspan=2>
    <table width='100%' cellpadding=2 cellspacing=2>
    <tr>
    <?php
    $tot_photos=0;
    $sql="select photo_url from users where auto_id=$data_set[my_id]";
    $res=mysql_query($sql);
    $data_set=mysql_fetch_array($res);
    if($data_set["photo_url"]!=Null)
    {
    $tot_photos=$tot_photos+1;
    }
    $sql="select * from members_contacted where mem_contact_id = $_SESSION[user_id] and accepted='1'";
    $res=mysql_query($sql);
    $sr_no=1;
    while($data_set=mysql_fetch_array($res))
    {
    //$sql="select * from users a, occupation b where a.occupation = b.value and a.auto_id=$data_set[my_id]";
    $sql="select * from users where auto_id=$data_set[my_id]";
    $result=mysql_query($sql);
    $d_s=mysql_fetch_array($result);
    if($sr_no%2==0)
    {
    print "</tr><tr>";
    }
    ?>
    <td width='33%' class='reg_left'>
    <div align='center'>
    <img src="image_gd/profile_image1.php?<?=$d_s["photo_url"]?>" border="0"></a>
    <br>
    <?php
    if($data_set["accepted"]=='1')
    {
    print "Accepted";
    }
    else
    {
    print "<a href='accept_message.php?mess_id=$data_set[contact_id]'>Accept</a>";
    }
    ?>
    <br>
    <a href="profile.php?username=<?=$d_s["username"]?>" class="smallbluelink"><?=$d_s["username"]?></a>
    <br>
    <a href='send_message.php?contact=<?=$d_s["username"]?>'>Send Message</a></b>
    </div>
    </td>
    <?php
    }
    ?>
    </table>
    </div><br>

    <!-- CENTER ENDS HERE -->

    <?php
    }
    ?>
    <!-- CENTER ENDS HERE -->
    <?php
    }
    else{
    print ("<script>window.location='validate_login.php';</script>");
    }
    ?>
    </td>


    <?php
    require("includes/right.php");
    require("includes/bottom.php");
    ?>


    and here is the output of this code. All I want is break the count of pictures to 3 and then start a new row, and show 3 more pictures then start a new row, this way continue for 5 rows and then a link for next page and on next page samething, 3 pics for 5 rows and then next page.

    if 1 profile has 400 friends, each page will show 3 friends pictures with 6 rows so that means 18 friends on 1 page and then next page, 18 friends on second page and next page..like that continue till finishes 400 friends (its just an example).

    this is the out put of the code




    Thank you so much

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Your code is pretty complex and i'm not sure what each part is designed to do, but here's the simple version of things.

    First... line breaks are incredibly easy. <br>. that's it.

    Just use a counting variable.

    Here's a mockup of the code:

    PHP Code:
    <?php
    while (mysqlthingy) {
    echo 
    "THIS IS WHERE YOUR STUFF GOES. CAN BE MORE THAN ONE CMND, ETC.";
    $count++;
    if (
    $count == 0) {
       echo 
    "<br>";
       }
    }
    ?>
    Note: the modulus (%) operator gets the remainder. If you want it broken at every third one, then you want the remainder to be 0 if divided by 3.
    You could also reset in that.... "if == 3, then $count = 0", but % works just fine.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    May 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    U should use table. it is better. and counter use for </tr><tr>

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
  •