Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing dta from 2 tables in 1 page.

Status
Not open for further replies.

jeellison

IS-IT--Management
May 29, 2002
78
GB
Hello All,

I have two pages which each display data from 2 different tables. Table projects on 1 page and users on the other. Now id like data from them both on the same page. Below is the code from each page.

This is the User page :

include "./init.php";
$sscript = "";

if($user['user_acct_status'] == "V")
redirect("./validate.php");

$title = "Browsing all user profiles";
$cat_name = "";

add_to_online("Browsing all user profile","$root_path/browse_users.php");

$ipp = 20;

$rt = mysql_query("SELECT COUNT(*) as total FROM {$prefix}users WHERE user_acct_status='A'") or report();
$ta = mysql_fetch_assoc($rt);

if($ta["total"]==0) {
$list_data = "<center><font color=555555><b>No users found !</b></font></center>";
$pagination = "";
$total_res = "";
}

else {

$ta['total'] = $ta['total']-1;

if(!isset($_GET['start']))
$_GET['start'] = 1;

if($settings['set_seo_onoff']=='off') {
$start=1;
if(isset($_GET['start']))
$start=_html(intval($_GET['start']));
}

$cpage = $start;
$start = ($start * $ipp) - $ipp;

$pages = "";
if($ta['total'] > $ipp) {

$next = "";
$prev = "";

$pages = "<table cellspacing='5' cellpadding='0'>
<tr>";
$total_pages = ceil($ta['total'] / $ipp)+1;

$mystart = $start+1;

// lets make the next and previous buttons
if(($mystart == 1) && ($total_pages>1)) {

$next = "<td width=10 stlye='cellpadding:5'><div align=center class=\"myPagePN\"><a href='$root_path/browse_users.php?start=".intval($_GET['start']+1)."'>Next ></a></div></td>";
$prev = "";

} else
if(($mystart == 1) && ($total_pages == 1)) {

$next = "";
$prev = "";

} else
if($mystart > ($total_pages+1)){

$next = "";
$prev = "<td width=10 stlye='cellpadding:5'><div align=center class=\"myPagePN\"><a href='$root_path/browse_users.php?start=".intval($_GET['start']-1)."'>< Prev</a></div></td>";

} else {
$next = "<td width=10 stlye='cellpadding:5'><div align=center class=\"myPagePN\"><a href='$root_path/browse_users.php?start=".intval($_GET['start']+1)."'>Next ></a></div></td>";
$prev = "<td width=10 stlye='cellpadding:5'><div align=center class=\"myPagePN\"><a href='$root_path/browse_users.php?start=".intval($_GET['start']-1)."'>< Prev</a></div></td>";
}

$pages .= $prev;

for($i=1; $i<$total_pages; $i++) {

if($cpage == $i)
$pages .= "<td width=10 align=center stlye='cellpadding:5'><div align=center class=\"myPageSelected\"><b>$i</b></div></td>";

else {
$pages .= $settings['set_seo_onoff']=='on'

? " <td width=10 stlye='cellpadding:5'><div align=center class=\"myPage\"><a href='$root_path/browse_users/".plaintext("$i")."-$i.html'>$i</a></div></td>"
: " <td width=10 stlye='cellpadding:5'><div align=center class=\"myPage\"><a href='./browse_users.php?start=$i'>$i</a></div></td>";
}
}

$pages .= "$next</tr></table>";

}

$fres = mysql_query("SELECT * FROM {$prefix}users usr, {$prefix}groups gr WHERE usr.user_acct_status='A' AND gr.group_id=usr.user_group_id ORDER by usr.user_id DESC LIMIT $start,$ipp;")
or report("fetch all games : ");

if(mysql_num_rows($fres)==0)
$list_data = "<table width=100% align=center><tr><td><b>No users found !.</b><br><br></td></tr></table>";

else {

$list_data = "
<table width='100%' border='0' cellspacing='1' cellpadding='6'>
<tr bgcolor='$table_top_color'>
<td width='35%'><b>Username and Details</b></td>
<td width='5%'>
<div align='center'><b>Feedback</b></div>
</td>
<td width='9%'>
<div align='center'><b>Join Date</b></div>
</td>
</tr>";

while($f_art_row=mysql_fetch_assoc($fres)) {

if($f_art_row['user_id'] == 1) {

$list_data .="<tr bgcolor=$bg_color2>
</tr>";

} else {

if($f_art_row['user_certified'] == "Y")
$certified = "<img src='./images/certified.gif' valign=baseline border=0>";
else $certified = "";


$profile_url = $settings['set_seo_onoff'] =='on'
? "$root_path/profile/".plaintext($f_art_row['user_name'])."-$f_art_row[user_id].html"
: "$root_path/profile.php?id=$f_art_row[user_id]";

$feedback = get_feedback($f_art_row['user_id'],"");
$jdate = date($date_format, $f_art_row['user_join_date']);

$list_data .= "
<tr bgcolor=$bg_color2>
<td style='padding:0px'>

<div class=\"myProject\">
<a href=\"./profile.php?id=$f_art_row[user_id]\" title=\"$f_art_row[user_name]\">

<span class='projectTitle'>$f_art_row[user_name] $certified</span>
<span class=smalltext><b>Group :</b> $f_art_row[group_name]. <b>City :</b> $f_art_row[user_city]</span>
</a>
</div>

</td>
<td bgcolor='#F6F6EC'>
<div align='center'>$feedback</div>
</td>
<td bgcolor='#F6F6EC'>
<div align='center'>$jdate</div>
</td>
</tr>";
}
}

$list_data .= "</table>";
}

$total_res = "
<div align='right'>$pages</div>";

$pagination = $pages;

}

