![]() |
![]() |
![]() |
||||
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. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
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)); } |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
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.
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Join Date: Jun 2009
Location: Asheville, NC
Posts: 2,277
|
__________________
ICQ: 258-202-811 | Email: eric{at}bestxxxporn.com |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
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>'; } |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
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; } ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 | |
Confirmed User
Join Date: Oct 2003
Location: Atlanta
Posts: 2,840
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 | |
Just Doing My Own Thing
Industry Role:
Join Date: Jan 2011
Location: London, Spain, New Zealand, GFY - Not Croydon...
Posts: 25,034
|
Quote:
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 |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 | |
Confirmed User
Join Date: Oct 2003
Location: Atlanta
Posts: 2,840
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
So Fucking Banned
Industry Role:
Join Date: May 2009
Location: ΠπΠ
Posts: 2,419
|
Join Database platforms not tables.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
Confirmed User
Join Date: Oct 2003
Location: Atlanta
Posts: 2,840
|
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++; } |
![]() |
![]() ![]() ![]() ![]() ![]() |