Jump to content

How do I style this PHP?


Lee1007

Recommended Posts

Hi there,

 

I have the following code:

 

 

<?php

include 'config.php';

include 'opendb.php';

 

$query  = "SELECT shop_name, street_name, town, postcode, contact_number, web_address, user_email FROM user_info";

$result = mysql_query($query);

 

while($row = mysql_fetch_row($result))

{

    $shop_name    = $row[0];

    $street_name = $row[1];

    $town = $row[2];

$postcode = $row[3];

$contact_number = $row[4];

$web_address = $row[5];

$user_email = $row[6];

 

 

 

echo 

"<h5>Name:</h5>$shop_name <br>" .

        "<h5>Address</h5>$street_name <br>" .

"$town <br>" .

"$postcode <br>" .

"<h5>Contact Details</h5>Phone Number:$contact_number <br>" .

"Web Address: $web_address <br>" .

        "Email : $user_email <br><br>";

 

}

 

 

include 'closedb.php';

 

?>

 

But i want to make the echo return in a box which is created by the div in the css? How do i do this?

 

Please Help!!!  :)

Link to comment
https://forums.phpfreaks.com/topic/231773-how-do-i-style-this-php/
Share on other sites

You want all results contained within one master div? Is that what I am understanding?

 

Before:

<?php
include 'config.php';
include 'opendb.php';

$query  = "SELECT shop_name, street_name, town, postcode, contact_number, web_address, user_email FROM user_info";
$result = mysql_query($query);

while($row = mysql_fetch_row($result))
{
    $shop_name    = $row[0];
    $street_name = $row[1];
    $town = $row[2];
   $postcode = $row[3];
   $contact_number = $row[4];
   $web_address = $row[5];
   $user_email = $row[6];



echo  
       "<h5>Name:</h5>$shop_name <br>" .
         "<h5>Address</h5>$street_name <br>" .
       "$town <br>" .
       "$postcode <br>" .
       "<h5>Contact Details</h5>Phone Number:$contact_number <br>" .
       "Web Address: $web_address <br>" .
         "Email : $user_email <br><br>";
    
}


include 'closedb.php';

?>

 

After:

<div class="resultWrapper">
<?php
include 'config.php';
include 'opendb.php';

$query  = "SELECT shop_name, street_name, town, postcode, contact_number, web_address, user_email FROM user_info";
$result = mysql_query($query);

while($row = mysql_fetch_row($result))
{
    $shop_name    = $row[0];
    $street_name = $row[1];
    $town = $row[2];
   $postcode = $row[3];
   $contact_number = $row[4];
   $web_address = $row[5];
   $user_email = $row[6];



echo  
       "<h5>Name:</h5>$shop_name <br>" .
         "<h5>Address</h5>$street_name <br>" .
       "$town <br>" .
       "$postcode <br>" .
       "<h5>Contact Details</h5>Phone Number:$contact_number <br>" .
       "Web Address: $web_address <br>" .
         "Email : $user_email <br><br>";
    
}


include 'closedb.php';

?>
</div>

I don't know if you're asking a php ? or an html ? Soooooooooo

 

1. I echo monkeytooth & 2

 

"<h5>Name:</h5>$shop_name <br>" . <------------unless you style h5 narrow and set a margin or float you have two lines here and two different fonts(?)

        "<h5>Address</h5>$street_name <br>" . <------------unless you style h5 narrow and set a margin or float you have two lines here and two different fonts

"$town <br>" . 

"$postcode <br>" .

"<h5>Contact Details</h5>Phone Number:$contact_number <br>" .  <------------unless you style h5 narrow and set a margin or float you have two lines here and two different fonts

"Web Address: $web_address <br>" .

        "Email : $user_email <br><br>";

 

Also do you need some escapes \" ?

"<h5>Name:</h5>$shop_name <br>" .
         "<h5>Address</h5>$street_name <br>" .
       "$town <br>" .
       "$postcode <br>" .
       "<h5>Contact Details</h5>Phone Number:$contact_number <br>" .
       "Web Address: $web_address <br>" .
         "Email : $user_email <br><br>";

 

