You need to use WHERE post_id = '3' OR post_id = '1' - what you have done is like saying WHERE '1' which is actually always going to return true so you get all records returned.
You can also use
WHERE post_id IN ('1', '3')
You need to use WHERE post_id = '3' OR post_id = '1' - what you have done is like saying WHERE '1' which is actually always going to return true so you get all records returned.
You can also use
WHERE post_id IN ('1', '3')
You can also use
WHERE post_id IN ('1', '3')
So, if I had a lot of values like: 1, 7, 245, 12, and 15 in an array like this I could format them and put them in a string and run the SQL?
foreach ($post_ids as $value) {
$fixed_post_ids = '\''. $value. '\', ';
}
$sql = 'SELECT * FROM `phpbb_posts_text` WHERE `post_id` IN ('. $fixed_post_ids. ') LIMIT 0, 200 ';
Is this the right way to do it?
Yeah you could do that but to build up the string you need to concatenate it - your foreach loop will just overwrite the $fixed_post_ids each time, so you'd need to use .=
Change
to
Alternatively you could use implode
$sql = 'SELECT * FROM `phpbb_posts_text` WHERE `post_id` IN ('. "'".$fixed_post_ids."'" .') LIMIT 0, 200 ';
Thanks for all of your help Nexonen! /biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" />
I finished (I think) the script. you can download it from:
http://learnphpfree.com/Unique Page - Show Forum Topics - Posts.zip
I am going to submit it to phpBB MODS now....
I am trying to select posts in MySQL from a phpBB forum.
The values I want to check are in a field called 'post_id'.
Eventualy, I want to get all posts that have a 'post_id' that matchs an array I will build.
// Performing SQL query
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
// Printing results in HTML
while ($row = mysql_fetch_assoc($result)) {
$post_subject = str_replace(' ', "-", $row["post_subject"]);
echo '<a href="'. $phpbb_root_path. $post_subject. '-vt6.html">'.$row["post_subject"]. '</a>';
}
You see, I made a custom page, and I am trying to turn the titles into links to the real forum topics. I have already been successful in printing out the links and them pointing to the forums. However, rather than JUST the posts that match the values '3' and '1' I also get post '2'. What is wrong with my SQL statement? And if anyone has experience in phpBB - am I doing it right? What if I have 200 topics is using the 'OR' command the right way to do it?
Any help would be appreciated
/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" />
God Bless.
Xeoncros - Code 2 Truth - Imrah - Code 2