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
Help needed...I will keep your DB Skills Sharp!
Old 03-22-2011, 08:00 PM Help needed...I will keep your DB Skills Sharp!
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Hi all,

I once again need some help with something I had posted here in the past, but deleted the entire script in the past not thinking it would be so handy for me in the future, and I had it working before someone replied to my post with the solution so I only have part of the solution posted in this thread: http://tycoontalk.freelancer.com/cod...n-part-ii.html)

Anyway what I am looking for is a way to echo the correct table code so that I have two columns by five rows. That will produce a table with 2 columns (across) and 5 rows (down) of images echoed out of the mysql database.



PHP Code:
<?php
$tr 
2;
$td 1;

for(
$i 0$i $tr$i++) 
{
echo 
'<tr>';
while(
$row mysql_fetch_array($result)) 

for(
$j 0$j $td$j++)
{
echo 
'<td>';

echo 
"<img src=\"machform/data/form_1/files/".$row['element_3']."\" border=\"1\" alt=\"".$row['element_1']."\" title=\"".$row['element_1']."\">";
// echo "Price: $$row[element_4]";
echo '</td>';

}
echo 
'</tr>';


?>
I want to add the above php code into the echo part of this pagination script:

PHP Code:
<html>
<head><title>Reunite My Site - Animals, Pets, & Accessories</title>

<link rel="stylesheet" type="text/css" href="/css/pagination.css" media="screen" />
<link rel="stylesheet" type="text/css" href="/css/default.css" media="screen" />

</head>

<body>

<div class="gradient">
<div class="pagination white">

<?php
            
/* Include your code to connect to DB. */
            
            
include('config.php');

            
/* Your DB table name */

            
$tbl_name="amp_ads";

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

            
/* 
            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 ad_type = '1'";
                
$total_pages mysql_fetch_array(mysql_query($query));
                
$total_pages $total_pages[num];

            
/* Setup vars for query. */
            
$targetpage "Animals, Pets & Accessories.php";     //your file name  (the name of this file)

            
$limit 2;              //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 remote_banner FROM $tbl_name LIMIT $start$limit";
                
$result mysql_query($sql);

            
/* 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\" 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\" 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\" class=\"number current\">$counter</a>";
                }
        
$pagination.= "<span class=\"dots\">...</span>";
        
$pagination.= "<a href=\"$targetpage?page=$lpm1\" class=\"number\">$lpm1</a>";
        
$pagination.= "<a href=\"$targetpage?page=$lastpage\" 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\" class=\"number\">1</a>";
        
$pagination.= "<a href=\"$targetpage?page=2\" 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\" class=\"number current\">$counter</ a>";                
        }
        
$pagination.= "<span class=\"dots\">...</span>";
        
$pagination.= "<a href=\"$targetpage?page=$lpm1\" class=\"number\">$lpm1</a>";
        
$pagination.= "<a href=\"$targetpage?page=$lastpage\" class=\"number current\">$lastpage</a>";        
        }

        
//close to end; only hide early pages

                
else
        {
        
$pagination.= "<a href=\"$targetpage?page=1\" class=\"number\">1</a>";
        
$pagination.= "<a href=\"$targetpage?page=2\" 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\" class=\"number current\">$counter</a>";
        }
        }
        }
        
        
//next button

        
if ($page $counter 1)
        
$pagination.= "<a href=\"$targetpage?page=$next\" class=\"number current\"> next </a>";
        else
        
$pagination.= "<span class=\"disabled\"> next </span>";
        
$pagination.= "</div>\n";        
            }

$result mysql_query("SELECT * FROM amp_ads WHERE ad_type = '1'") or die(mysql_error());

echo 
"<table align=\"center\" border=\"0\" cellpadding=\"5\" cellspacing=\"5\">";

while(
$row mysql_fetch_array($result)){

echo 
"<td>";

$f fopen('http://www.reunitemysite.com/scripts/amp/show.php?z=1&incl=1&ip='.getenv('REMOTE_ADDR').'&url='.urlencode(getenv('HTTP_HOST').getenv('REQUEST_URI')),'r');
echo 
stripslashes(fread($f,100000));
fclose($f);

echo 
"</td>";

}

?>
</div>

<?=$pagination?> 
</body>
</html>
The part that echoes the table part of the script is near the bottom, right after this:
Code:
$result = mysql_query("SELECT * FROM amp_ads WHERE ad_type = '1'") or die(mysql_error());
Thank you, and I really appreciate you effort!
Brian
__________________
Made2Own

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

Last edited by Brian07002; 03-22-2011 at 08:01 PM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-23-2011, 06:05 AM Re: Help needed...I will keep your DB Skills Sharp!
Skilled Talker

Posts: 50
Trades: 0
Does it have to be a table? If you put your images in a UL within a Div when the images get to the end of the Div they will automatically flow on to the next row.

Wayne.
HullBorn is offline
Reply With Quote
View Public Profile
 
Old 03-23-2011, 08:20 AM Re: Help needed...I will keep your DB Skills Sharp!
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Would it be:

This thread? OR this one?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-23-2011, 05:11 PM Re: Help needed...I will keep your DB Skills Sharp!
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Chris, neither of those url examples are right, but Wayne is correct, I am just going to need a sample if you could. A working one for this particular issue would be great,

Btw, in the above code, (the <b>First Code Box</b> I am getting the results in one row and the banners are out putting across the page, scrolling a mile wide, not like how i want it to display like 2 banners across and 5 down

Thank you *both* for your thoughts on this topic.
Brian
__________________
Made2Own

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

Last edited by Brian07002; 03-23-2011 at 06:17 PM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 03-23-2011, 06:59 PM Re: Help needed...I will keep your DB Skills Sharp!
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Count 2 cells close the row and open a new row.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-24-2011, 06:28 AM Re: Help needed...I will keep your DB Skills Sharp!
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Quote:
Originally Posted by chrishirst View Post
Count 2 cells close the row and open a new row.
Chris, I don't know how I do it, I just doo it! I guess some times it takes a kick in the pants.

Thanks!
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help needed...I will keep your DB Skills Sharp!
 

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.18435 seconds with 12 queries