Forum Moderators: coopster
I'm not even sure if it's possible but can you get the first 100 or whatever you specify from a certain field
ie something like
select id,name,partofstring(0,100,description) from tablename;
meaning I only want the first 100 chars from the description field but all the 'id' and all from 'name'
Can't find anything on mysql.com for this
Thanks
Trent
this is my code
$sql2 = "select Cid, Pid, Sid, link_text, SUBSTRING('chapter_content',0,20) from chapters where chapter_content like '%" . $_GET["query"] . "%'";
and I'm doing standard while and printing
while ($myrow2 = mysql_fetch_array($result2)){
$search_content .= '<p><a href="' . rootdir('chapters.php?pid=' . $myrow2['Pid'] . '&sid=' . $myrow2['Sid'] . '&cid=' . $myrow2['Cid']) . '">' . $myrow2['link_text'] . '</a> - Chapter Page<br/>' . str_replace('¦¦¦¦', ' ', $myrow2['chapter_content']) . '</p>';
}
But now no chapter_content shows... also not getting any errors
Trent
It's weird not to even get an error on any of the ways I try the page still loads and displys the link_text etc ok ....
The content_chapter field is of type 'TEXT' if that makes any difference, other then that I'm stummped.
Also is the way i'm trying to get the return ie $myrow2['chapter_content'], (Just like normal), is that still right
Cheers
Trent
$sql2 = "select Cid, Pid, Sid, link_text, SUBSTRING(chapter_content,0,100) from chapters where chapter_content like '%" . $_GET["query"] . "%'";
$result2 = mysql_query [php.net]($sql2);
while ($myrow2 = mysql_fetch_array($result2)) {
$search_content .= '<p><a href="' . rootdir('chapters.php?pid=' . $myrow2['Pid'] . '&sid=' . $myrow2['Sid'] . '&cid=' . $myrow2['Cid']) . '">' . $myrow2['link_text'] . '</a> - Chapter Page<br/>' . str_replace('¦¦¦¦', ' ', $myrow2['chapter_content']) . '</p>';
I can't imageing what's wrong because the code does what it should ie make a link etc but just won't print anything from $myrow2['chapter_content'].
I may have to let this one go as an unsolved mystery :)
try
$sql2 = "select Cid, Pid, Sid, link_text, SUBSTRING('chapter_content',0,20) AS chapter_content from chapters where chapter_content like '%" . $_GET["query"] . "%'";
I try to echo $myrow2['chapter_content'] in the while statement without the rest and still nothing yet I can echo $myrow2['link_text'] fine.
I also just tried
$sql2 = "select Cid, Pid, Sid, SUBSTRING(link_text,0,5) AS link_text, chapter_content from chapters where chapter_content like '%" . $_GET["query"] . "%'";
and
$sql2 = "select Cid, Pid, Sid, SUBSTRING(link_text,0,5), chapter_content from chapters where chapter_content like '%" . $_GET["query"] . "%'";
(same but without the 'AS')
and it will now show chapter_content but alas now no link_text
maybe a mysql setting problem or version or somthing..
$sql2 = "select Cid, Pid, Sid, SUBSTRING(link_text,0,5) AS link_text, chapter_content from chapters where chapter_content like '%" . $_GET["query"] . "%'";
exit($sql2); // insert this line to stop processing and see statement
$result2 = mysql_query($sql2);
while (...) {
Nice catch on the ALIAS there, BOL
Thansk for your replays
I just got back from holidays and we'll the break did me good I worked it out
it was a combination of using SUBSTRING(chapter_content,0,100) instead of SUBSTRING(chapter_content,1,100) I did try this as suggested by jatar_k but did not combine it with AS chapter_content on the same attempt :(, with I debuged running the query on the command line..
final working code..
$sql2 = "select Cid, Pid, Sid, link_text, SUBSTRING(chapter_content,1,100) AS chapter_content from chapters where chapter_content like '%" . $_GET["query"] . "%'";
I'm using this metod apposed to the substring($myrow['chapter_content'],0,100]) just because I think is quicker code letting mysql do the work and giving php less data to need to work with.
Cheers
Trent