Jump to content

seperate mysql table data by common username


calmchess

Recommended Posts

I need to select data from  3 tables that all have usename as the common data......now after selecting the data i need to arrange it so that all the users relevant data from the 3 tables  is in a table or array or somthing........starts out something like this

 


<?php
$conn = mysql_connect("127.0.0.1", "root", "secret") or die(mysql_error());
mysql_select_db("testsuite",$conn) or die(mysql_error());
////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////// 
$result0=mysql_query("select id,name from mprofiles") 
or die(mysql_error());
$row0 = mysql_fetch_array( $result0 );
$current0 = $row0['name'];
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
$result1=mysql_query("select country from members") 
or die(mysql_error());
$row1 = mysql_fetch_array( $result1 );
$current1 = $row1['country'];
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
$result2=mysql_query("select cpm from vfcp_profile") 
or die(mysql_error());
$row2 = mysql_fetch_array( $result2 );
$current2 = $row2['cpm'];
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
echo $current0;
echo $current1;
echo $current2;
?>

use INNER JOIN

 

$sql = "SELECT a.id, a.file, a.task,  b.id, b.file, b.task  FROM pf_table a INNER JOIN pf_table1 b ON (a.id = b.id) OR (a.fie = b.file) WHERE (b.file='".$file."' OR b.id='".$id."')  GROUP BY 1,2 ORDER BY $something DESC"; 

 

Somthing like this. You can join multiple tables by grouping them like this.

 

Cheers! ;)

here is what i ended up doing if anybody intrested

 

 


<?php

require_once("inc/pull.lib.php");
include_once("inc/layout.lib.php");
//include_once("templates/_default/profile.php");
?>
<style type="text/css"><!-- 
.center{text-align:center;width:105px;height:150px;}
-->
</style>
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="<?=$color_tab_bk?>">
  <tr bgcolor="#f0f0f0" valign="top" class='tr1'>
    <td bgcolor="<?=$color_tab_bk?>"><font color='<?=$color_head?>'><b><?=l1("Start Private Chatting With Hot Sexy Models Now!!")?></b></font></td>
  </tr>
  <tr bgcolor="#f0f0f0" valign="top" class='tr1'>
    <td bgcolor="<?=$color_light_bk?>">
<?php

$results_per_row=3;
$results_per_page=15;
echo layout_tab_start();$n=0;	
$r=qs("id,name from mprofiles where p1=1 and pics>0 and approved=1 order by online desc limit 0, $results_per_page");
$ss=qs("country from members ");
$sss=qs("Username,cpm from vfcp_profile");

$temp_array0 = array();
/*	
//country needs username as key to pair this up with $temp_array2 which will put the data in the proper place.
if (!e($ss))while($pp=f($ss) ) {
array_push($temp_array0, $pp[country]);

}
*/
$temp_array1 = array();
$temp_array2 = array();

if (!e($r)) while ($p=f($r)) 
{
//id and name match within their arrays so using username as a key here isn't necessary.
array_push($temp_array1, $p[id]);
array_push($temp_array2, $p[name]);

}

$temp_array3 = array();
$i=0;
if (!e($sss)) while ($ppp=f($sss)) 
{

//temp_array3 uses the username as its key then is matched up with $temp_array2 see line 68
$temp_array3[$ppp[username]]=$ppp[cpm];
}


for($i=0;$i<count($temp_array1);$i++){	
echo_tab_cell_start($n,$results_per_row);
show_snap_only($temp_array1[$i]);
  
?>


<div class ="center">	<span><?php echo $temp_array2[$i]?></span><br />
  <a href="profile.php?profile_id=<?=$temp_array1[$i]?>&s_e=<?=($s_e)?>&s_r=<?=($s_r)?>&s_p=1&s_s=<?=(!$s_s)?>&s_f=<?=($s_f)?>&s_c=<?=($s_c)?>&s_b=<?=($s_b)?>&profile_name=<?=urlencode($temp_array2[$i])?>"><strong>
	    <?=l1("More Photos")?></a><!--<br /> <span>Country:--><?php// echo $rev1[$i+3];?><!--</span>--><br />
	    <!-- $temp_array3 has the user's name as a key value that key value is matched to $temp_array2[$i] which contains the users cost per minute(def = $3.99) -->
		Private :$<?php if($temp_array3[$temp_array2[$i]]!=null){echo $temp_array3[$temp_array2[$i]];}else{echo "3.99";}?></div>

<?php
echo_tab_cell_end($n,$results_per_row);

}
echo layout_tab_end($n,$results_per_row);
asfdasdfasdfsdf
?></td>
  </tr>

  <tr bgcolor="#f0f0f0" valign="top" class='tr1'>
    <td align="right" bgcolor="<?=$color_tab_bkg?>"><a href="view_snaps.php?type=1">
      <?=l1("More")?>
    <img src="<?=t1i("icons16/page_right", "interface/arw3.gif")?>" border="0" align="absmiddle" />    </a></td>
  </tr>
  <tr bgcolor="#f0f0f0" valign="top" class='tr1'>
    <td align="right" bgcolor="<?=$color_tab_bkg?>"><div align="center"><img src="templates/<?=$template?>/layout/joinimage.jpg" width="520" height="100" border="0" usemap="#Map" />
        <map name="Map" id="Map">
          <area shape="rect" coords="5,62,177,95" href="http://www.eazygirls4u.com/models.php" target="_blank" title="Click Here To Become Webcam Model" />
          <area shape="rect" coords="349,65,513,94" href="http://www.eazygirls4u.com/studio.php" target="_blank" title="Become A Webcam Studio Now! Click Here" />
          </map>
    </div></td>
  </tr>
</table>


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.