Need php/css outputing help

thenewprogrammer

New Member
Messages
45
Reaction score
0
Points
0
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:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Float the <li>; other combinations of inline & block will most likely make the <li> display on separate lines.

PHP:
<style type="text/css">
.items li {
  float: left;
}
.items li img {
  display: block;
}
</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:

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
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>
 
Top