SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: line breaks

  1. #1
    ? big bad opus's Avatar
    Join Date
    Jun 2001
    Location
    DC
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    line breaks in an array

    I do I make an array print out with line breaks after every five items. So I can get something like

    A B C D E
    F G H I J

    instead of:

    A B C D E F G H I J
    Last edited by big bad opus; Jul 20, 2003 at 16:44.

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    Michigan, USA
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The thread below offers some insight into this:

    http://www.sitepointforums.com/showt...hreadid=118283

    I'd recommend using the modulus (sp?), which is the %, operator. It had slipped my mind while I was coming up with a solution

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    Middle / East TN
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    for ($i 0$i count($array); $i++) {
         echo 
    $array[$i];
         if (
    $i%== 4)
              echo 
    "\n";

    There are 10 kinds of people in this world,
    those who can read binary and those who can't.

  4. #4
    ? big bad opus's Avatar
    Join Date
    Jun 2001
    Location
    DC
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you so much

  5. #5
    public static void brain Gybbyl's Avatar
    Join Date
    Jun 2002
    Location
    Montana, USA
    Posts
    647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Andy Tomaka
    I'd recommend using the modulus (sp?), which is the %, operator. It had slipped my mind while I was coming up with a solution
    Modulo operator - singular
    Modulus operator - plural
    (You had it right )

    Bonk's code has the general idea -- I think you should be checking for '0' after the modulo operation instead of 4, however. 4 may work, however, but the general idea of modulo is to return a remainder -- If the remainder is 0, then you know you've got a number that's divisible by 5.
    Ryan

  6. #6
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    Middle / East TN
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, usually I do it that way, but since your going through an array, you need $i to be 0 etc. And since your starting with 0 and not 1, the fifth one would be 4.

    The modulus works like this: it divides the two numbers and returns the remainder, so 9%5 would be 4, 10%5 would be 0.
    There are 10 kinds of people in this world,
    those who can read binary and those who can't.

  7. #7
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    Michigan, USA
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can honestly say I have never heard it referred to as modulo. Thanks for the tip

  8. #8
    ? big bad opus's Avatar
    Join Date
    Jun 2001
    Location
    DC
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay i tried implementing this into existing code and it's giving me a problem.

    it's printing AAAAAAAA BBBBBBBB CCCCCC DDDDD and so forth. What am I doing wrong?

    Code:
      <?php
      $quicklink_array = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
      while (list($ql_pointer, $quicklink) = each($quicklink_array)) {
       $get_title = $mm->dbQuery("SELECT movie_title FROM movies_list WHERE movie_title LIKE '$quicklink%' ORDER BY movie_title");
    	for($i = 0; $i < count($quicklink_array); $i++) {
       if (! $mm->dbCountRows($get_title)){ 
      
    	  
    	print ("$quicklink&nbsp;");
    	
       } else {
       
    	print ("<a href=""\"index.php?module=movies&do=search&ql=$quicklink\">$quicklink</a>&nbsp;");
    	 }
    			  if(($i % 5) == 4) 
    	{ 
    		echo "<br>"; 
     
    	};   
    };		  
      };
      ?>

  9. #9
    SitePoint Member CorneliusBolten's Avatar
    Join Date
    Jul 2003
    Location
    germany
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb

    try this to cut the str $str each 6th.letter:

    Code:
        $str = "AAAAAABBBBBBCCCCCCDDDDDDEEEEEE";
        $newstr = wordwrap($str,6,"<bR>",1);
        echo $newstr;
    this will print out:

    Code:
    AAAAAA
    BBBBBB
    CCCCCC
    DDDDDD
    EEEEEE

  10. #10
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    Middle / East TN
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $quicklink_array = array("1""2""3""4""5""6""7""8""9""A""B""C""D""E""F""G""H""I""J""K""L""M""N""O""P""Q""R""S""T""U""V""W""X""Y""Z" );

    for(
    $i 0$i count($quicklink_array); $i++) {
         
    $current $quicklink_array[$i];
         
    $get_title $mm->dbQuery("SELECT movie_title FROM movies_list WHERE movie_title LIKE '$current%' ORDER BY movie_title" );
         if (!
    $mm->dbCountRows($get_title))
              echo 
    $quicklink_array[$i] . '&nbsp;';
         else
              print 
    '<a href="index.php?module=movies&do=search&ql=' $quicklink_array[$i] . '">' $quicklink_array[$i] . '</a>&nbsp;';
         if (
    $i%== 4
              echo 
    "<br>"

    You had the loop twice for every letter.
    There are 10 kinds of people in this world,
    those who can read binary and those who can't.

  11. #11
    ? big bad opus's Avatar
    Join Date
    Jun 2001
    Location
    DC
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    perfect, thanks


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
  •