MySQL-PHP Query Results Help


Posted on 16th Feb 2014 07:03 pm by admin

Hello all. I'm hoping to be able to get some help in solving a problem with query/rowcount output. I've been learning PHP and mySQL for about 7 months now and have several successful Mods written/modified for PHP-Fusion CMS version7.00.05. My host is running PHP-5 and MySQL-5. I am converting a Mod from Fusion-ver6 to work on ver-7, called Classified Ads. It has turned out to be a MONSTER to modify and I have run into a snag. There is code that selects ALL the categories and divides them in half displaying half in a table TD and the other half in another TD beside it for a 2 column display. This works just great. What I have is 22 categories and approx. 220 sub-categories. What I am trying to do is display the number of sub-categories below each main category. Here is a pic of the current display with annotations:



I tried using the same code (which works for the main cats), to display the # of sub-cats. It works fine for the first TD but fails in the second TD. I will show the pertinent code rather than posting the entire script, unless requested to do so. Here is the code that produces what you see in the pic:

Code: echo "<table width='100%' border='0' cellspacing='0' cellpadding='3'><tr>n";
$result = dbquery("SELECT * FROM ".DB_CLASSIFIED_CATEGORIES." WHERE status='1' AND parentid=0");
$numrows = dbrows($result);
if($numrows > 0) {
$numrows % 2 ? $numrows += 1 : $numrows;
$rows = $numrows / 2;
echo "<td valign='top' width='50%'>";
$result = dbquery("SELECT cid, title, description, image, parentid FROM ".DB_CLASSIFIED_CATEGORIES." WHERE status='1' AND parentid='0' ORDER BY title LIMIT $rows");
while(list($cid, $title, $description, $image, $parentid) = dbarraynum($result))
{
$count1=dbcount("(*)", $db_prefix."classified", " cid='$cid' AND status='1'");
echo "<table cellspacing='2' cellpadding='1' width='100%' border='0'><tr>n";
echo "<td valign='top' width='100%'>";
if($image) {
echo "<a href='".FUSION_SELF."?op=view_ad&amp;cid=".$cid."'><img src='".INFUSIONS."classified_ads_panel/images/cat/".$image."' alt='".$title."' border='0'></a>(<strong>".$count1." ";
if($count1>1 || $count1<1) {
echo $locale['CLS_0120'];
} else {
echo $locale['CLS_0119'];
}
echo "</strong>)";
} else {
echo "<a href='".FUSION_SELF."?op=view_ad&amp;cid=".$cid."'><strong>".$title."</strong></a>(<strong>".$count1." ";
if($count1>1 || $count1<1) {
echo $locale['CLS_0120'];
} else {
echo $locale['CLS_0119'];
}
echo "</strong>)<br />";
// start here
$subresult = dbquery("SELECT * FROM ".DB_CLASSIFIED_CATEGORIES." WHERE status='1' AND parentid >0");
$myrows = dbrows($subresult);
if($myrows > 0) {
$myrows % 2 ? $myrows += 1 : $myrows;
$subrows = $myrows / 2;
$subresult = dbquery("SELECT cid, title, description, image, parentid FROM ".DB_CLASSIFIED_CATEGORIES." WHERE parentid >0 AND parentid=$cid ORDER BY parentid LIMIT $subrows");
$myrows = dbrows($subresult);
$subrows = $myrows;
}

echo $subrows." sub-categories<br />";
// end here
}
echo "</td>n";
echo "</tr><tr>n";
echo "<td>".$description."</td>n";
echo "</tr></table>n";
}
echo "</td><td valign='top' width='50%'>";
$result1 = dbquery("SELECT cid, title, description, image, parentid FROM ".DB_CLASSIFIED_CATEGORIES." WHERE status='1' AND parentid='0' ORDER BY title LIMIT $rows, $rows");
while(list($cid, $title, $description, $image, $parentid) = dbarraynum($result1))
{
$count1=dbcount("(*)", $db_prefix."classified", " cid='$cid' AND status='1'");
echo "<table cellspacing='2' cellpadding='1' width='100%' border='0'><tr>n";
echo "<td valign='top' width='100%'>";
if($image) {
echo "<a href='".FUSION_SELF."?op=view_ad&amp;cid=".$cid."'><img src='".INFUSIONS."classified_ads_panel/images/cat/".$image."' alt='".$title."' border='0'></a>(<strong>".$count1." ";
if($count1>1 || $count1<1) {
echo $locale['CLS_0120'];
} else {
echo $locale['CLS_0119'];
}
echo "</strong>)";
} else {
echo "<a href='".FUSION_SELF."?op=view_ad&amp;cid=".$cid."'><strong>".$title."</strong></a>(<strong>".$count1." ";
if($count1>1 || $count1<1) {
echo $locale['CLS_0120'];
} else {
echo $locale['CLS_0119'];
}
echo "</strong>)<br />";
// start here
$subresult = dbquery("SELECT cid, title, description, image, parentid FROM ".DB_CLASSIFIED_CATEGORIES." WHERE parentid >0 AND parentid=$cid ORDER BY parentid LIMIT $subrows, $subrows");
$myrows = dbrows($subresult);
$subrows = $myrows;

echo $subrows." sub-categories<br />";
// end here
}
echo "</td>n";
echo "</tr><tr>n";
echo "<td>".$description."</td>n";
echo "</tr></table>n";
}
echo "</td>n";
}

I'm wondering why my added code works OK for the first part but not the second part. Any and all help/suggestions would be GREATLY appreciated

No comments posted yet

Your Answer:

Login to answer
123 Like 6 Dislike
Previous forums Next forums
Other forums

LinkedList help
Ok so I just learned quickly about lists, so I have a not too hard project I think, but am having a

FAGL_FC_TRANSLATION FAS52 New GL ECC 6.0
Hello,

The new program for Translating GL Balances (FAS 52) gives the option to use diffe

asp authentication problem
Hello all, I want to use the asp authentication (from asp.net configuration) in my web site. there

How to implement HTTP connection timeout
Hi All,I would like to implement an HTTP connection timeout.

I am working on a application wh

breaking a text file into paragraphs based on strings
I have a text file of email addresses that is all squished together. It looks like this:

abc

Including calander to page - will not show other months than current??
im trying to add an existaing calander onto a profile page by using Code: <?php include "

What am I missing here? Help!
Hello all!. I can't seem to get this working right. Well - it renders right, but something is goin

Loosing changed contents when used FM REUSE_ALV_GRID_DISPLAY
Hi,

I have used FM REUSE_ALV_GRID_DISPLAY in my program as below.

CALL FUNCT

Material Master Update through BAPI - Follow up material not updated
Hi Experts,

I am updating the material master through a custom transaction using the BAPI

mysql UNION | warning mysql_fetch_array !!
Code: <?php
$i = 0;
$query1="SELECT * FROM `products` WHERE `div

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash