Jump to content

[SOLVED] Results not being shown


cs1h

Recommended Posts

Hi,

 

I have a function that is designed to show the two latest posts that a user has made. It gets the information from several tables, it gets the first set of information (what I have called the "base info" in the code) but not the rest of the data from the other tables doesn't show.

 

It's not showing any errors. The code is

 

<?php function twoLatestPosts($db_user, $db_pass, $db_database, $code_1_user){

mysql_connect("localhost", "$db_user", "$db_pass") or die(mysql_error()) ; 
mysql_select_db("$db_database") or die(mysql_error()) ;

//Get base info 

$result = mysql_db_query($db_database, "select * from article_thread WHERE code_1_user = '$code_1_user' LIMIT 2") or  die (mysql_error()); 

$num_rows = mysql_num_rows($result);
if($num_rows == 0) {
echo "";
} else {
while($row = mysql_fetch_array($result)) {
$id=$row["id"];
   	$title=$row["title"];
   	$country_ID=$row["country_ID"];
   	$abstract=$row["abstract"];
$town=$row["town"];
   	$added=$row["added"];
   	$version=$row["version"];
   	$code_1_article=$row["$code_1_article"];
   	$sub_cat=$row["sub_cat"];
   	
// Get star rating

$result2 = mysql_db_query($db_database, "select * from article_comments WHERE code_1_article = '$code_1_article'") or  die (mysql_error()); 

$num_rows2 = mysql_num_rows($result2);
if($num_rows2 == 0) {
$rating= "0";
} else {
while($row2 = mysql_fetch_array($result2)) {
$rating=round($row2["AVG(rating_number)"],0);

}
}

// Get country data

$result3 = mysql_db_query($db_database, "select * from country_sectors WHERE country_ID = '$country_ID'") or  die (mysql_error()); 

$num_rows3 = mysql_num_rows($result3);
if($num_rows3 == 0) {
echo "";
} else {
while($row3 = mysql_fetch_array($result3)) {
$country_Name=$row["country_Name"];

}
}

$result4 = mysql_db_query($db_database, "select * from country_list WHERE country = '$country_Name'") or  die (mysql_error()); 

$num_rows4 = mysql_num_rows($result4);
if($num_rows4 == 0) {
echo "";
} else {
while($row4 = mysql_fetch_array($result4)) {
$country_alias=$row["alias"];

}
}


// Get category data

$sub_cat_b = numberRemover($sub_cat);

$result5 = mysql_db_query($db_database, "select * from category_sectors WHERE category_ID = '$sub_cat_b'") or  die (mysql_error()); 

$num_rows5 = mysql_num_rows($result5);
if($num_rows5 == 0) {
echo "no name";
} else {
while($row5 = mysql_fetch_array($result5)) {
$category_Name=$row["category_Name"];

}
}

$result6 = mysql_db_query($db_database, "select * from sub_category_sectors WHERE sub_category_ID = '$sub_cat'") or  die (mysql_error()); 

$num_rows6 = mysql_num_rows($result6);
if($num_rows6 == 0) {
echo "no cat name";
} else {
while($row6 = mysql_fetch_array($result6)) {
$sub_category_Name=$row["sub_category_Name"];
$sub_category_Name = str_replace("_", " ", $sub_category_Name);

}
}

// Work out version info

if($version == draft){
   	$draftOrNot = "Unpublished";
   	}else{
   	$draftOrNot = "Published";
   	}

if($version == draft){
   	$pubOrHide = "<a href=\"add_photo_feature.php\">Publish</a> | <a href=\"africa.php\">Edit</a>";
   	}else{
   	$pubOrHide = "<a href=ssi_css_form.php?article={$code1v2[$i]}>Not Published - Publish Now</a>";
   	}

echo "<div class=\"grey_details_box\">
  <div class=\"grey_details_box_left\">$draftOrNot</div>
  <div class=\"grey_details_box_right\">$pubOrHide</div>
</div>

<div>
<div id=\"abstract_profile\">
<div id=\"abstract_image\" class=\"$country_Name\"><span class=\"abstract_default\">$country_alias<br />
$sub_category_Name</span></div> 
<div class=\"abstract_header\"><span class=\"abstract_title\">$title</span><span class=\"comment_stars\"><img src=\"stars_$rating.png\" /></span></div><div class=\"abstract_text\"><span class=\"black_abstract_small\">$abstract</span></div>
<div class=\"abstract_town_link\"><div class=\"abstract_town\"><span class=\"grey_abstract_capitals\">$town</span></div><div class=\"abstract_link\"><span class=\"grey_small\"></span></div></div></div>
</div>";

}
}
} ?>

 

Can anyone help?

 

All help is very much appreciated,

Cs1h

 

Link to comment
https://forums.phpfreaks.com/topic/152369-solved-results-not-being-shown/
Share on other sites

var_dump is your friend...

var_dump($var);

 

Use that to check the output of data you're getting from the database to see exactly what you're getting back from a query.

 

It may be a simple case that your query isn't written properly to what you need but not malformed to generate an error.

 

Right-click and view source to see the formatted output from var_dump()

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.