CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   MySQL (http://www.codingforums.com/forumdisplay.php?f=7)
-   -   Page System - problem with sending me in to the next page (http://www.codingforums.com/showthread.php?t=279935)

Saber 10-28-2012 09:10 PM

Page System - problem with sending me in to the next page
 
I have problem with the page system of my site. On a page i have 10 jokes, and i need to go to page 2 to see 10 to 20 jokes, page 3 is 20 to 30 jokes and etc, but the problem is that when i press the button 2, to transfer me to see jokes 10 to 20 i get transfered in a different link this one:
/jokes_category.php?from=3

And it should be this:
/jokes_category.php?from=30&cat_id=1

Why is this problem comming ?
?from=30 means for the site to search jokes from 30 to 40 and id is the category, but it doesnt search the category and it sends me nowhere..

This is the category file:
Code:

<?
include(DIR_LNG.'jokes_category_with_jokes_form.php');
        if (!$HTTP_GET_VARS['cat_id'])
                $post_string = TEXT_ALL_CATEGORIES;
        else
        {
                $select_category_name_SQL = "select * from $database_table_name1 where category_id='".$HTTP_GET_VARS['cat_id']."'";
                $select_category_name_query = bx_db_query($select_category_name_SQL);
                SQL_CHECK(0,"SQL Error at ".__FILE__.":".(__LINE__-1));
                $select_category_name_result = bx_db_fetch_array($select_category_name_query);
                $post_string = "'<b>".$select_category_name_result['category_name'.$slng]."</b>' ".TEXT_CATEGORY;
        }
?>
<tr valign="top">
        <td>

<?

if($mode != "random" && $mode != "search")
{
        $from = $HTTP_GET_VARS['from'];
        $result_array = step( $HTTP_GET_VARS['from'], $item_back_from, $SQL, $display_nr);
}

echo "<table width=\"100%\"><tr><td align=\"center\"><b><font size=\"3\" font-family=\"verdana\" color=\"".TOP_JOKES_PAGE_TITLE_FONTCOLOR."\">"."&nbsp;&nbsp;".$type." ".$post_string."&nbsp;&nbsp;"."</font></td></tr></table><br></b>";

if (sizeof($result_array) == 0)
{
?>
                <table align="center" border="0" cellspacing="0" cellpadding="0" width="100%">
                <tr align="center">
                        <td colspan="4" align="center">
                                <table align="center" border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="<?=THERE_ARE_NO_JOKES_BORDERCOLOR?>">
                                        <tr><td>
                                                <table align="center" border="0" cellspacing="0" cellpadding="0" width="100%" bgcolor="<?=THERE_ARE_NO_JOKES_INTERNAL_BGCOLOR?>">
                                                        <tr><td align="center" style="color:<?=THERE_ARE_NO_JOKES_FONT_COLOR?>">
                                                                <br><b><?=TEXT_NO_JOKES?></b><br><br>
                                                        </td></tr></table>
                                                </td></tr></table>
                        </td>
                </tr>
                </table>
<?
}
for( $i = 0 ; $i < sizeof($result_array) ; $i++ )
{
?>
                <table align="center" border="0" cellspacing="0" cellpadding="1" width="90%">
                <tr>
                        <td background="images/head_bg.jpg" bgcolor="<?=SHORT_JOKE_TITLE_HEAD_BGCOLOR?>" width="5%">
<?
$new_res = '<img src="'.HTTP_LANG_IMAGES.'new.gif" border="0" alt="">';
echo $new_res = (date('Y-m-d',mktime (0,0,0,date('m'),date('d')-$newperiod_for_jokes-1,date('Y'))) < $result_array[$i]['date_add'] ? $new_res : "&nbsp;");
?>
                        </td>
                        <td background="images/head_bg.jpg" bgcolor="<?=SHORT_JOKE_TITLE_HEAD_BGCOLOR?>" align="center" width="95%">
                                <font size="<?=JOKE_TOPHEADER_FONT_SIZE?>" color="<?=JOKE_TOPHEADER_FONT_COLOR?>"><?=TEXT_JOKE_POSTED?> <b><?=$result_array[$i]['name'];?></b> <?=TEXT_AT?> <?=$result_array[$i]['date_add'];?></font>
                        </td>
                </tr>
                <tr>
                        <td colspan="2" bgcolor="<?=SHORT_JOKE_TITLE_BORDERCOLOR?>" >
                                <table align="center" border="0" cellspacing="0" cellpadding="2" width="100%" bgcolor="<?=SHORT_JOKE_TITLE_BGCOLOR?>">
<?
$get_extra= ($HTTP_POST_VARS['adv_search']=="1" || $HTTP_GET_VARS['adv_search']=="1" ? "&adv_search=1" : "").($HTTP_POST_VARS['x'] =="1" ? "&q_search=1" : "");
?>
                                <tr>
                                        <td colspan="2">
                                                <font size="<?=SHORT_JOKE_TITLE_FONT_SIZE?>" color="<?=SHORT_JOKE_TITLE_FONTCOLOR?>">&nbsp;<?=$from+$i+1?>.-</font>
                                                <a href="<?=HTTP_SERVER?>jokes.php?joke_id=<?=$result_array[$i]['joke_id']?><?=$get_extra?>&cat_id=<?=$HTTP_GET_VARS['cat_id']?>&jtype=<?=$jtype?>" style="text-decoration:none;color:<?=SHORT_JOKE_TITLE_FONTCOLOR?>;font-weight:bold"><?=$result_array[$i]['joke_title']?></a>
                                                <br>
                                                &nbsp;<font size="<?=SHORT_JOKE_TEXT_SIZE?>" color="<?=SHORT_JOKE_TEXT_COLOR?>"><?=short_string($result_array[$i]['joke_text'], $joke_listing_show_characters, "...");?></font>
                                        </td>
                                </tr>
                                <tr>
                                        <td align="right" style="font-size:9pt;color:<?=SHORT_JOKE_RATE_EMAIL_FONT_COLOR?>" colspan="2">
                                                &nbsp;<b><?=TEXT_RATE?>
                                                <?
                                                if($result_array[$i]['rating_value'] > 0)
                                                {
                                                        for ($star=0;$star<$result_array[$i]['rating_value'] && $result_array[$i]['rating_value'] != '0';$star++ )
                                                        {
                                                                echo "<img src=\"".DIR_IMAGES."star2.gif\" border=\"0\">";
                                                        }
                                                }
                                                elseif($result_array[$i]['rating_value'] == '0' || $result_array[$i]['rating_value']='NULL' || $result_array[$i]['rating_value']=='')
                                                                echo "0";
                                                        ?>
                                               
                                                </b>,
                                                &nbsp;<b><?=TEXT_EMAILED?></b>&nbsp;<?=$result_array[$i]['emailed_value'];?>&nbsp;&nbsp;&nbsp;
                                        </td>
                                </tr>
                                </table>
                        </td>
                </tr>
                </table>
                <br>

<?
}
?>

                <table align="center" border="0" cellspacing="0" cellpadding="0" width="100%">
                <tr>
                        <td>
<?

make_next_previous_with_number( $from, $SQL, $this_file_name, $get_vars ,$display_nr);
?>
                        </td>
                </tr>
                </table>
        </td>
</tr>

And this is the function that it calles:
Code:

/****************************************************/
// Next prevoius using numbers
/****************************************************/
function make_next_previous_with_number($from, $SQL, $filename, $vars, $display_nr)
{

        $count = bx_db_num_rows(bx_db_query($SQL));
        @$active = ($from+$display_nr) / $display_nr;
        @$total_pages =  ceil($count/$display_nr);

        if ($active <= $display_nr)
        {
                if ($active>1)
                {
                        echo "<a href='".$filename."?from=0&".$vars."'><img src=\"".DIR_IMAGES."first.gif\" border=\"0\"></a>&nbsp;&nbsp;<a href='".$filename."?from=".($active*$display_nr-2*$display_nr)."&".$get_vars = "cat_id=".$cat_id."'><img src=\"".DIR_IMAGES."previous.gif\" border=\"0\"></a>&nbsp;&nbsp;";
                }

                for ( $i = 1 ; $i <($active + $display_nr) && $total_pages >=$i ; $i++ )
                {
                        if ($active == $i)
                        {
                                if ($count > $display_nr)
                                        echo "<b>".$i."</b> ";
                        }
                        else
                                echo "<a href='".$filename."?from=".($i*$display_nr-$display_nr)."&".$vars."'>".$i."</a> ";
                }
                if ($count > $active && $count > $active*$display_nr)
                {
                        echo "&nbsp;&nbsp;<a href='".$filename."?from=".($active*$display_nr)."&".$vars."'><img src=\"".DIR_IMAGES."next.gif\" border=\"0\"></a>";
                        echo "&nbsp;&nbsp;<a href='".$filename."?from=".(ceil($count/$display_nr)*$display_nr-$display_nr)."&".$vars."'><img src=\"".DIR_IMAGES."last.gif\" border=\"0\"></a>";
                }
        }
        else
        {

                if ($active>1)
                {
                        echo "<a href='".$filename."?from=0&".$vars."'><img src=\"".DIR_IMAGES."first.gif\" border=\"0\"></a>&nbsp;&nbsp;<a href='".$filename."?from=".($active*$display_nr-2*$display_nr)."&".$vars."'><img src=\"".DIR_IMAGES."previous.gif\" border=\"0\"></a> ";
                }

                for ( $i = $active - $display_nr ; $i < ($active + $display_nr) && $total_pages >= $i ; $i++ )
                {
                        if ($active == $i)
                                echo "<b>".$i."</b> ";
                        else
                                echo "<a href='".$filename."?from=".($i*$display_nr-$display_nr)."&".$vars."'>".$i."</a> ";
                }

                if ($count > $active * $display_nr)
                {
                        echo "<a href='".$filename."?from=".($active*$display_nr)."&".$vars."'><img src=\"".DIR_IMAGES."next.gif\" border=\"0\"></a>";
                        echo "&nbsp;&nbsp;<a href='".$filename."?from=".(ceil($count/$display_nr)*$display_nr-$display_nr)."&".$vars."'><img src=\"".DIR_IMAGES."last.gif\" border=\"0\"></a>";
                }
        }

}


Saber 10-30-2012 01:30 PM

I have updated my first post and added more detailed info, can anyone help me ?

Fou-Lu 10-30-2012 02:29 PM

This code is old. If you update to PHP 5.4, it will not function at all.
$HTTP_GET_VARS was replaced with $_GET superglobal in PHP 4.1. Registered long arrays have been supported the last decade or so for legacy code only.
You are not creating $get_vars in that code anywhere. So you are triggering an error and providing the function call with null. This would be an existing querystring; you can use the $_GET and build a string (looping or using http_build_query), or pull it from the server's QUERY_STRING. I'd suggest http_build_query as you can pop off the from before using it.

Saber 10-30-2012 03:33 PM

Thank you about that, but i don't know how to use the tips you gave me. The truth is that i don't undarstand nothing about PHP i was under the impression that this is finished system. I didn't know i would have to do work on it. I know the code is old, but i think it would not make problem for me. But as i said, i don't know PHP i don't know how to do what you are saying. Is there absolutely no chance for you to make this work, to repair the code ?

Fou-Lu 10-30-2012 04:59 PM

Quote:

Originally Posted by Saber (Post 1286893)
Thank you about that, but i don't know how to use the tips you gave me. The truth is that i don't undarstand nothing about PHP i was under the impression that this is finished system. I didn't know i would have to do work on it. I know the code is old, but i think it would not make problem for me. But as i said, i don't know PHP i don't know how to do what you are saying. Is there absolutely no chance for you to make this work, to repair the code ?

I won't rewrite it, but it would be easy to patch it to work properly. Simply search and replace this: $HTTP_GET_VARS and replace with $_GET, and then right before make_next_previous_with_number( $from, $SQL, $this_file_name, $get_vars ,$display_nr); add this:
PHP Code:

$aQS $_GET;
unset(
$aQS['from']);
$get_vars http_build_query($aQS); 

And that looks like it should pass the querystring properly.

Saber 10-30-2012 06:05 PM

I can't thank you enough man, you don't know how much this means to me, thank you.

Fou-Lu 10-30-2012 08:22 PM

Yep, yw. You may want to search for a new one though, just make sure your criteria includes PHP5 as its version, and it should be relatively up to date.


All times are GMT +1. The time now is 09:10 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.