PDA

View Full Version : PHP: Error



Christopher
June 6th, 2002, 15:17
I got this from the one that I think spec posted in my other thread "Separate Pages," but now it throws an error on the last line, the ?> is the only thing on that line... I did custimize it and add a little bit, but I don't think anything is wrong with it... Please just look over it, thanx!


<?php

mysql_connect("my_server","my_database","my_password");
mysql_select_db("my_database");


if(empty($per_page))
{
$per_page = "10";
}

if ((empty($page)) || ($page <= 0))
{
$page = 1;
}

$limitvalue = $page * $per_page - ($per_page);
$sql = "SELECT * FROM dis LIMIT $limitvalue, $per_page";
$sqlcount = "SELECT COUNT(*) FROM dis";
$print_query ="?per_page=$per_page&";

$sql_countresult = mysql_query($sqlcount);
list($totalrows) = mysql_fetch_row($sql_countresult);

if ($get_items = mysql_query($sql))
{
$num_items = mysql_num_rows($get_items);

if ($num_items > 0)
{
if ($per_page < $totalrows)
{
make_user_page_nums($totalrows, $print_query, "$PHP_SELF");
}

print "<table>";
$x = 1;
while ($foo = mysql_fetch_array($get_items) )
{
if($x == 1)
{
$color = "#FFFFFF";
$x++;
}
elseif($x == 2)
{
$color = "#C0C0C0";
$x = 1;
}

print "<tr><td bgcolor=\"$color\">";
print "<br><a href=\"page.php?pid=3&did=$foo[did]&title=".urlencode($foo[dname])."\">".stripslashes($foo[dname])."</a><br>";
print "Date Added: $foo[ddate]<br>";
print "Average Rating: $foo[drate]<br><br>";
print "</td></tr>";
}
print "</table";

function make_user_page_nums($totalrows, $print_query, $page_name) {
global $per_page;
global $page;
global $limitvalue;

print "<br><br><br>";

if($page != 1) {
$pageprev = $page - 1;
echo "<a href=\"".$page_name.$print_query."page=".$pageprev."\">&lt;Prev</a> ";
}

$numofpages = $totalrows/$user_view_limit;

for($i= 0; $i < $numofpages; $i++)
{

$real_page = $i + 1;
if ($real_page!=$page)
{
print " <a href=\"".$page_name.$print_query."page=".$real_page."\">".$real_page."</a> ";
}

else
{
echo "<b>".$real_page."</b>";
}
}

if(($totalrows-($user_view_limit*$page)) > 0)
{
$pagenext = $page + 1;
print " <a href=\"".$page_name.$print_query."page=".$pagenext."\">Next &gt;</a> ";
}

}

?>

spec
June 6th, 2002, 15:56
Thats usually if you brake out of php or you are missing a closing bracket. Look at your if/while/functions and see if the brakets add up

YUPAPA
June 6th, 2002, 15:59
Get rid of the } at the end if you want a direct answer...

Christopher
June 6th, 2002, 17:17
No, still there. I think the last brace is for the if statement.. this one: if ($get_items = mysql_query($sql))
I think it goes all way down to the end.

spec
June 6th, 2002, 17:48
Yapa Try not to contradict good advice with bad advice
if you or christopher took the time to take my advice and count your brackets you would see that



if ($get_items = mysql_query($sql))
{
$num_items = mysql_num_rows($get_items);

if ($num_items > 0)
{
if ($per_page < $totalrows)
{
make_user_page_nums($totalrows, $print_query, "$PHP_SELF");
}

print "<table>";
$x = 1;
while ($foo = mysql_fetch_array($get_items) )
{
if($x == 1)
{
$color = "#FFFFFF";
$x++;
}
elseif($x == 2)
{
$color = "#C0C0C0";
$x = 1;
}

print "<tr><td bgcolor=\"$color\">";
print "<br><a href=\"page.php?pid=3&did=$foo[did]&title=".urlencode($foo[dname])."\">".stripslashes($foo[dname])."</a><br>";
print "Date Added: $foo[ddate]<br>";
print "Average Rating: $foo[drate]<br><br>";
print "</td></tr>";
}
print "</table";

is missing some brakets
at least one but i am counting 2,

YUPAPA
June 6th, 2002, 17:54
Originally posted by spec
Yapa Try not to contradict good advice with bad advice

I am Yupapa. What was wrong with me? I was trying to help him.

Christopher
June 6th, 2002, 18:16
Yupapa, thank you anyway.

spec, I already did look over everything and found nother wrong, but I will look again for I have an untrained eye.

YUPAPA
June 6th, 2002, 19:00
<?php

mysql_connect("my_server","my_database","my_password");
mysql_select_db("my_database");


if(empty($per_page)) {
$per_page = "10";
}

if ((empty($page)) || ($page <= 0)) {
$page = 1;
}

$limitvalue = $page * $per_page - ($per_page);
$sql = "SELECT * FROM dis LIMIT $limitvalue, $per_page";
$sqlcount = "SELECT COUNT(*) FROM dis";
$print_query ="?per_page=$per_page&";

$sql_countresult = mysql_query($sqlcount);
list($totalrows) = mysql_fetch_row($sql_countresult);

if ($get_items = mysql_query($sql)) {
$num_items = mysql_num_rows($get_items);

if ($num_items > 0) {
if ($per_page < $totalrows) {
make_user_page_nums($totalrows, $print_query, "$PHP_SELF");
}
print "<table>";
$x = 1;
while ($foo = mysql_fetch_array($get_items) ) {
if($x == 1) {
$color = "#FFFFFF";
$x++;
} elseif($x == 2) {
$color = "#C0C0C0";
$x = 1;
}
print "<tr><td bgcolor=\"$color\">";
print "<br><a href=\"page.php?pid=3&did=$foo[did]&title=".urlencode($foo[dname])."\">".stripslashes($foo[dname])."</a><br>";
print "Date Added: $foo[ddate]<br>";
print "Average Rating: $foo[drate]<br><br>";
print "</td></tr>";
}
print "</table>";

function make_user_page_nums($totalrows, $print_query, $page_name) {
global $per_page;
global $page;
global $limitvalue;
print "<br><br><br>";

if($page != 1) {
$pageprev = $page - 1;
echo "<a href=\"".$page_name.$print_query."page=".$pageprev."\">&lt;Prev</a> ";
}
$numofpages = $totalrows/$user_view_limit;
for($i= 0; $i < $numofpages; $i++) {
$real_page = $i + 1;
if ($real_page!=$page) {
print " <a href=\"".$page_name.$print_query."page=".$real_page."\">".$real_page."</a> ";
} else {
echo "<b>".$real_page."</b>";
}
}
if(($totalrows-($user_view_limit*$page)) > 0) {
$pagenext = $page + 1;
print " <a href=\"".$page_name.$print_query."page=".$pagenext."\">Next &gt;</a> ";
}
}
}
}

?>

Christopher
June 6th, 2002, 19:28
Mind sharing what you changed? :D

YUPAPA
June 6th, 2002, 20:55
INDENTATION and a few brakets! :classic2:

spec
June 6th, 2002, 20:59
I was just wondering why you are defining a function in the middle of your nested if statements

Christopher
June 6th, 2002, 21:17
It os not my code (almost all of isn't), I think it was you who suggested it in my other thread "Separate Pages"

spec
June 6th, 2002, 21:20
Sorry yes i did, well it works. Odd that snipe did such a sloppy job. She usually is alot better

Christopher
June 6th, 2002, 21:37
Well, I might have screwed up the braces and she said that she couldn't get the tabs right, so mabe she did do it good.

YUPAPA
June 6th, 2002, 21:57
WHO is sheeeee?? :confused: