Fallen_angel Posted December 10, 2006 Share Posted December 10, 2006 Hi I need a bit of help with a script I haveI what I basicly want to do is have a short summary pulled from one of my database fields the database field itself can have 10,000 charictors in it , however I only want to return 250 charictors to be returned so that it can be used as a description in the bellow search script I have looked around but I can't find a way that I can simply just limit the number of charictors the results return . I know it can be done because I have seen it done but just don't know how to do it bellow is my code so far , anyone that can help I would really apreciate it [code]<?php//Connect To databaseinclude "connect.php";$id = $_GET['id'];//collects Data$data=mysql_query(" SELECT * FROM DB where s_id='$id' ")or die(mysql_error());Print "<table class='print_list_alpha' border=0px style=border-bottom:1px;>" ;while ($info= mysql_fetch_array($data) ){Print "<tr><td><img src=./uploads/mini_thumbs/".$info['img']."></td><td><table><tr><td><a href=../guide/report.php?id=".$info['s_id']."><b>".$info['name']."</b></a></td><tr><td> ".$info[notes'] ."</td></tr></table>";}Print "</table>" ;?>[/code]Thanx to anyone that can help Link to comment https://forums.phpfreaks.com/topic/30169-help-with-a-summary-script/ Share on other sites More sharing options...
trq Posted December 10, 2006 Share Posted December 10, 2006 As an example.[code]SELECT SUBSTRING(fld,0,250) FROM tbl WHERE id = '3';[/code]Also note, using the wildcard * is considered bad practice Its more work for the database and can become considerably less maintainable. Link to comment https://forums.phpfreaks.com/topic/30169-help-with-a-summary-script/#findComment-138689 Share on other sites More sharing options...
Fallen_angel Posted December 11, 2006 Author Share Posted December 11, 2006 Ok well i think I have it semi working I think however I may be calling it incorrectly , would I still use ".$info['fieldname']." to call the contained info ? or does it change because I used a substring , atm All I get is no summary at all , no errors and everything else loads ok so I'm guessing it's the way I am calling in on the page I have also replaced the * with the specific fields that I need thankyou very much for that extra tip :) here is what my code looks like now [code]<?php//Connect To databaseinclude "connect.php";$id = $_GET['id'];//collects Data$data=mysql_query("SELECT SUBSTRING(description,0,250) s_id,name,rating,img FROM DB where name LIKE '$id%'ORDER by 'name'")or die(mysql_error());Print "<table class='print_list_alpha' border=0px style=border-bottom:1px;>" ;while ($info= mysql_fetch_array($data) ){Print "<tr style=background-color:#E9F3EA;><td><img src=./uploads/mini_thumbs/".$info['img']."></td><td background-color=#E9F3EA><table><tr><td><a href=../strainguide/page.php?id=".$info['s_id']."><b>".$info['name']."</b></a></td><tr><td> ".$info['notes'] ."</td></tr></table>";}Print "</table>" ;?>[/code] thanx in advance for any help people can give :) Link to comment https://forums.phpfreaks.com/topic/30169-help-with-a-summary-script/#findComment-138759 Share on other sites More sharing options...
Fallen_angel Posted December 11, 2006 Author Share Posted December 11, 2006 He he I feel silly but I got it workign now for any one that wants to see the script it is now as follows [code]<?php//Connect To databaseinclude "connect.php";$id = $_GET['id'];//collects Data$data=mysql_query("SELECT s_id,name,rating,img,description FROM strains where name LIKE '$id%'ORDER by 's_name'")or die(mysql_error());Print "<table class='print_list_alpha' border=0px style=border-bottom:1px;>" ;while ($info= mysql_fetch_array($data) ){Print "<tr style=background-color:#E9F3EA;><td><img src=./uploads/mini_thumbs/".$info['img']."></td><td background-color=#E9F3EA><table><tr><td><a href=../strainguide/page.php?id=".$info['s_id']."><b>".$info['name']."</b></a></td><tr><td> " ;Print substr($info['description'],0,250); Print "</td></tr></table>";}Print "</table>" ;?>[/code]thankyou very much for your assistance :) Link to comment https://forums.phpfreaks.com/topic/30169-help-with-a-summary-script/#findComment-138762 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.