thats your key bit.. this is where you would either change the html to something you want be it a single div rather than all the h5 tags, or whatever. The thing you need to concern yourself with ultimately when changing the html in this for however you want to style it is preserve the pieces that are $......

 

example:

<?php 
echo "<div>
$shop_name<br />
$street_name<br />
$town. $postcode<br /><br />
$contact_number<br /><br />
$web_address<br><br />
$user_email<br><br />
</div>";
?>

I probably havent explained this too good - I have the results of:

 

echo 

      "<h5>Name:</h5>$shop_name <br>" .

        "<h5>Address</h5>$street_name <br>" .

      "$town <br>" .

      "$postcode <br>" .

      "<h5>Contact Details</h5>Phone Number:$contact_number <br>" .

      "Web Address: $web_address <br>" .

        "Email : $user_email <br><br>";

   

}

 

but on the web page i want the results to be displayed in horizontal blocks of 3 - and the php will not accept the div within it to create this - is it even possible to change the layout of the results?

Yea it is stored in a database.

 

The script I want to style is:

 

 

<?php

include 'config.php';

include 'opendb.php';

 

$query  = "SELECT shop_name, street_name, town, postcode, contact_number, web_address, user_email FROM user_info";

$result = mysql_query($query);

 

while($row = mysql_fetch_row($result))

{

    $shop_name    = $row[0];

    $street_name = $row[1];

    $town = $row[2];

$postcode = $row[3];

$contact_number = $row[4];

$web_address = $row[5];

$user_email = $row[6];

 

 

 

echo 

"<h5>Name:</h5>$shop_name <br>" .

        "<h5>Address</h5>$street_name <br>" .

"$town <br>" .

"$postcode <br>" .

"<h5>Contact Details</h5>Phone Number:$contact_number <br>" .

"Web Address: $web_address <br>" .

        "Email : $user_email <br><br>";

 

}

 

 

include 'closedb.php';

 

?>

 

 

 

</div>

 

The SQL is:

 

<?php

if (isset($_REQUEST['Submit'])) {

# THIS CODE TELL MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE

$sql = "INSERT INTO $db_table(shop_name,street_name,town,postcode,contact_number,web_address,user_email) values ('".mysql_real_escape_string(stripslashes($_REQUEST['shop_name']))."','".mysql_real_escape_string(stripslashes($_REQUEST['street_name']))."','".mysql_real_escape_string(stripslashes($_REQUEST['town']))."','".mysql_real_escape_string(stripslashes($_REQUEST['postcode']))."','".mysql_real_escape_string(stripslashes($_REQUEST['contact_number']))."','".mysql_real_escape_string(stripslashes($_REQUEST['web_address']))."','".mysql_real_escape_string(stripslashes($_REQUEST['user_email']))."')";

if($result = mysql_query($sql ,$db)) {

echo '<h1>Thank you</h1>Your information has been entered into our database<br><br>';

} else {

echo "ERROR: ".mysql_error();

}

} else {

?>

 

<?php

include 'config.php';
include 'opendb.php';

$query  = "SELECT shop_name, street_name, town, postcode, contact_number, web_address, user_email FROM user_info";
$result = mysql_query($query);

while($row = mysql_fetch_row($result)) {
    $shop_name    = $row[0];
    $street_name = $row[1];
    $town = $row[2];
    $postcode = $row[3];
    $contact_number = $row[4];
    $web_address = $row[5];
    $user_email = $row[6];

    echo  
       "<div style=\"float:left;width:300px;margin-right:20px;\">" .
       " <h5>Name:</h5>$shop_name <br>" .
       "<h5>Address</h5>$street_name <br>" .
       "$town <br>" .
       "$postcode <br>" .
       "<h5>Contact Details</h5>Phone Number:$contact_number <br>" .
       "Web Address: $web_address <br>" .
       "Email : $user_email <br><br>" .
       "</div>";
}

include 'closedb.php';

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.