This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-06-19 01:00:58

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Help with PHP/SQL?

As good as everyone thinks I am at PHP, I'm not that good as SQL.

Could someone please help me turn the group of SQL queries grouped with PHP into a single query?

Here is the code:

Code:

function check_read_forum($fid) {
    global $db, $forum_user;
    if ($forum_user['is_guest']) {
        return false;
    }
    $result = $db->query('SELECT id FROM ' . $db->prefix . 'topics
    WHERE forum_id=' . $fid) or error_msg('Could not check for unread messages - part 1');
    while ($topic = $db->fetch_assoc($result)) {
        $r2 = $db->query('SELECT 1 FROM ' . $db->prefix . 'read
        WHERE topic_id=' . $topic['id'] . ' AND user_id=' . $forum_user['id']) or error_msg('Could not check unread messages - part 2');
        if (!$db->num_rows($r2)) {
            return true;
        }
    }
}

http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#2 2012-06-20 01:13:42

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: Help with PHP/SQL?

Bump  sad
I need help!


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#3 2012-06-20 08:25:47

SJRCS_011
Scratcher
Registered: 2011-02-07
Posts: 1000+

Re: Help with PHP/SQL?

jvvg wrote:

Bump  sad
I need help!

What's wrong with the current one?
it seems like it would work fine
But couldn't you just do

Code:

SELECT * FROM  ' . $db->prefix . 'topics WHERE forum_id = '.$fid

Then just pick and choose which parts you want to use?


http://i.imgur.com/vQqtH.png
Learning to Program in a Nutshell:  "You're missing a closing parentheses" - LS97

Offline

 

#4 2012-06-20 10:39:15

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: Help with PHP/SQL?

So your trying to use OOP and PDO?


http://i.imgur.com/zeIZW.png

Offline

 

#5 2012-06-20 12:01:20

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: Help with PHP/SQL?

rookwood101 wrote:

So your trying to use OOP and PDO?

The OOP is database abstraction. What's PDO?

@SJRCS_011: That won't work.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#6 2012-06-20 22:12:31

SJRCS_011
Scratcher
Registered: 2011-02-07
Posts: 1000+

Re: Help with PHP/SQL?

jvvg wrote:

rookwood101 wrote:

So your trying to use OOP and PDO?

The OOP is database abstraction. What's PDO?

@SJRCS_011: That won't work.

ok, it was just expermiental


http://i.imgur.com/vQqtH.png
Learning to Program in a Nutshell:  "You're missing a closing parentheses" - LS97

Offline

 

#7 2012-06-20 22:21:30

GP1
Scratcher
Registered: 2009-07-06
Posts: 1000+

Re: Help with PHP/SQL?

You want multiple querys in a single call, right?
If you are using the mysql functions, then it wont work. Mysqli functions, however, do have a method that allows you to do multiple querys at the same time. I never use mysqli because mysql functions do the job just fine for me. I only do single querys  wink


I am currently http://blocks.scratchr.org/API.php?user=GP1&action=onlineStatus&type=imagehttp://blocks.scratchr.org/API.php?user=GP1&action=onlineStatus&type=text and I finally got over 1000 posts.

Offline

 

#8 2012-06-21 01:03:17

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: Help with PHP/SQL?

Let me put it this way:

I am writing a program to check for unread messages in a forum.
What I do is I have a table that shows read topics (user ID and topic ID).

I need code to check if the forum has any unread messages.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

Board footer