Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2009
    Posts
    2

    Red face Unanswered: sql, php and css

    Hi all,

    Im new to sql, php and this forum! so hope i've posted in the correct place.

    I have been learning mysql and created a simple two field database and used php to create a form to enter data into the database and just list the contents of the database.

    I would like to know if i can now use div's to possition the list called from the database.

    Here is my basic php code:


    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <title>The Internet Joke Database</title>
    <meta http-equiv="content-type" 
       content="text/html; charset=iso-8859-1" /> 
    </head> 
    <body> 
    <?php if (isset($_GET['addjoke'])): // User wants to add a joke 
    ?> 
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
    <label>Type your joke here:<br /> 
    <textarea name="joketext" rows="10" cols="40"> 
    </textarea></label><br /> 
    <input type="submit" value="SUBMIT" /> 
    </form> 
    <?php else: // Default page display 
    
     // Connect to the database server 
     $dbcnx = @mysql_connect('localhost', 'root', ''); 
     if (!$dbcnx) { 
       exit('<p>Unable to connect to the ' . 
           'database server at this time.</p>'); 
     } 
    
     // Select the jokes database 
     if (!@mysql_select_db('jokes')) { 
       exit('<p>Unable to locate the joke ' . 
           'database at this time.</p>'); 
     } 
    
     // If a joke has been submitted, 
     // add it to the database. 
     if (isset($_POST['joketext'])) { 
       $joketext = $_POST['joketext']; 
       $sql = "INSERT INTO jokes SET 
           joketext='$joketext', 
           jokedate=CURDATE()"; 
       if (@mysql_query($sql)) { 
         echo '<p>Your joke has been added.</p>'; 
       } else { 
         echo '<p>Error adding submitted joke: ' . 
             mysql_error() . '</p>'; 
       } 
     } 
    
     // If a joke has been deleted, 
     // remove it from the database. 
     if (isset($_GET['deletejoke'])) { 
       $jokeid = $_GET['deletejoke']; 
       $sql = "DELETE FROM jokes 
           WHERE id=$jokeid"; 
       if (@mysql_query($sql)) { 
         echo '<p>The joke has been deleted.</p>'; 
       } else { 
         echo '<p>Error deleting joke: ' . 
             mysql_error() . '</p>'; 
       } 
     } 
    
     echo '<p> Here are all the jokes in our database: </p>'; 
    
     // Request the ID and text of all the jokes 
     $result = @mysql_query('SELECT id, joketext FROM jokes'); 
     if (!$result) { 
       exit('<p>Error performing query: ' . 
           mysql_error() . '</p>'); 
     } 
    
     // Display the text of each joke in a paragraph 
     // with a "Delete this joke" link next to each. 
     while ($row = mysql_fetch_array($result)) { 
       $jokeid = $row['id']; 
       $joketext = $row['joketext']; 
       echo '<p>' . $joketext . 
           ' <a href="' . $_SERVER['PHP_SELF'] . 
           '?deletejoke=' . $jokeid . '">' . 
           'Delete this joke</a></p>'; 
     } 
     
     // When clicked, this link will load this page 
     // with the joke submission form displayed. 
     echo '<p><a href="' . $_SERVER['PHP_SELF'] . 
         '?addjoke=1">Add a Joke!</a></p>'; 
    
    endif; 
    ?>
    </body> 
    </html>

    I want the list of jokes to be styled and put in possition on the page with css. If i close the php tags and then use css it doesn't work...how can I determine where the list of jokes is shown on the page using css?

    Hope you understand any questions please ask. Thank you for your time.

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    How are you assigning the CSS? Are you using inline, header or linked?
    Try this inline
    Code:
     // Display the text of each joke in a paragraph 
     // with a "Delete this joke" link next to each. 
     while ($row = mysql_fetch_array($result)) { 
       $jokeid = $row['id']; 
       $joketext = $row['joketext']; 
       echo '<p style="color:#00FF00">' . $joketext . 
           ' <a href="' . $_SERVER['PHP_SELF'] . 
           '?deletejoke=' . $jokeid . '">' . 
           'Delete this joke</a></p>';
    Header:
    Code:
    <header>
      <script type="text/css">
        .cssthis {
          color: #00FF00
        }
      </script>
    </header>
    
    ...
    
     // Display the text of each joke in a paragraph 
     // with a "Delete this joke" link next to each. 
     while ($row = mysql_fetch_array($result)) { 
       $jokeid = $row['id']; 
       $joketext = $row['joketext']; 
       echo '<p class="cssthis">' . $joketext . 
           ' <a href="' . $_SERVER['PHP_SELF'] . 
           '?deletejoke=' . $jokeid . '">' . 
           'Delete this joke</a></p>';
    Either of these make the text red?
    George
    Home | Blog

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by georgev
    Either of these make the text red?
    that's highly unlikely

    if you want red, try #FF0000

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10


    ...I mean... you noticed my little trap, well done Rudy
    George
    Home | Blog

  5. #5
    Join Date
    Jan 2009
    Posts
    2

    Thank you

    Thanks for your help all....the solution is perfect for what I needed.

    I will continue my learning from here.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •