Help with MySQL queries |
Author: |
Message: |
absorbation
Elite Member
Posts: 3636 Reputation: 81
– / /
Joined: Feb 2005
|
O.P. Help with MySQL queries
OK, I use MySQL databases for everything when I use PHP, I never used .txt files and it is so easy to understand and learn. However, I really am limited on the actual syntax (not the PHP functions for it).
Below is an awful query and I want to know an easier and shorter way to do this query. Thank you
quote: $result = mysql_query("select * from posts where fid='2' or fid='8' or fid='4' or fid='5' or fid='6' or fid='9' or fid='22' or fid='24' or fid='14' or fid='23' or fid='11' or fid='12' or fid='13' order by dateline desc limit 5");
|
|
08-23-2006 05:52 PM |
|
|
Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
Joined: Mar 2003
|
RE: Help with MySQL queries
|
|
08-23-2006 06:07 PM |
|
|
RaceProUK
Elite Member
Posts: 6073 Reputation: 57
39 / /
Joined: Oct 2003
|
RE: Help with MySQL queries
$result = mysql_query("select *from posts where fid in ('2','8','4','5','6','9','22','24','14','23','11','12','13') order by dateline desc limit 5");
|
|
08-24-2006 12:12 PM |
|
|
absorbation
Elite Member
Posts: 3636 Reputation: 81
– / /
Joined: Feb 2005
|
O.P. RE: Help with MySQL queries
Great, thanks to both you guys, it really made some of my queries easier to write
|
|
08-24-2006 12:14 PM |
|
|
RaceProUK
Elite Member
Posts: 6073 Reputation: 57
39 / /
Joined: Oct 2003
|
RE: Help with MySQL queries
Actually, quick question: why is fid a text field when you're storing numbers in it?
I also recommend using capitals for all keyworks, like:
SELECT * FROM posts WHERE fid IN ('2','8','4','5','6','9','22','24','14','23','11','12','13') ORDER BY dateline DESC LIMIT 5
The SQL stands out from the data then.
|
|
08-24-2006 02:27 PM |
|
|
absorbation
Elite Member
Posts: 3636 Reputation: 81
– / /
Joined: Feb 2005
|
O.P. RE: Help with MySQL queries
quote: Originally posted by RaceProUK
Actually, quick question: why is fid a text field when you're storing numbers in it?
I'm not, it's in MyBB post's table, I'm taking the id from it to show the latest posts on my forums. Some forums are hidden so I'm using all those numbers to display the forum ids I want. I then process the data like this :
code: $result = mysql_query("select *from posts where fid in ('2','8','4','5','6','9','22','24','14','23','11','12','13') order by dateline desc limit 5");
while($r = mysql_fetch_array($result))
{
$pid = $r['pid'];
$tid = $r['tid'];
$subject = $r['subject'];
echo "<a href=\"http://forum.msgstuff.com/showthread.php?tid=$tid&pid=$pid\" target=\"_blank\">$subject</a>\n";
}
|
|
08-24-2006 03:21 PM |
|
|
RaceProUK
Elite Member
Posts: 6073 Reputation: 57
39 / /
Joined: Oct 2003
|
RE: Help with MySQL queries
quote: Originally posted by absorbation
quote: Originally posted by RaceProUK
Actually, quick question: why is fid a text field when you're storing numbers in it?
I'm not, it's in MyBB post's table
In that case: Why is fid a text field when MyBB stores numbers in it? It just doesn't make sense to me.
This post was edited on 08-25-2006 at 10:11 AM by RaceProUK.
|
|
08-25-2006 10:11 AM |
|
|
surfichris
Former Admin
Posts: 2365 Reputation: 81
Joined: Mar 2002
|
RE: Help with MySQL queries
Nobody ever said it was a text field - stop assuming because he is using single quotes it means it is a text field.
|
|
08-25-2006 10:22 AM |
|
|
RaceProUK
Elite Member
Posts: 6073 Reputation: 57
39 / /
Joined: Oct 2003
|
RE: Help with MySQL queries
quote: Originally posted by Chris Boulton
Nobody ever said it was a text field - stop assuming because he is using single quotes it means it is a text field.
Well, sorry if I offended you by assume that using text strings means comparing strings. It's not as if I said the whole thing was shit because it looks like a text field. All I said was it doesn't make sense to me.
After all, it was just a question out of interest.
This post was edited on 08-25-2006 at 10:47 AM by RaceProUK.
|
|
08-25-2006 10:46 AM |
|
|
|