SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    London
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi could anyone provide a little guidance as to how you go about formatting the MySQL output data when it appears in a client's browser. I have recently completed kevin yanks tuorial and at present any text generated is displayed in a simple table.

    I am fairly new to this and at present the scripts I have working display my output as one block of text or as stated above. I am really pleased it works but I would like to improve the look of my site and make what appears in the clients browser a little more organised!

    One more little question I want to use includes can anyone tell me how you construct include tables that will increse in size according to amount of data displayed. I know these are simple in fact probably quite sad questions but I have spent a lot of time trying to solve them on my own and have been unsuccessfull Help!

    Thanks in advance Kevin1

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't quite understand what you're saying. Formatting is amazingly simple. If you have a variable called $name, you would bold it like this:

    echo("<b>" . $name . "</b>");

    As for include tables - you'll have to describe what you mean in detail, I don't really follow it right now.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    London
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply TWTCommish
    The kind of formatting I would like to try and acheive would be something like what is used on the home page of this site where the articles are ordered side by side and you have a link if you wish to read more. Is this a little ambitious?
    Thanks Kevin1

  4. #4
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not really. Let's say the variable storing your article is called "$body", and the ID of the document is "$aid":

    Code:
    $body = nl2br($body);
    $array = explode("<br>", $body);
    $summary = $array[0];
    
    echo($summary . "<br>");
    printf('<b><a href="articles.php?id=%s">Read More!</a></b>', $aid);
    Feel free to ask me any questions you might have - some of that might be a bit confusing.

    The only line that may not apply to you specifically is the first one, which takes all double line breaks and preserves their formatting so that paragraphs are broken up on their own - this allows you to type in your text/paragraphs just as you do on these forums.

    The above code will grab the first paragraph from the $body variable and display it with a link to article.php?id=ID NUMBER HERE. From then, you place a simple query in article.php to display the article based on the ID number in the query string - ta-da!

    As for the way they have them lined up: I believe that makes use of the LIMIT statement in SQL. For example:

    SELECT * FROM articles LIMIT 5

    That will only select 5 records from the table. If you want to select articles 5-6, rather than 1-5, you'd use this:

    SELECT * FROM articles LIMIT 5, 2

    That command tells it to skip over the first 5 results, and then only print out 2 records from that spot. So basically, SP's first query might look like this:

    SELECT * FROM articles LIMIT 2

    ...their next might look like this:

    SELECT * FROM articles LIMIT 2, 2

    ...and their third might look like this:

    SELECT * FROM articles LIMIT 4, 2

    Now, it's more likely that they have some more advanced queries to save time and such, but that's the general concept behind it.

    EDIT: My block of PHP code near the top of this post originally made use of the more sensible printf() function to print out the "Read More" link, but the PHP highlighter seems to have botched it up, so I changed it to CODE.
    Last edited by TWTCommish; Mar 12, 2001 at 11:26.

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    London
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks again TWTCommish the code you have posted looks exactly what I am looking for.

    I will not have time to try it until Friday but I am sure it will provide the kind of look I want. Sitepoint forums are great!
    I am a very new member and already I have had some really useful advice.

    As a new member you feel a little reluctant to ask what may be precieved as stupid questions by experienced programmers such as yourself. I have asked a few stupid questions already and got some great tips and information. Thanks for taking the time!

    PS I have sorted the problems with includes and tables etc
    Thanks Kevin1

  6. #6
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm glad to have helped - I like stupid questions: they're the easiest to answer! I can honestly say that I get a good feeling from helping people out here, and it helps me to hone my skills while working on real-world projects.

  7. #7
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    London
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi TWTCommish
    I have had a look at the code I have and what you have given me, even though what you have provided makes perfect sense I am not sure how to implement it with what I am using?

    I have posted my code could you have a look and point me in the right direction

    Thanks Kevin1

    Here is the page used to search db
    <!-- subjects1.php -->
    <HTML>
    <HEAD>
    <TITLE> Manage Subjects </TITLE>
    </HEAD>
    <BODY>
    <H1>Manage Subjects</H1>
    <P><A HREF="newsubject1.php">Create New Subject</A></P>
    <?php
    $dbcnx = @mysql_connect("localhost", "root", "mypasswd");
    mysql_select_db("project");

    $authors = mysql_query("SELECT ID, Name FROM Authors");
    $cats = mysql_query("SELECT ID, Name FROM Categories");
    ?>

    <FORM ACTION="subjectlist.php" METHOD=POST>
    <P>View subjects satisfying the following criteriaBR>
    By Author:
    <SELECT NAME="aid" SIZE=1>
    <OPTION SELECTED VALUE="">Any Author
    <?php
    while ($author = mysql_fetch_array($authors)) {
    $aid = $author["ID"];
    $aname = $author["Name"];
    echo("<OPTION VALUE='$aid'>$aname\n");
    }
    ?>
    </SELECT><BR>
    By Category:
    <SELECT NAME="cid" SIZE=1>
    <OPTION SELECTED VALUE="">Any Category
    <?php
    while ($cat = mysql_fetch_array($cats)) {
    $cid = $cat["ID"];
    $cname = $cat["Name"];
    echo("<OPTION VALUE='$cid'>$cname\n");
    }
    ?>
    </SELECT><BR>
    Containing Text: <INPUT TYPE=TEXT NAME="searchtext"><BR>
    <INPUT TYPE=SUBMIT NAME="submit" VALUE="Search">
    </FORM>

    <P ALIGN=CENTER><A HREF="admin.php">Return to Front Page</A></P>
    </BODY>
    </HTML>
    ------------------------------------------------------
    Heres the page that provides the output
    <!-- subjects.php -->
    <HTML>
    <HEAD>
    <TITLE> Manage Subjects </TITLE>
    </HEAD>
    <BODY>
    <H1>Manage Subjects</H1>
    <P><A HREF="newsubject.php">Create New Subject</A></P>
    <?php

    $dbcnx = @mysql_connect("localhost", "root", "mypasswd");
    mysql_select_db("project");

    $authors = mysql_query("SELECT ID, Name FROM Authors");
    $cats = mysql_query("SELECT ID, Name FROM Categories");
    ?>

    <FORM ACTION="subjectlist1.php" METHOD=POST>
    <P>View subjects satisfying the following criteriaBR>
    By Author:
    <SELECT NAME="aid" SIZE=1>
    <OPTION SELECTED VALUE="">Any Author
    <?php
    while ($author = mysql_fetch_array($authors)) {
    $aid = $author["ID"];
    $aname = $author["Name"];
    echo("<OPTION VALUE='$aid'>$aname\n");
    }
    ?>
    </SELECT><BR>
    By Category:
    <SELECT NAME="cid" SIZE=1>
    <OPTION SELECTED VALUE="">Any Category
    <?php
    while ($cat = mysql_fetch_array($cats)) {
    $cid = $cat["ID"];
    $cname = $cat["Name"];
    echo("<OPTION VALUE='$cid'>$cname\n");
    }
    ?>
    </SELECT><BR>
    Containing Text: <INPUT TYPE=TEXT NAME="searchtext"><BR>
    <INPUT TYPE=SUBMIT NAME="submit" VALUE="Search">
    </FORM>

    <P ALIGN=CENTER><A HREF="admin.php">Return to Front Page</A></P>
    </BODY>
    </HTML>

    $dbcnx = @mysql_connect("localhost", "root", "mypasswd");
    mysql_select_db("project");

    $authors = mysql_query("SELECT ID, Name FROM Authors");
    $cats = mysql_query("SELECT ID, Name FROM Categories");
    ?>

    <FORM ACTION="subjectlist.php" METHOD=POST>
    <P>View subjects satisfying the following criteriaBR>
    By Author:
    <SELECT NAME="aid" SIZE=1>
    <OPTION SELECTED VALUE="">Any Author
    <?php
    while ($author = mysql_fetch_array($authors)) {
    $aid = $author["ID"];
    $aname = $author["Name"];
    echo("<OPTION VALUE='$aid'>$aname\n");
    }
    ?>
    </SELECT><BR>
    By Category:
    <SELECT NAME="cid" SIZE=1>
    <OPTION SELECTED VALUE="">Any Category
    <?php
    while ($cat = mysql_fetch_array($cats)) {
    $cid = $cat["ID"];
    $cname = $cat["Name"];
    echo("<OPTION VALUE='$cid'>$cname\n");
    }
    ?>
    </SELECT><BR>
    Containing Text: <INPUT TYPE=TEXT NAME="searchtext"><BR>
    <INPUT TYPE=SUBMIT NAME="submit" VALUE="Search">
    </FORM>

    <P ALIGN=CENTER><A HREF="admin.php">Return to Front Page</A></P>
    </BODY>
    </HTML>

    Please don't laugh to much we all have to learn?
    Thanks again Kevin1

  8. #8
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm a tad confused - what problem are you running into?

  9. #9
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    London
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi TWTCommish
    The problem I'm having is that I am not sure should I modify the scripts I posted or should I try and cobble something together from what I have and what you have kindly provided. As I said I am very new to this and programming is an area where I have plenty to learn. It is probably such a simple task to you but for me it is a daunting prospect trying to fit the peices together.
    Many thanks Kevin1

  10. #10
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't understand what it is you want - what I basically need to know is what you're trying to do, and what your script is currently doing.

  11. #11
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    London
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At present my script pulls the total contents of a subject that is seached for in the db by category, author and any specific words if used. What I would like to do is have the script do exactly what it is except when the results are displayed they are shown as the first few lines (say 5) of the subject with a link as you provided that can be used to pull the rest of the subject out if the user wants to read it. I would like to preserve some formatting as you've shown in your code and if possible display articles in rows of 2 side by side.

    Sorry if I'm not being very clear when explaining!
    Thanks Kevin1


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
  •