Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 01-23-2012, 02:39 PM   #1
acctman
Confirmed User
 
Join Date: Oct 2003
Location: Atlanta
Posts: 2,840
Mysql / php query question.

I'm collecting data from 3 tables, of which one of the tables (social_meminfo) has multiple rows for results. How can I isolate the results of social_meminfo identifying each rows results? Or should I use two separate queries? At there should be at least two rows that would be found. Also instead of using `$en['m'.$key]` I want to use `$en['b'.$key]`

Code:
        $res = mysql_query("SELECT *, DATE_FORMAT(sm.m_lld,'%m/%d/%y') 
                            AS m_lld_formatted 
                            FROM social_members sm
                            JOIN social_meminfo smi ON (sm.m_id = smi.m_id)
                            LEFT OUTER JOIN social_memtext smt ON (sm.m_id = smt.m_id)
                            WHERE sm.m_user = '".mysql_real_escape_string($en['user'])."'");            
        if (mysql_num_rows($res) == 0) call404();
    #while ($line = mysql_fetch_assoc($res)) {
        $line = mysql_fetch_assoc($res);
        foreach ($line as $key => $value) {
                $en['m'.$key] = str_replace("\n",'<br/>',stripslashes($value));
                }
or should I just use two queries and a while statement?
acctman is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-23-2012, 02:58 PM   #2
KickAssJesse
Confirmed User
 
KickAssJesse's Avatar
 
Industry Role:
Join Date: Jul 2008
Location: Los Angeles
Posts: 942
I believe you want to use the SELECT DISTINCT() and the GROUP BY clause.
__________________

Contact - email: jesse~AT~atkcash~DOT~com - Skype: kickassjesse - ICQ: 386185547
ATK Cash $$$
KickAssJesse is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-23-2012, 03:07 PM   #3
BestXXXPorn
Confirmed User
 
BestXXXPorn's Avatar
 
Join Date: Jun 2009
Location: Asheville, NC
Posts: 2,277
Also:

http://www.php.net/nl2br

__________________
ICQ: 258-202-811 | Email: eric{at}bestxxxporn.com
BestXXXPorn is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-23-2012, 10:11 PM   #4
acctman
Confirmed User
 
Join Date: Oct 2003
Location: Atlanta
Posts: 2,840
I decided to split the query... using the code below how can I get each row plus field result? (i.e. $line['m_pos'][0] or something like that. which would be fieldname and row result 1)

Code:
$bio = mysql_query("SELECT * FROM social_meminfo 
            WHERE m_id = '".mysql_real_escape_string($en['mm_id'])."'");
                             
if (mysql_num_rows($bio) == 0) call404();
while ($line = mysql_fetch_assoc($bio)) {
foreach ($line as $key => $value) {
        $en['b'.$key] = str_replace("\n",'<br/>',stripslashes($value));
        }
echo '<pre>'; 
    print_r($line);
echo '</pre>';
}
acctman is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-24-2012, 02:47 AM   #5
ewsmedia
Registered User
 
Industry Role:
Join Date: Jan 2012
Posts: 4
Best for rapid development is to use custom query functions like this

Code:
	function fetchAll($query = false, $key = false) {
		$fetch = false;

		if($query) {
			if($result = mQuery($query)) {
	    		while($res = mysql_fetch_assoc($result)) {

	    			if($key && $res[$key]) {
	    				$fetch[$res[$key]] = $res;
	    			} else {
	    				$fetch[] = $res;
	    			}
	    		}
	    	}
	    }

	    return $fetch;
	}
and than you can tune it all, you will not have your code doubled
ewsmedia is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-24-2012, 08:34 AM   #6
acctman
Confirmed User
 
Join Date: Oct 2003
Location: Atlanta
Posts: 2,840
Quote:
Originally Posted by ewsmedia View Post
Best for rapid development is to use custom query functions like this

Code:
	function fetchAll($query = false, $key = false) {
		$fetch = false;

		if($query) {
			if($result = mQuery($query)) {
	    		while($res = mysql_fetch_assoc($result)) {

	    			if($key && $res[$key]) {
	    				$fetch[$res[$key]] = $res;
	    			} else {
	    				$fetch[] = $res;
	    			}
	    		}
	    	}
	    }

	    return $fetch;
	}
and than you can tune it all, you will not have your code doubled
still running into the problem of not being able to separate the data by the outputting rows. everytime it does a loop it grabs another row or data. but I can't figure out how to designate a specific id or var for each row+field. if I have 5 rows of data I want to be able to say echo row:2 field: m_pos ... show data
acctman is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-24-2012, 08:52 AM   #7
EddyTheDog
Just Doing My Own Thing
 
EddyTheDog's Avatar
 
Industry Role:
Join Date: Jan 2011
Location: London, Spain, New Zealand, GFY - Not Croydon...
Posts: 25,034
Quote:
Originally Posted by acctman View Post
I'm collecting data from 3 tables, of which one of the tables (social_meminfo) has multiple rows for results. How can I isolate the results of social_meminfo identifying each rows results? Or should I use two separate queries? At there should be at least two rows that would be found. Also instead of using `$en['m'.$key]` I want to use `$en['b'.$key]`

Code:
        $res = mysql_query("SELECT *, DATE_FORMAT(sm.m_lld,'%m/%d/%y') 
                            AS m_lld_formatted 
                            FROM social_members sm
                            JOIN social_meminfo smi ON (sm.m_id = smi.m_id)
                            LEFT OUTER JOIN social_memtext smt ON (sm.m_id = smt.m_id)
                            WHERE sm.m_user = '".mysql_real_escape_string($en['user'])."'");            
        if (mysql_num_rows($res) == 0) call404();
    #while ($line = mysql_fetch_assoc($res)) {
        $line = mysql_fetch_assoc($res);
        foreach ($line as $key => $value) {
                $en['m'.$key] = str_replace("\n",'<br/>',stripslashes($value));
                }
or should I just use two queries and a while statement?
All that code gives me a headache, I am a relative novice at this stuff.

I know you are trying to refine and use best coding practice and all that stuff, but unless this is a job for someone else or for a site with MASSIVE traffic why worry so much?

Use 2 or more queries - any modern server could handle it...
__________________
-

Chaturbate Script - https://gfy.com/fucking-around-and-b...er-issues.html - Now supports White Labels
EddyTheDog is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-24-2012, 08:58 AM   #8
acctman
Confirmed User
 
Join Date: Oct 2003
Location: Atlanta
Posts: 2,840
Quote:
Originally Posted by EddyTheDog View Post
All that code gives me a headache, I am a relative novice at this stuff.

I know you are trying to refine and use best coding practice and all that stuff, but unless this is a job for someone else or for a site with MASSIVE traffic why worry so much?

Use 2 or more queries - any modern server could handle it...
I decided to just go with two queries in post #4 but I'm running into the problem of not knowing how to separate the outputting data by rows. I need to do something like $line['m_pos'][0] where 0 means row one. That way I can properly place the data where it needs be. As of right now $line['FIELD'] doesn't let me know when row it came from
acctman is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-24-2012, 10:23 AM   #9
Operator
So Fucking Banned
 
Industry Role:
Join Date: May 2009
Location: ΠπΠ
Posts: 2,419
Join Database platforms not tables.
Operator is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-24-2012, 11:04 AM   #10
acctman
Confirmed User
 
Join Date: Oct 2003
Location: Atlanta
Posts: 2,840
Quote:
Originally Posted by Operator View Post
Join Database platforms not tables.
explain...? I personally am not a big fan of joins cause they can slow a system down if used to much.

decided to go with two queries and solved my row issue with an increment. so everything is working.

Code:
$bio = mysql_query("SELECT * FROM social_meminfo 
            WHERE m_id = '".mysql_real_escape_string($en['mm_id'])."'");
$i = 1;
if (mysql_num_rows($bio) == 0) call404();
    while ($line = mysql_fetch_assoc($bio)) { 
        foreach ($line as $key => $value) {
        $en['b'.$key . $i] = str_replace("\n",'<br/>',stripslashes($value));
        }
    $i++;        
    }
acctman is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.