Current location: Hot Scripts Forums » Other Discussions » Database » help with select statment


help with select statment

Reply
  #1 (permalink)  
Old 06-21-07, 05:35 AM
mahmoud82's Avatar
mahmoud82 mahmoud82 is offline
Wannabe Coder
 
Join Date: Nov 2006
Location: Jordan
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
X_X help with select statment

hi,

PHP Code:

 $article_query=$mysql_conn->query("select `articles_tbl`.`ArticleID`,`articles_tbl`.`Title`,`articles_tbl`.`Date`,`articles_tbl`.`Thumb`,`articles_tbl`.`Author`,`articles_tbl`.`Views`,LEFT(articles_tbl.Text, 1200) TEXT,`categories_tbl`.`Private` from `categories_tbl` INNER JOIN `articles_tbl` ON(`articles_tbl`.`CatID`=`categories_tbl`.`CatID`) where `articles_tbl`.`Active`='1' order by `articles_tbl`.`Date` DESC LIMIT 5") or die(mysql_error()); 

this select statment return a 1200 char but i want to be more dynamic by select the character until the select fount ? at the Text so the user insert the article and he will decided how many character he want to display at the home page when he put the ? at the article so the select statment will stop when it found this (?)
can anyone help me.
__________________
Their is no 100% secure system. ZCE
Reply With Quote
  #2 (permalink)  
Old 06-21-07, 05:46 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
SQL Code:
  1. SELECT
  2.   articles_tbl.ArticleID,
  3.   articles_tbl.Title,
  4.   articles_tbl.Date,
  5.   articles_tbl.Thumb,
  6.   articles_tbl.Author,
  7.   articles_tbl.Views,
  8.   SUBSTRING_INDEX(articles_tbl.Text, '?', 1) TEXT,
  9.   categories_tbl.Private
  10. FROM
  11.   categories_tbl
  12. INNER JOIN
  13.   articles_tbl
  14. ON (
  15.   articles_tbl.CatID=categories_tbl.CatID
  16. )
  17. WHERE
  18.   articles_tbl.Active=1
  19. ORDER BY
  20.   articles_tbl.Date
  21. DESC LIMIT 5
this should do. For more information about SUBSTRING_INDEX, have a look at this page:
http://dev.mysql.com/doc/refman/5.0/...ubstring-index

PS: you don't have to wrap the tablenames and fieldnames in `, you only have to do so when the names are reserved keywords (but you should avoid using such names)
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #3 (permalink)  
Old 06-21-07, 06:15 AM
mahmoud82's Avatar
mahmoud82 mahmoud82 is offline
Wannabe Coder
 
Join Date: Nov 2006
Location: Jordan
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
thanx man this is just fine.
__________________
Their is no 100% secure system. ZCE
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
change options of select based on selection in other select nassau JavaScript 3 08-31-06 08:00 AM
Select an option zoliky PHP 3 08-03-06 12:10 PM
Multiple Select phppick JavaScript 3 04-11-05 12:09 AM
Select List insert into DB The Omega JavaScript 1 01-12-05 12:51 PM
i have 3 select box this is urgent traceMe JavaScript 0 12-02-03 01:24 AM


All times are GMT -5. The time now is 05:01 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.