Results 1 to 3 of 3

Thread: sql, php with css

  1. #1
    Join Date
    Oct 2008
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default sql, php with css

    Hey all, I have done a simple tutorial to create a sql database and call and add results to a webpage. I want to do a page layout next and I use css float to layout webpages. How do I mix css with my php?

    Here is my simple coded website:

    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>

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    In the <head> section of the above document - add a style link, as explained here.
    Jeremy | jfein.net

  3. #3
    Join Date
    Oct 2008
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thank you have liked my css file to the code above.

    If I want to put the jokes list into a yellow box for example. So the contents of my database is called and listed in a box. Where can i put my divs in the code above?

    Here is my css:

    Code:
    #results {
    	position:absolute;
    	top:100px;
    	left:100px;
    	height:auto;
    	width:400px;
    	background-color:#FF9;
    }
    Im just learning and have not done sql or php before but i have done css and need to know how to add my css layout to the php code. So that i can display the results where ever i need on a page etc...

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
  •