Shoutbox

Help with MySQL queries - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Help with MySQL queries (/showthread.php?tid=65290)

Help with MySQL queries by absorbation on 08-23-2006 at 05:52 PM

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");

RE: Help with MySQL queries by Ezra on 08-23-2006 at 06:07 PM

W3Schools SQL Syntax


RE: Help with MySQL queries by RaceProUK on 08-24-2006 at 12:12 PM

$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");


RE: Help with MySQL queries by absorbation on 08-24-2006 at 12:14 PM

Great, thanks to both you guys, it really made some of my queries easier to write :)


RE: Help with MySQL queries by RaceProUK on 08-24-2006 at 02:27 PM

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.


RE: Help with MySQL queries by absorbation on 08-24-2006 at 03:21 PM

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";
}

RE: Help with MySQL queries by RaceProUK on 08-25-2006 at 10:11 AM

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.
RE: Help with MySQL queries by surfichris on 08-25-2006 at 10:22 AM

Nobody ever said it was a text field - stop assuming because he is using single quotes it means it is a text field.


RE: Help with MySQL queries by RaceProUK on 08-25-2006 at 10:46 AM

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.