Help please, get no data with substr in mysql php,& erro

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
tovia2000
Forum Newbie
Posts: 12
Joined: Sat Aug 25, 2007 7:45 am

Help please, get no data with substr in mysql php,& erro

Post by tovia2000 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi 

I cant use substring with my mysql database column in php

i get the error:
PHP Notice: Undefined property: stdClass::$body in C:\Inetpub\wwwroot\index2.php on line 241 PHP Notice: Undefined property: stdClass::$body in C:\Inetpub\wwwroot\index2.php on line 241 PHP Notice: Undefined property: stdClass::

and it carries on the same....

my code is as follows:

Code: Select all

<?php

include("db_config.php");

// user credentials
// $host = "localhost";
// $user = "root";
// $pass = "police";
// $data = "test";

// Establish connection, and select db
// $conn = mysql_connect($host, $user, $pass) or die(mysql_error());
// mysql_select_db($data, $conn) or die(mysql_error());

//create some variables
$pagenumber = (isset($_GET["page"]) && is_numeric($_GET["page"])) ? $_GET["page"] : 1;

//establish number of resulsts per page
$perpage = 10;

//establish a padding value
$padding = 7;

// get start index of results
$startindex = ($pagenumber * $perpage) - $perpage;

// get total number of dbms entries
$totalcount = "SELECT COUNT(*) as 'Total' FROM test.articles";
$rscount = mysql_query($totalcount) or die(mysql_error());
$rowcount = mysql_fetch_object($rscount);
 


// Show page listings -----------------------------------------------------
print "<div align=\"center\">";

// get our total number of pages
$numofpages = ceil($rowcount->Total / $perpage);


// pages division
print "<div id = pages>";
	// print link to first page
	print "<a href=\"index2.php?page=1\">First</a> ";



//Show page listings to left:---------------------------------------------------

// if our current page, minus our padding is greater than 1
   if (($pagenumber - $padding) > 1) {
        print "... ";
        // set our lower limit
	$lowerlimit = $pagenumber - $padding;
	// print all padded numbers between lowerlimit and current page
	for($i = $lowerlimit; $i < $pagenumber; $i++) {
		print "<a href=\"index2.php?page=".$i."\">".$i."</a> ";

	}
        
} else {
   // print all numbers between current page, and first page
   for($i = 2; $i < $pagenumber; $i++) {
	print "<a href=\"index2.php?page=".$i."\">".$i."</a> ";
	}
}

//End page listings to left:---------------------------------------------------


// if were not on the first page, or the last page, print current page
if(($pagenumber !=0) && ($pagenumber !=1) && ($pagenumber != $numofpages))
{ print "<b> - " . $pagenumber . " - </b>"; }


//Show page listings to right:---------------------------------------------------

// if our current page, plus our padding , is less than the total number of pages
if (($pagenumber + $padding) < $numofpages) {
// set upper limit
$upperlimit = $pagenumber + $padding;
// print all numbers from padded pages above current page
for($i = ($pagenumber + 1); $i <= $upperlimit; $i++) {
		print "<a href=\"index2.php?page=".$i."\">".$i."</a> ";
		}
		print "... ";
	} else {
//print all page numbers between number of pages and current page
	for($i = ($pagenumber +1); $i < $numofpages; $i++) {
		print "<a href=\"index2.php?page=".$i."\">".$i."</a> ";
	}
}
// print link to last page
print "<a href=\"index2.php?page=".$numofpages."\">Last</a>";

//End page listings to right:---------------------------------------------------

print "</div>";

print "</div>";





// get page results
$sql = "SELECT timestamp1,title,author,substring(body,100) FROM test.articles ORDER BY timestamp1 desc
LIMIT $startindex, $perpage";



// get result set
$rs = mysql_query($sql) or die(mysql_error());

// do we have results
if (mysql_num_rows($rs) > 0) {
// show the results
while ($row = mysql_fetch_object($rs)) {
print "<div>";



print "<div id = title>";
print "<b>  " . $row->title . "  </b>";
print "</div>";


print "<div id = author>";	
print "<b>  " . $row->author . "  </b>";
print "<b>  " . $row->timestamp1 . "  </b>";
print "</div>";



print "</div>";

print "<div id = body>";
print $row->body;
print "</div>";
print "<p>";


}

} else {
    print "Sorry, no results found.";

}


//close our dbms connection
mysql_close($link);

?>
Thanks in Advance

Tovia


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Is this index2.php?.. because there aren't 241 lines here. "Undefined property" notice means that you're referencing a class member that hasn't been initialized.
Post Reply