$temp = template("./templates/browse_users");
eval("\$right = \"$temp\";");

$latest_projects_header = get_project_titles(4);
$categories = list_categories(15);

$temp = template("./templates/overall_header");
eval("\$overall_header = \"$temp\";");

$temp = template("./templates/overall_footer");
eval("\$overall_footer = \"$temp\";");

$temp = template("./templates/header");
eval("\$header = \"$temp\";");

if($user){

$temp = template("./templates/left_provider");
eval("\$login_data = \"$temp\";");

} else {
$temp = template("./templates/left_login");
eval("\$login_data = \"$temp\";");
}

$temp = template("./templates/left");
eval("\$left = \"$temp\";");

$temp = template("./templates/footer");
eval("\$footer = \"$temp\";");

$temp = template("./templates/main");
eval("\$main = \"$temp\";");

echo $main;
cdie();

?>



And this is the project page : Please see it is here I am wanting the City field from the users table to be displayed along with the other data but no matter what I try it will not work.




include "./init.php";
$sscript = "";

if($user['user_acct_status'] == "V")
redirect("./validate.php");

$title = "Browsing all projects";
$cat_name = "";

add_to_online("Browsing all projects","$root_path/browse_projects.php");

$ipp = $settings['set_projects_per_page']; // projects per page


$rt = mysql_query("SELECT COUNT(*) as total FROM {$prefix}projects WHERE project_status='O'") or report();
$ta = mysql_fetch_assoc($rt);

if($ta["total"]==0) {
$list_data = "<center><font color=555555><b>No projects found !</b></font></center>";
$pagination = "";
$total_res = "";
}

