+ Reply to Thread
Results 1 to 5 of 5

Thread: Need php/css outputing help

  1. #1
    thenewprogrammer is offline x10Hosting Member thenewprogrammer is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    45

    Need php/css outputing help

    Making a virtual pet site for fun but the shop items when i output them the price goes to the side of it instead of underneath it. looking for a way to output the price underneath the picture instead of to the side of it.

    Code:
    <style type="text/css">
    li{display:inline}
    </style>
    <ul>
    <?php 
    $dbhost = "localhost"; 
    $dbname = "*****"; 
    $dbuser = "*****"; 
    $dbpass = "****"; 
    
    mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); 
    mysql_select_db($dbname) or die(mysql_error());
    $query2 = "SELECT * FROM game WHERE item_type = 'food' ORDER BY RAND() LIMIT 5";
    $result = mysql_query($query2);
    
    while($row = mysql_fetch_assoc($result)){
    $image = $row["item_img"];
    $desc = $row["item_desc"];
    $cost = $row["item_cost"];
    
    echo '<li><img src="Images/items/'. $image . '.png" alt='. $desc . ' /></li>';
    echo '<li>Cost: '. $cost . '<li>';
    }
    ?>
    </ul>
    Last edited by thenewprogrammer; 08-19-2009 at 01:18 AM.

  2. #2
    GrandeMike's Avatar
    GrandeMike is offline x10Hosting Member GrandeMike is an unknown quantity at this point
    Join Date
    Nov 2008
    Location
    Happy Valley, UT, USA
    Posts
    37

    Re: Need php/css outputing help

    Short answer: Change display:inline to display:block.
    The Grande-est of them all!

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Need php/css outputing help

    Float the <li>; other combinations of inline & block will most likely make the <li> display on separate lines.

    PHP Code:
    <style type="text/css">
    .
    items li {
      
    floatleft;
    }
    .
    items li img {
      
    displayblock;
    }
    </
    style>
    ...
    <
    ul class="items">
    ...
        echo 
    "<li><img src='Images/items/${image}.png' alt='$desc' />Cost: $cost<li>";
    ?></ul> 
    Note: you left off quotes around the 'alt' attribute.

    Ack. Need sleep.
    Last edited by misson; 08-19-2009 at 10:59 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Need php/css outputing help

    I believe he wants

    Code:
    Image       Image     Image      Image    Image
     cost           cost         cost          cost       cost

    Code:
    <table>
    <?php 
    
        $image_row = "<tr>\n" ;
        $cost_row = "<tr>\n" ;
        while($row = mysql_fetch_assoc($result)){
             $image = $row["item_img"];
             $desc = $row["item_desc"];
             $cost = $row["item_cost"];
    
             $image_row .= "<td><img src='Images/items/$image.png' alt='$desc' /></td>\n";
             $cost_row .=  "<td>Cost: $cost </td>\n";
        }
    
         echo "$image_row\n</tr>\n" ;
         echo "$cost_row\n</tr>\n" ;
    ?>
    
    </table>
    Nothing is always absolutely so.

  5. #5
    thenewprogrammer is offline x10Hosting Member thenewprogrammer is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    45

    Re: Need php/css outputing help

    ty for help got my problem solved now.

+ Reply to Thread

Similar Threads

  1. Help with outputing a picture and text below it
    By purpleflame in forum Programming Help
    Replies: 2
    Last Post: 02-07-2009, 02:17 PM
  2. Looking for PHP/CSS Coder
    By Sohail in forum The Marketplace
    Replies: 12
    Last Post: 05-07-2008, 08:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers