SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php skip to next line

    When it comes to scripting by php a dropdown menu, how do I skip to the next line?

    <select>
    <option>...
    <option>...
    <option>...
    <option>...
    <option>...
    <option>...
    </select>
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    United States
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using \n, and making sure it is surrounded by double quotes, not single quotes.

    PHP Code:
    echo '<option>'.$name.'</option>'."\n"

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    What do you mean?

    Edit:

    Right, how do I add a newline character to my html source code ... well devined tmapm

  4. #4
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.

    Now let's say I want to retrieve the first 22 records...how does that work?
    Code:
    				
    $query = odbc_exec($odbc, "
    Select DISTINCT(recordType), Book_Title, Book FROM Bible ORDER BY Book ASC
    ") or die (odbc_errormsg());
    Compare bible texts (and other tools):
    TheWheelofGod

  5. #5
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Don't you need a GROUP BY clause if you're using DISTINCT, or is this only for MYSQL?

    Anyway throw a LIMIT 22 at the end.

  6. #6
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wonshikee View Post
    Don't you need a GROUP BY clause if you're using DISTINCT, or is this only for MYSQL?

    Anyway throw a LIMIT 22 at the end.
    No group? ok.

    Well I'm using MSAccess2000.

    LIMIT 22: Ok I think I need to further explain. My intention is to make 3 columns of a table where each column has 22 books listed. How do I do that?

    Or is there a way of breaking 22 and inserting <tr><td></td></tr> and then continuing?
    Last edited by gilgalbiblewheel; Oct 31, 2007 at 17:15.
    Compare bible texts (and other tools):
    TheWheelofGod

  7. #7
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Cape Cod
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes one way would be to use a counter. set it prior to the script then add 1 each time through the loop. check it each time through and when it hits 22 have the script print the necessary html then reset the counter and continue on with the loop. If this does not make sense let me know and I will type up an example.

  8. #8
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I tried that. But maybe I didn't use it properly because at one point it was repeating each 22 times. I changed things and then it did other things...where's the right place to put it?
    Compare bible texts (and other tools):
    TheWheelofGod

  9. #9
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You must have a while statement outputting the results. Just after that add
    something like this. Remember to set $a to 0 at the top of the page

    Code:
    if ($a < 22)
    {
          your outtputting statements.....
    
        $a++
    } else {
         disconnect your database
    }

    Or even easier I think this will work in your SQL statement

    Code:
    SELECT TOP 22 DISTINCT(recordType), Book_Title, Book FROM Bible ORDER BY Book ASC
    
    I am not overly sure on SQL syntax

  10. #10
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Would you require pagination of the results?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  11. #11
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dc_duo123 View Post
    You must have a while statement outputting the results. Just after that add
    something like this. Remember to set $a to 0 at the top of the page

    Code:
    if ($a < 22)
    {
          your outtputting statements.....
    
        $a++
    } else {
         disconnect your database
    }

    Or even easier I think this will work in your SQL statement

    Code:
    SELECT TOP 22 DISTINCT(recordType), Book_Title, Book FROM Bible ORDER BY Book ASC
    
    I am not overly sure on SQL syntax
    Well just by looking at it the second suggestion isn't what I'm looking for because as I put DISTINCT the database DINSTINCTly has 66 books named. And what I'm looking for is to place 22 in each of the 3 columns of a table.

    And the first one won't work because I did something similar putting a while statement and it gave the same results 22 times. Then I put it outside the SELECT statement and Outside the closing of the connection so that it opened and closed three times and it went through the entire 66 books 3 times.
    Compare bible texts (and other tools):
    TheWheelofGod

  12. #12
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there a way to number the SELECT statement? Write three statements and make one 1-22 then the 2nd 23-44 and the 3rd 45-66?

    or a while statement or loop? or what?
    Compare bible texts (and other tools):
    TheWheelofGod

  13. #13
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Cape Cod
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I am no expert so if someone else has a better way I would also like to see it but this code will put your data into a three column table. Unfortunately it is going to to do it across instead of down one row and then back to the top. let me know if it helps or if you have a problem.

    you can see it in action here www.capephotos.net/test.php


    Code:
    //set the count variable so you can use it to control the coding	
    $count = 1;
    
    //this is a just sets up an array to use as an example
    	
    	$books = array("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","aa","bb","cc","dd","ff","gg","hh","ii","jj","kk","ll","mm","nn");
    	
    //this starts the html code
    
                        $msg = "<table>
    				<tr>";
    	
    	
    //if this were coming from a DB I would use a while loop
              foreach ($books as $book) {
    	
    		$msg .= "<td>$book</td>";
    	
    //this is to check and see if we are ready to start the next row in the table if we are it prints the html and resets the $count variable
    		if ($count == 3) {
    			
    			$msg .="</tr><tr>";
    			
    			$count = 1;
    			
    		} else {
    
    //this adds 1 to the $count variable		
    			$count++;
    		}
    		
    		}
    
    //once it is done going through the array it closes the table		
    		$msg .="</tr>
    				</table>";
    				
    		echo $msg;

  14. #14
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it comes pretty close to what I'm looking for except I would like to, in this case make the SELECT give the result IN the array. This way I can maybe place the table tags accordingly. Thanks.

    But I think ( I'm new in PHP ) JavaScript is needed for the array right?
    Compare bible texts (and other tools):
    TheWheelofGod

  15. #15
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Cape Cod
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well in mysql you could do the select statement and then after the query is run instead of doing the foreach loop do this

    Code:
    while ($my_array = mysql_fetch_array($my_sql)
    I do not know what it would be in access.

    If this does not help let me know and I will post the example again with the DB code

  16. #16
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks.
    Compare bible texts (and other tools):
    TheWheelofGod


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
  •