else {

if(!isset($_GET['start']))
$_GET['start'] = 1;

if($settings['set_seo_onoff']=='off') {
$start=1;
if(isset($_GET['start']))
$start=_html(intval($_GET['start']));
}

$cpage = $start;
$start = ($start * $ipp) - $ipp;

$pages = "";
if($ta['total'] > $ipp) {

$next = "";
$prev = "";

$pages = "<table cellspacing='5' cellpadding='0'>
<tr>";
$total_pages = ceil($ta['total'] / $ipp)+1;

$mystart = $start+1;

//$rt = mysql_query("SELECT COUNT(*) as total FROM {$prefix}users WHERE user_acct_status='A'") or report();

// lets make the next and previous buttons
if(($mystart == 1) && ($total_pages>1)) {

$next = "<td width=10 stlye='cellpadding:5'><div align=center class=\"myPagePN\"><a href='$root_path/browse_projects.php?start=".intval($_GET['start']+1)."'>Next ></a></div></td>";
$prev = "";

} else
if(($mystart == 1) && ($total_pages == 1)) {

$next = "";
$prev = "";

} else
if($mystart > ($total_pages+1)){

$next = "";
$prev = "<td width=10 stlye='cellpadding:5'><div align=center class=\"myPagePN\"><a href='$root_path/browse_projects.php?start=".intval($_GET['start']-1)."'>< Prev</a></div></td>";

} else {
$next = "<td width=10 stlye='cellpadding:5'><div align=center class=\"myPagePN\"><a href='$root_path/browse_projects.php?start=".intval($_GET['start']+1)."'>Next ></a></div></td>";
$prev = "<td width=10 stlye='cellpadding:5'><div align=center class=\"myPagePN\"><a href='$root_path/browse_projects.php?start=".intval($_GET['start']-1)."'>< Prev</a></div></td>";
}

$pages .= $prev;

for($i=1; $i<$total_pages; $i++) {

if($cpage == $i)
$pages .= "<td width=10 align=center stlye='cellpadding:5'><div align=center class=\"myPageSelected\"><b>$i</b></div></td>";

else {
$pages .= $settings['set_seo_onoff']=='on'

? " <td width=10 stlye='cellpadding:5'><div align=center class=\"myPage\"><a href='$root_path/browse_projects/".plaintext("$i")."-$i.html'>$i</a></div></td>"
: " <td width=10 stlye='cellpadding:5'><div align=center class=\"myPage\"><a href='./browse_projects.php?start=$i'>$i</a></div></td>";
}
}

$pages .= "$next</tr></table>";

}

$fres = mysql_query("SELECT * FROM {$prefix}projects WHERE project_status='O' ORDER by project_id DESC LIMIT $start,$ipp;")
or report("fetch all games : ");

if(mysql_num_rows($fres)==0)
$list_data = "<table width=100% align=center><tr><td><b>No project found !.</b><br><br></td></tr></table>";

else {

$list_data = "
<table width='100%' border='0' cellspacing='1' cellpadding='6'>
<tr bgcolor='$table_top_color'>
<td width='35%'><b>These are our latest Projects - Are you a Tradesman? Sign up now to bid on these jobs</b></td>
<td width='5%'>
<div align='center'><b>Bids</b></div>
</td>
<td width='7%'>
<div align='center'><b>Avg Bid</b></div>
</td>
</tr>";

while($f_art_row=mysql_fetch_assoc($fres)) {

if($f_art_row['project_featured'] == "Y")
$featured = "<img src='./images/featured.gif' valign=baseline border=0>";
else $featured = "";

if($f_art_row['project_urgent'] == "Y")
$urgent = "<img src='./images/urgent.gif' valign=baseline border=0>";
else $urgent = "";

$bids = get_total_bids($f_art_row['project_id']);
$avg_bid = get_avg_bid($f_art_row['project_id']);

$f_art_row['project_cat_names'] = str_replace("^^^"," - ",$f_art_row['project_cat_names']);


$project_url = $settings['set_seo_onoff'] =='on'
? "$root_path/project/".plaintext($f_art_row['project_title'])."-$f_art_row[project_id].html"
: "$root_path/projects.php?id=$f_art_row[project_id]";

$list_data .= "
<tr bgcolor=$bg_color2>
<td style='padding:0px'>

<div class=\"myProject\">
<a href=\"./project.php?id=$f_art_row[project_id]\" title=\"$f_art_row[project_title]\">

<span class='projectTitle'>$f_art_row[project_title] $urgent$featured</span>
<span class=smalltext><b>Category :</b> $f_art_row[project_cat_names].<b> City :</b> $f_art_row[user_city]</span>
</a>
</div>

</td>
<td bgcolor='#F6F6EC'>
<div align='center'>$bids</div>
</td>
<td bgcolor='#F6F6EC'>
<div align='right'>&pound;$avg_bid</div>
</td>
</tr>";
}

$list_data .= "</table>";
}

$total_res = "
<div align='right'>$pages</div>";

$pagination = $pages;

}

$temp = template("./templates/browse_projects");
eval("\$right = \"$temp\";");

$latest_projects_header = get_project_titles(4);
$categories = list_categories(15);

$temp = template("./templates/overall_header");
eval("\$overall_header = \"$temp\";");

$temp = template("./templates/overall_footer");
eval("\$overall_footer = \"$temp\";");

$temp = template("./templates/header");
eval("\$header = \"$temp\";");

if($user){

$temp = template("./templates/left_provider");
eval("\$login_data = \"$temp\";");

} else {
$temp = template("./templates/left_login");
eval("\$login_data = \"$temp\";");
}

$temp = template("./templates/left");
eval("\$left = \"$temp\";");

$temp = template("./templates/footer");
eval("\$footer = \"$temp\";");

$temp = template("./templates/main");
eval("\$main = \"$temp\";");

echo $main;
cdie();

?>

Im hoping this is simple but everything I have tried is not working.

Any advice on this would be greattly appreciated.

Best Regards
James
 
This appears to be in the wrong forum. Do you have a problem with your t-sql code? Ask this in the forum for whatever language you are calling the pages from.

"NOTHING is more important in a database than integrity." ESquared
 
I think you would get better answers if you ask your question in PHP forum.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top