What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Help with MySQL queries

Help with MySQL queries
Author: Message:
absorbation
Elite Member
*****

Avatar

Posts: 3636
Reputation: 81
– / Male / Flag
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
Profile PM Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
RE: Help with MySQL queries
W3Schools SQL Syntax
[Image: 1-0.png]
             
08-23-2006 06:07 PM
Profile PM Web Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
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");
[Image: spartaafk.png]
08-24-2006 12:12 PM
Profile PM Web Find Quote Report
absorbation
Elite Member
*****

Avatar

Posts: 3636
Reputation: 81
– / Male / Flag
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
Profile PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
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.
[Image: spartaafk.png]
08-24-2006 02:27 PM
Profile PM Web Find Quote Report
absorbation
Elite Member
*****

Avatar

Posts: 3636
Reputation: 81
– / Male / Flag
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 :P:

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
Profile PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
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.
[Image: spartaafk.png]
08-25-2006 10:11 AM
Profile PM Web Find Quote Report
surfichris
Former Admin
*****

Avatar

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
Profile PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
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.
[Image: spartaafk.png]
08-25-2006 10:46 AM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On