Page 1 of 1
Show SOME text from a database
Posted: Wed Dec 08, 2010 2:59 pm
by jannik
Hi
when i write
it says:
Cat - Subcat
I only want it to show
Subcat
How do I do this codewise? So it ONLY shows what is in the database field AFTER the
-
sign.
Really hope that someone understands my bad english, and can help me.
Thanx in advance.
Jannik
Re: Show SOME text from a database
Posted: Wed Dec 08, 2010 3:10 pm
by McInfo
There are many was to do that. Which way is best depends on the expected inputs and outputs.
Here is one example.
Code: Select all
<?php
list ($cat, $sub) = explode(' - ', 'Cat - Subcat', 2);
var_dump($cat, $sub);
/*
string(3) "Cat"
string(6) "Subcat"
*/
Re: Show SOME text from a database
Posted: Wed Dec 08, 2010 3:24 pm
by jannik
Hmm dont think u understand what I need.... (my bad)
Perhaps this can help. Just found it by searching google...
opentable($locale['400'].": ".$cdata['download_cat_name'] = substring(download_cat_name, instr(download_cat_name, '-') + 1));
But it doesnt seem to work...
Dont know if I can add the "Substring" inside the Opentable function...
Can you see what i am doing wrong?
Re: Show SOME text from a database
Posted: Wed Dec 08, 2010 4:04 pm
by McInfo
You say you have a variable, $data['download_cat_name'], that holds a string. The string is something like "Fruit - Apple" where a category and subcategory are joined by the string " - ".
So,
Code: Select all
list ( , $data['download_cat_name']) = explode(' - ', $data['download_cat_name'], 2);
Does $data['download_cat_name'] not now hold just the subcategory?
Re: Show SOME text from a database
Posted: Wed Dec 08, 2010 4:34 pm
by jannik
My code now looks like this
Code: Select all
echo "<a href='downloads.php?cat_id=".$data['download_cat_id']."'>".$strip = strstr($data['download_cat_name'], '-')."</a>";
It works but it still shows the "- " in front. do you know hos to remove those two in this code???
If not I will then try your code tomorrow, will go to sleep now
Thanx in advance.

Re: Show SOME text from a database
Posted: Wed Dec 08, 2010 4:46 pm
by McInfo
Re: Show SOME text from a database
Posted: Wed Dec 22, 2010 7:42 am
by jannik
Hi. Could someone please help me with the code
I simply can't add the ltrim or trim function.... Pulling my hair off
Could someone please add the trim code to the above code of mine, so that "- " is being removed from the beginning.
Regards
Jannik