Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Centering some php code...
Old 06-07-2012, 11:33 PM Centering some php code...
Brian07002's Avatar
Defies a Status

Posts: 2,301
Name: ...
Location: ...
Trades: 1
Hi,

Can someone help me do a simple center? The images are output where the {$row['preview']} tag is. I want to center that tag. I have tried many ways, just guess it's tired-ness setting in...Man I wish I wasn't human...

Here's the code
Note: I have commented out the included css files in advance so it's only modifying the code below:

PHP Code:
<?php

$page_url 
parse_url($_SERVER["REQUEST_URI"], PHP_URL_QUERY);
$page_url .= "&" $_SERVER['QUERY_STRING'];
parse_str($page_url$_GET);

include(
'./common.php');
include(
'./path.php');

$category $_GET["cat"];
$cid $_GET["cid"];
if (empty(
$category) && empty($cid)) {
    
Header("Location: " getCategoryPath());
    exit;
}

$subcategory $_GET["subcat"];
$sid $_GET["sid"];
if (empty(
$subcategory) && empty($sid)) {
    
Header("Location: " getCategoryPath());
    exit;
}


// Turn on error reporting
error_reporting(E_ALL);
ini_set('display_errors','off');


$category replace_once_text($category);
$cid intval($cid);
$query "SELECT cid, seo_name, category_name FROM `amp_category` WHERE parent_cid = 0 and (seo_name = '{$category}' or cid = '{$cid}')";
$row mysql_fetch_array(mysql_query($query));
$cid $row['cid'];
$category_name $row['category_name'];
$category_seo_name $row['seo_name'];

if (
$cid == "" || $cid <= ){
    
Header("Location: " getCategoryPath());
    exit;
}

$subcategory replace_once_text($subcategory);
$sid intval($sid);
$query "SELECT cid, seo_name, category_name FROM `amp_category` WHERE parent_cid = '{$cid}' and (seo_name = '{$subcategory}' or cid = '{$sid}')";
$row mysql_fetch_array(mysql_query($query));
$sid $row['cid'];
$subcategory_name $row['category_name'];
$subcategory_seo_name $row['seo_name'];

if (
$sid == "" || $sid <= ){
    
Header("Location: " getSubcatPath($category_seo_name$cid));
    exit;
}

$zid intval($_GET['zid']);
if (
$zid != "" && $zid 0)
    
$query "select * from `amp_zones` where `n` = '$zid' limit 1";
else
    
$query "select * from `amp_zones` where `cid` = '$sid' limit 1";

$rowZone mysql_fetch_array(mysql_query($query));
$zid $rowZone['n'];
if (empty(
$zid)) $zid 'xxx';

$query "select * from `amp_zones` where `cid` = '$sid' order by `title`";
$result mysql_query($query);
$optionBox ""$linkBox "";
while (
$row mysql_fetch_array($result))
{
    
$sel ="";
    if (
$row['n'] == $zid$sel ="selected";
    
$optionBox .= "<option value='{$row['n']}{$sel}>{$row['title']}</option>";
    if (
$isSEO){
        
$linkBox .= "<a href='?zid={$row['n']}'>{$row['title']}</a></br>";
    }
    else {
        
$linkBox .= "<a href='?cid={$cid}&sid={$sid}&zid={$row['n']}'>{$row['title']}</a></br>";
    }
}

?>

<html>
<head><title>Reunite My Site - Zones Navigation Page</title> 
<!--<link rel="stylesheet" type="text/css" href="/css/index.css" media="screen" />-->
<!-- <link rel="stylesheet" type="text/css" href="/css/pagination.css" media="screen" />  -->
</head>

<style type="text/css">

body {
color: #fff;
}

#main_content {
background-color: #66CCCC;
border: 1px solid #000;
color: #fff;
margin: auto;
padding-left:2.5px;
padding-right:2.5px;
width: 100%;
}

#outer {
width: 98%;
}
.my_element 
{
    float:left; 
    margin: 0 0 0 0;
    min-width: 300px;
    }
 .wrapper_central 
 {   width: 98%;
     margin: auto;
     padding: auto;
     text-align:center;
     }
 div.pagination a.my_details 
 {
     color:#fff;
     }
</style>


<body> 
<div id="main_content">
<div class="pagination white">
<div id="1" align="center"><h3><a href="<?php echo getSubcatPath($category_seo_name$cid); ?>"><?php echo "You're in the""&nbsp;",$category_name?></a> / <a href="<?php echo getZonesPath($category_seo_name$cid$subcategory_seo_name$sid); ?>"><?php echo $subcategory_name?>&nbsp;Category</a></h3></div>

<script>
<!--
function doChange(obj){

<?php    
    
if ($isSEO) {
        echo 
"document.location = '?zid='+ obj.value;";
    }
    else {
        echo 
"document.location = '?cid={$cid}&sid={$sid}&zid='+ obj.value;";
    }
?>
}

-->
</script>
<?php 
if  ($optionBox != "") {
?>
<select name="zid" onchange="doChange(this);">
<?php
    
echo $optionBox;
?>
</select>
<?php 
}
?>
<p />

<?php 

// Turn on error reporting
error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors','on');

?>

<?php 

// Pagination Code


          
            /* Your DB table name */

            
$tbl_name="amp_ads";

            
// How many adjacent pages should be shown on each side?
            
$adjacents 1;

            
/* 
            First get total number of rows in data table. 
            If you have a WHERE clause in your query, make sure you mirror it here.
            */


            
$query "SELECT COUNT(*) as num FROM $tbl_name WHERE zones like '%_{$zid}_%' and `ad_complete` = 1";

            
$total_pages mysql_fetch_array(mysql_query($query));
            
$total_pages $total_pages['num'];
  
            
            
/* Setup vars for query. */
            
if ($isSEO)
            {
                
$targetpage "?";     //your file name  (the name of this file)
            
}
            else
            {
                
$targetpage getZonesPath($category_seo_name$cid$subcategory_seo_name$sid );     //your file name  (the name of this file)
            
}

            
$limit 6;              //how many items to show per page

            
$page $_GET['page'];

            if(
$page
            
$start = ($page 1) * $limit//first item to display on this page

            
else
            
$start 0;           //if no page var is given, set start to 0
            
            /* Get data. */

            
$sql "SELECT * FROM $tbl_name WHERE zones like '%_{$zid}_%'  and `ad_complete` = 1 LIMIT $start$limit";

             
// exit($sql);
            
$result mysql_query($sql) or die(mysql_error());

            
/* Setup page vars for display. */
            
if ($page == 0$page 1;           //  if no page var is given, default to 1.
            
$prev $page 1;                   //  previous page is page - 1
            
$next $page 1;                   //  next page is page + 1
            
$lastpage ceil($total_pages/$limit);    //lastpage is = total pages / items per page, rounded up.
            
$lpm1 $lastpage 1;            //last page minus 1

            /*
            Now we apply our rules and draw the pagination object. 
            We're actually saving the code to a variable in case we want to draw it more than once.
            */

            
$pagination "";
            if(
$lastpage 1)
           { 
            
$pagination .= "";

            
//previous button


            
if ($page 1
            
$pagination.= "<a href=\"$targetpage&page=$prev&zid={$zid}\" class=\"current\"> previous </a>";
            else
            
$pagination.= "<span class=\"disabled\"> previous </span>";

            
//pages

            
if ($lastpage + ($adjacents 2))    //not enough pages to bother breaking it up
           
{    
            for (
$counter 1$counter <= $lastpage$counter++)
           {
            if (
$counter == $page)
            
$pagination.= "<span class=\"number\">$counter</span>";
            else
            
$pagination.= "<a href=\"$targetpage&page=$counter&zid={$zid}\" class=\"number current\">$counter</a>";                
           }
           }
            elseif(
$lastpage + ($adjacents 2))  //enough pages to hide some
           
{

           
//close to beginning; only hide later pages

            
if($page + ($adjacents 2))        
           {
            for (
$counter 1$counter + ($adjacents 2); $counter++)
           {
            if (
$counter == $page)
            
$pagination.= "<span class=\"number\">$counter </span>";
            else
            
$pagination.= "<a href=\"$targetpage&page=$counter&zid={$zid}\" class=\"number current\">$counter</a>";
           }
            
$pagination.= "<span class=\"dots\">...</span>";
            
$pagination.= "<a href=\"$targetpage&page=$lpm1&zid={$zid}\" class=\"number\">$lpm1</a>";
            
$pagination.= "<a href=\"$targetpage&page=$lastpage&zid={$zid}\" class=\"number current\">$lastpage</a>";        
           }

            
//in middle; hide some front and some back

            
elseif($lastpage - ($adjacents 2) > $page && $page > ($adjacents 2))
           {
            
$pagination.= "<a href=\"$targetpage&page=1&zid={$zid}\" class=\"number\">1</a>";
            
$pagination.= "<a href=\"$targetpage&page=2&zid={$zid}\" class=\"number\">2</a>";
            
$pagination.= "<span class=\"dots\">...</span>";
            for (
$counter $page $adjacents$counter <= $page $adjacents$counter++)
           {
            if (
$counter == $page)
            
$pagination.= "<span class=\"number\">$counter</span>";
            else
            
$pagination.= "<a href=\"$targetpage&page=$counter&zid={$zid}\" class=\"number current\">$counter</ a>";                
           }
            
$pagination.= "<span class=\"dots\">...</span>";
            
$pagination.= "<a href=\"$targetpage&page=$lpm1&zid={$zid}\" class=\"number\">$lpm1</a>";
            
$pagination.= "<a href=\"$targetpage&page=$lastpage&zid={$zid}\" class=\"number current\">$lastpage</a>";        
           }

            
//close to end; only hide early pages

            
else
           {
            
$pagination.= "<a href=\"$targetpage&page=1&zid={$zid}\" class=\"number\">1</a>";
            
$pagination.= "<a href=\"$targetpage&page=2&zid={$zid}\" class=\"number\">2</a>";
            
$pagination.= "<span class=\"dots\">...</span>";
            for (
$counter $lastpage - (+ ($adjacents 2)); $counter <= $lastpage$counter++)
           {
            if (
$counter == $page)
            
$pagination.= "<span class=\"number\">$counter</span>";
            else
            
$pagination.= "<a href=\"$targetpage&page=$counter&zid={$zid}\" class=\"number current\">$counter</a>";
           }
           }
           }
        
            
//next button

            
if ($page $counter 1)
            
$pagination.= "<a href=\"$targetpage&page=$next&zid={$zid}\" class=\"number current\"> next </a>";
            else
            
$pagination.= "<span class=\"disabled\"> next </span>";
            
$pagination.= "</div>\n";        
           }
           
           
// End of Pagination Script //


?>

<?php

##################################################################################

function create_banner($ad_type_vars,$ad_vars,$this_url) {
global 
$s;
if (
$ad_vars[kind]=='raw')
{ if (
$ad_vars[javascript])
  { 
$ad '<iframe onfocus="track_image'.$ad_vars[n].$ad_vars[camp].'.src=\''.$this_url.'&ix=1\'" src="'.$s[site_url].'/show_i.php?'.str_replace("$s[site_url]/click.php?",'',$this_url).'&target='.$s[target].'" width='.$ad_type_vars[w].' height='.$ad_type_vars[h].' marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling="no"></iframe>
     <img src="'
.$s[site_url].'/images/blank.gif" width="0" height="0" id="track_image'.$ad_vars[n].$ad_vars[camp].'">';
  }
  else
  { 
    
$ad $ad_vars[raw];
  }
}
elseif (
eregi(".*swf$",$ad_vars[banner]))
$value[click_tag] = urlencode($this_url).'&window='.$s[target];
  
$value[banner] = $ad_vars[banner]; $value[w] = $ad_type_vars[w]; $value[h] = $ad_type_vars[h];
  
$line $s[flash_code];
  
reset ($value); while(list($k,$v) = each($value)) $line str_replace("#%$k%#",$v,$line);
  
$ad eregi_replace("#%[a-z0-9_]*%#",'',$line);
}
else 
$ad '<a target="'.$s[target].'" href="'.$this_url.'"><img alt="'.$ad_vars[alt].'" border=0 src="'.$ad_vars[banner].'" width="'.$ad_type_vars[w].'" height="'.$ad_type_vars[h].'"></a>';
return 
$ad;
}

##################################################################################

  
  
$iPos=1;
  while (
$row=mysql_fetch_array($result)){
    
//print_r($row);
    
$ads[$iPos] = $row;
    
$iPos++;
  }

// Start of Multiple Columns Script //

    
$cols=1;    // Here we define the number of columns
    
echo "<div class=\"wrapper_central\" >"// The container table with $cols columns
    
$iPos 1;
    do {
        for(
$i=1;$i<=$cols;$i++) {  // All the rows will have $cols columns even if
                        // the records are less than $cols
        
$row=$ads[$iPos];
        if(
$row) {
            
/*
            $ad_vars = $row;
            if (!$ad_type_vars)
            { $q = mysql_query("select ad_type,w,h,color_style,logotext_color from $s[pr]ad_types where n = '$ad_vars[ad_type]'");
              $ad_type_vars = mysql_fetch_assoc($q);
            }
            $this_url = $base_url."";
            if ($ad_type_vars[ad_type]=='banner') $ad = create_banner($ad_type_vars,$ad_vars,$this_url);
            */
     
 
?>
              <div class="my_element"><?php echo "<p>{$row['title']}</p>{$row['preview']} <br/><a class=\"my_details\" href='{$root_path}/details.php?n={$row['n']}&cid=$cid&sid=$sid&zid=$zid&page=$page'>Details...</a>"?></div>
<?
            $iPos
++;
            }
            else{
                
// echo "<tr><td>&nbsp;</td></tr>";  //If there are no more records at the end, add a blank column
            
}
        }
    } while(
$row);
          echo 
"<div style=\"clear:both;\">&nbsp;</div></div>";

// End of Multiple Columns Script //

echo $pagination

?>



<?php

// Display the total number of categories.

$query "SELECT COUNT(*) as num FROM $tbl_name WHERE zones like '%_{$zid}_%'";
$row mysql_fetch_array(mysql_query($query));
$count $row['num'];


// Start Subcategories Counter

if ( $count == ) {

echo 
"<p />";
echo 
"There is currently Only" ."&nbsp;" .$count ."&nbsp;" ."Ads in this Subategory!";

} else {

echo 
"<p />";
echo 
"There are currently" ."&nbsp;" .$count ."&nbsp;" ."Ads in this Subategory!";
}

// End Subcategories Counter
?>

</div>

<?php
echo "<br>{$linkBox}";
?>

<div style="padding-right: 5px;" align="right">Copyright &copy; 2012 - 2076</div>
<p />
</div>
</body>
</html>
Thank you in advance!
Brian
__________________
Made2Own

Please login or register to view this content. Registration is FREE

Last edited by Brian07002; 06-07-2012 at 11:34 PM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-08-2012, 01:33 AM Re: Centering some php code...
lizciz's Avatar
Super Spam Talker

Posts: 845
Name: Mattias Nordahl
Location: Sweden
Trades: 0
You could i.e. enclose it within a centered div or paragraph.

Code:
.center { text-align: center; }
PHP Code:
echo '<p class="center">' $row['preview'] . '</p>' 
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 06-08-2012, 06:48 AM Re: Centering some php code...
Brian07002's Avatar
Defies a Status

Posts: 2,301
Name: ...
Location: ...
Trades: 1
Quote:
Originally Posted by lizciz View Post
You could i.e. enclose it within a centered div or paragraph.

Code:
.center { text-align: center; }
PHP Code:
echo '<p class="center">' $row['preview'] . '</p>' 
Could you answer directly, as I tried the copy/paste to that code, and it didn't center, just slightly adjusted over to the right...Here's the page, I remove you code above, as in am in a rush to work, but the test page is:

http://reunitemysite.com/category/An...uities/?zid=24

I will be home at around 1:00pm est.
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 06-08-2012, 11:59 AM Re: Centering some php code...
lizciz's Avatar
Super Spam Talker

Posts: 845
Name: Mattias Nordahl
Location: Sweden
Trades: 0
You've added left float to the "my_element" class. What exactly is it that you want to center?
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 06-08-2012, 01:19 PM Re: Centering some php code...
Brian07002's Avatar
Defies a Status

Posts: 2,301
Name: ...
Location: ...
Trades: 1
Quote:
Originally Posted by lizciz View Post
You've added left float to the "my_element" class. What exactly is it that you want to center?
Hi,

I would like to center the part on the page that says test ad and test ad 2 (going across) and the ads under each of those titles as well as the details link under that. so that whole block of code if using colorzilla (firefox addon) it would be called: div.wrapper_central ( I think it's that or my_element class, but I can't get either or centered)

Brian
__________________
Made2Own

Please login or register to view this content. Registration is FREE

Last edited by Brian07002; 06-08-2012 at 01:20 PM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 06-08-2012, 01:58 PM Re: Centering some php code...
lizciz's Avatar
Super Spam Talker

Posts: 845
Name: Mattias Nordahl
Location: Sweden
Trades: 0
I would change the wrapper_central to this:

Code:
.wrapper_central {
    display: table;
    margin: auto;
}
display:table; will make the element take as little space as possible, instead of streching to 100% width as block elements does, meaning that it can be centered by setting the horizontal margin to auto. Just remember to also remove the "width: 98%;".
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 06-08-2012, 02:25 PM Re: Centering some php code...
Brian07002's Avatar
Defies a Status

Posts: 2,301
Name: ...
Location: ...
Trades: 1
Quote:
Originally Posted by lizciz View Post
I would change the wrapper_central to this:

Code:
.wrapper_central {
    display: table;
    margin: auto;
}
display:table; will make the element take as little space as possible, instead of streching to 100% width as block elements does, meaning that it can be centered by setting the horizontal margin to auto. Just remember to also remove the "width: 98%;".
Worked nicely!
Thank you very much!
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Centering some php code...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31451 seconds with 11 queries