TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

June 17, 2024, 04:54:38 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,253
  • Total Topics: 21,225
  • Online today: 149
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 110
  • Total: 110

Database Queries

Started by DistantJ, October 19, 2010, 10:21:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DistantJ

Hi,

I'm having trouble getting any database queries to work in blocks...

I've been using this method:

$query = db_query(
    "SELECT id, subject, intro
     FROM {$db_prefix}tp_articles
     WHERE approved=1 AND off=0
     ORDER BY date DESC
     LIMIT 10", __FILE__, __LINE__) or die(mysql_error());


And every time it breaks the site (the "or die(mysql_error())" part is in there to ensure it's in that piece of code where the problem is - if the problem is elsewhere the data just doesn't show up, if it's in there the mysql_error will stop the rest of the site from loading, which proves to me that there's something wrong with that code).

So, erm... Am I missing something? Has something been changed since TP was updated? Or is there something going horribly wrong at my server? I've tried to use a few of the block codes on here and even create my own (I've been working on creating an RSS feed plugin to share on here for people to use etc.) but for some reason I can't seem to get it to connect with the database.

IchBin

If you could provide that info on the post page that we asked for it really helps us to answer questions more quickly. Depending on what version of SMF you're using the db_query() functions are different. However, you can change db_query() to be tpdb_query(). This should work on both SMF versions until Bloc decides to update the way he uses database queries. :)

DistantJ

Wow, that quick change and it worked straight away! Thanks IchBin.

Sorry, I forgot to provide the info. I'm assuming we don't need it now since that function worked fine (I'm using SMF2.0 RC3)

ZarPrime

Yeah, we don't need it now but it's always good to include the information requested in the Posting Guidelines when first posting a new Support topic.  It helps us to help you faster because we don't have to ask you for that info if you've included it right at the beginning.

I will mark this topic solved. O0

ZarPrime