Current location: Hot Scripts Forums » Programming Languages » PHP » convert problem


convert problem

Reply
  #1 (permalink)  
Old 02-22-08, 05:10 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
convert problem

Hi there..

I got this data in my DB:

HTML Code:
<p style="margin-top: 0pt; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; word-break: normal; direction: ltr; text-indent: 0in; line-height: normal; unicode-bidi: embed; text-align: left">Op goede locatie in de wijk<p style="margin-top: 0pt; margin-bottom: 0pt; margin-left: 0in; word-break: normal; direction: ltr; unicode-bidi: embed; text-align: left"><br />&nbsp;</p></span>
I set in my php code that only the first 120 characters of this text must be shown..
but as you can see the first 120 characters are "html" code. so nothing is shown.
How can I fix this?..

_j
Reply With Quote
  #2 (permalink)  
Old 02-22-08, 05:19 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
use the strip_tags function to strip the html, and then display the first 120 characters:

PHP Code:

$string substr (strip_tags ($string), 0120); 

__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #3 (permalink)  
Old 02-22-08, 05:46 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
searching problem

great.. it works fine!

another question:
I use this script to search in my DB:
PHP Code:

$word $plaats;


if(
$soort == "geen") { $soort "[[:alnum:]]"; }
if(
$kamers == "0") { $kamers "[[:digit:]]"; }
if(
$woonopp == "0") { $woonopp "[[:digit:]]"; }
if(
$perceelopp == "0") { $perceelopp "[[:digit:]]"; }

$word1 explode(" ",$word); 
$operator "|"// Set regex operator to "|".

if($word)
{
 
$word "'"// Prepare $word for new string
 
for($i=0;$i<count($word1);$i++)
 {
  if(
$word1[$i] && $word1[$i] != ""
  {
   
$word .= $word1[$i].$operator;
   }
  }
 
$word substr($word,0,strlen($word)-1);
 
$word .= "'"// Add closing ' to $word

 
if($word == "'"){$word "' '";}
$result mysql_query("SELECT * FROM aanbod WHERE plaats RLIKE $word AND soort RLIKE '$soort' AND kamers RLIKE '$kamers' AND woonopp >= '$woonopp' AND perceelopp >= '$perceelopp' AND prijs BETWEEN '$prijsvan' AND '$prijstot' ORDER BY prio, id DESC") or die(mysql_error());

else

$result mysql_query("SELECT * FROM aanbod WHERE soort RLIKE '$soort' AND kamers RLIKE '$kamers' AND woonopp >= '$woonopp' AND perceelopp >= '$perceelopp' AND prijs BETWEEN '$prijsvan' AND '$prijstot' ORDER BY prio, id DESC"

 or die(
mysql_error());

when I leave everything blank except $plaats no result are shown..
you can see this at: http://www.kerkvlietmakelaars.nl/aanbod.php?src=adv
Reply With Quote
  #4 (permalink)  
Old 02-22-08, 07:48 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
can you show us what the query should look like, and what kind of data you are storing in the table?

It seems to me that you have created a query that can never select any data if you only fill in $plaats (probably some conditions that were set wrong). Try echo-ing the query, usually you automatically see what's wrong with it.
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #5 (permalink)  
Old 02-22-08, 07:56 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
did you checked the site?..

would it help when I echo all posted data?..


I think it goes wrong when $soort is set to [[:alnum:]]...
don't know if this can be used to select in a DB...

it would make:
PHP Code:

mysql_query("SELECT * FROM aanbod WHERE soort RLIKE '[[:alnum:]]'"); 

_j

Last edited by jonnekke; 02-22-08 at 07:59 AM.
Reply With Quote
  #6 (permalink)  
Old 02-22-08, 07:59 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
I just did

Just the query, and what a normal query should look like. Just add this above the mysql_query call:
PHP Code:

echo "SELECT * FROM aanbod WHERE plaats RLIKE $word AND soort RLIKE '$soort' AND kamers RLIKE '$kamers' AND woonopp >= '$woonopp' AND perceelopp >= '$perceelopp' AND prijs BETWEEN '$prijsvan' AND '$prijstot' ORDER BY prio, id DESC"
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #7 (permalink)  
Old 02-22-08, 08:07 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
I added the line of code..
Reply With Quote
  #8 (permalink)  
Old 02-22-08, 09:31 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by jonnekke View Post
I added the line of code..
Right. And then what happened? How many guesses do we get, and will you tell us if we're getting warm?
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #9 (permalink)  
Old 02-22-08, 09:35 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 706
Thanks: 0
Thanked 0 Times in 0 Posts
I did what UnrealEd asked me...
I added the line of code..

this is shown:
Code:
SELECT * FROM aanbod WHERE soort REGEXP '[[:alnum:]]' AND kamers REGEXP '[[:digit:]]' AND woonopp >= '[[:digit:]]' AND perceelopp >= '[[:digit:]]' AND prijs BETWEEN '0' AND '10000000000' ORDER BY prio, id DESC
it should select all DB entries in this case... because each var is "alnum" or "digit"..
but it doesn't work..
Reply With Quote
  #10 (permalink)  
Old 02-24-08, 11:37 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
After you finish a script, you need to test it. Usually testing a script results in a large amount of errors, or basic conceptual problems.
When a programmer faces these problems, he starts debugging: going over each line of code that might cause the problem. If he doesn't find it immediately, he strips the code untill the most elementary code is left. Then he tests again, if it works, he adds a small piece of the original code, and tests again. And so on, till all bugs are fixed and all code is up and running

At the moment you're facing a small problem: a query isn't fetching what it's supposed to do. So, going from what I just wrote: strip the query down to the most basic query:
SQL Code:
  1. SELECT * FROM aanbod
The query above will probably cause no problems at all, so add 1 WHERE clause:
SQL Code:
  1. SELECT * FROM aanbod WHERE soort REGEXP '[[:alnum:]]'
Test if this is working. If not, you found at least one of the problems in the query. If it is working, add another where clause. Keep repating this untill you solved all problems and the query returns exactly what you need.


Don't get me wrong: I do want to help you, but you have to make an effort yourself: if you're just going to ask "what's it/what am I doing wrong?", you won't learn anything from it
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

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
"cannot convert parameter" errors, when compiling torque 1.4 primalminds C/C++ 3 02-28-07 09:29 PM
.flv sound problem bpool_lee Flash & ActionScript 2 11-27-06 03:32 AM
login, roles problem dbrook007 ASP.NET 10 11-10-06 03:42 PM
date problem - convert eg. '06' to 'jun' tallpaul858 PHP 3 04-16-05 06:39 PM
Asp and Microsoft Access 2002 problem gop373 ASP 2 10-06-04 09:13 AM


All times are GMT -5. The time now is 07:37 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.