View Full Version : Seperate a value
mokujin
07-16-2008, 08:38 PM
Hi, can you help me with seperating?
I have ex. this script:
// Get details
$sql = $vbulletin->db->query_read("
SELECT field1
FROM " . TABLE_PREFIX . "mytable AS mytable
");
if field1 has 2 words is seperating with a comma
ex. "word 1, word2",
How can I show for each word in template with <a href="myfile.php?do=word 1">word 1</a>, <a href="myfile.php?do=word2">word2</a>
Sorry for my bad English, I cant say better :mad:
Opserty
07-16-2008, 08:46 PM
$query = $vbulletin->db->query_read("
SELECT field1
FROM " . TABLE_PREFIX . "mytable
");
while($row = $vbulletin->db->fetch_array($query))
{
$words = explode(',', $row['field1']);
foreach($words as $word)
{
echo '<a href="myfile.php?do='. htmlspecialchars_uni($word) .'">'. htmlspecialchars_uni($word) .'</a>';
}
}
mokujin
07-16-2008, 08:54 PM
Oh thank you for your replying, but I need it in template. If I use your code it shows in top of the page :(
RLShare
07-17-2008, 03:08 AM
You have to put the php code in a plugin that hooks at the proper location.
Opserty
07-17-2008, 08:34 AM
Change echo
To:
$somevarx .=
Then use $somevarx in your template.
mokujin
09-27-2008, 08:16 PM
Hi again,
I have now another problem with seperating (using foreach function)
If I have SELECTED 3 rows from Database.
From second and third row they will repeat what previous row has.
Something like this:
Row 1: mytext, text
Row 2: thisis, thetext
Row 3: someword, my word
Then in template shows:
1: mytext, text
2: mytext, text, thisis, thetext
3: mytext, text, thisis, thetext, someword, my word
I think you will understand what I mean, thanks for helping me :(
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.