11
javier
Re: help with mysql query in latest downloads block
  • 2004/3/29 16:29

  • javier

  • Not too shy to talk

  • Posts: 184

  • Since: 2002/8/6 1


Hi, thanks for taking your time for reply,

the alternate approach sound much better to go for me,

i tried but not work ,the MySQL debug not give errors (the query is not there)
maybe i made something wrong? i replaced $category_id_you_want_on_top
with $9 wich is the main category.

grettings and thanks again.

12
Mithrandir
Re: help with mysql query in latest downloads block

not $9 - just a 9

What about php debug?

13
javier
Re: help with mysql query in latest downloads block
  • 2004/3/29 19:40

  • javier

  • Not too shy to talk

  • Posts: 184

  • Since: 2002/8/6 1


sure, sorry for forget about php debug:

Parse error: parse error, unexpected T_STRING in c:\phpdev5\www\site\modules\mydownloads\blocks\mydownloads_top.php on line 19

the line 19 is
le="color: #000000"><?php $xt = new XoopsTree(".$xoopsDB->prefix("mydownloads_cat")." , "cid", "pid");


----


le="color: #000000"><?php function b_mydownloads_top_show($options) { global $xoopsDB; $block = array(); $myts =& MyTextSanitizer::getInstance(); //$order = date for most recent reviews //$order = hits for most popular reviews $xt = new XoopsTree(".$xoopsDB->prefix("mydownloads_cat")." , "cid", "pid"); $categories = $xt->getAllChildId(9); $categorystring = "("; foreach ($categories as $key => $categoryid) { if ($key != 0) { //Only comma-separate subsequent categories $categorystring .= ", "; } $categorystring .= $categoryid; } $categorystring = ")"; $result = $xoopsDB->query("SELECT lid, cid, title, date, hits FROM ".$xoopsDB->prefix("mydownloads_downloads")." WHERE cid IN ".$categorystring." ORDER BY".$options[0]." DESC", $options[1], 0); while($myrow=$xoopsDB->fetchArray($result)){ $download = array(); $title = $myts->makeTboxData4Show($myrow["title"]); if ( !XOOPS_USE_MULTIBYTES ) { if (strlen($myrow['title']) >= $options[2]) { $title = $myts->makeTboxData4Show(substr($myrow['title'],0,($options[2] -1)))."..."; } } $download['id'] = $myrow['lid']; $download['pid'] = $myrow['pid']; $download['cid'] = $myrow['cid']; $download['title'] = $title; if($options[0] == "date"){ $download['date'] = formatTimestamp($myrow['date'],"s"); }elseif($options[0] == "hits"){ $download['hits'] = $myrow['hits'];



14
Mithrandir
Re: help with mysql query in latest downloads block

Did I write anything about $xoopsDB->prefix? No, I don't think so

And don't go putting ". in function calls, where they are not needed - if you were putting a function call in the middle of a string, then yes - but here you are just interested in the variables and values, so no need to go ". ."

And unless $option[0] starts with a space, put one in the SQL query between that and ORDER BY

15
javier
Re: help with mysql query in latest downloads block
  • 2004/3/29 20:48

  • javier

  • Not too shy to talk

  • Posts: 184

  • Since: 2002/8/6 1


ohh, a prefix appear in my code, who was the guilty?

i removed the prefix and fix the space in front of ORDER,

now i get:

php debug:
Fatal error: Cannot instantiate non-existent class: xoopstree in c:\phpdev5\www\site\modules\mydownloads\blocks\mydownloads_top.php on line 19

man sincerely i feel shame, im abusing of your time
thanks for your explanations,you have alot of patience.

16
Mithrandir
Re: help with mysql query in latest downloads block

you'll need to have a
le="color: #000000"><?php include (XOOPS_ROOT_PATH."/class/xoopstree.php");

beforehand - sorry, I forgot.

17
javier
Re: help with mysql query in latest downloads block
  • 2004/3/30 0:20

  • javier

  • Not too shy to talk

  • Posts: 184

  • Since: 2002/8/6 1


i added xoops_ to both table names,
because i get this error

SELECT cid FROM mydownloads_cat WHERE pid=8
Error number: 1146
Error message: Table 'site.mydownloads_cat' doesn't exist

i modified mydownloads_cat to xoops_mydownloads_cat and solved, because i have my tables with the XOOPS prefix.
that´s a detail only
----------------

now the true stuff:
this is the code:

le="color: #000000"><?php include (XOOPS_ROOT_PATH."/class/xoopstree.php"); $xt = new XoopsTree('xoops_mydownloads_cat', "cid", "pid"); $categories = $xt->getAllChildId(8); $categorystring = "("; foreach ($categories as $key => $categoryid) { if ($key != 0) { //Only comma-separate subsequent categories $categorystring .= ", "; } $categorystring .= $categoryid; } $categorystring = ")"; $result = $xoopsDB->query("SELECT lid, cid, title, date, hits FROM 'xoops_mydownloads_downloads' WHERE cid IN ".$categorystring." ORDER BY ".$options[0]." DESC", $options[1], 0);


and this is the MySQL debug:

le="color: #000000"><?php SELECT lid, cid, title, date, hits FROM 'xoops_mydownloads_downloads' WHERE cid IN ) ORDER BY date DESC LIMIT 0, 10 Error number: 1064 Error message: You have an error in your SQL syntax near ''xoops_mydownloads_downloads' WHERE cid IN ) ORDER BY date DESC LIMIT 0, 10' at line 1


18
Dave_L
Re: help with mysql query in latest downloads block
  • 2004/3/30 0:35

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


$categorystring .= ")";

But a cleaner method is:

le="color: #000000"><?php $categorystring = implode(',', $categories); $result = $xoopsDB->query( "SELECT lid, cid, title, date, hits FROM xoops_mydownloads_downloads WHERE cid IN ($categorystring) ORDER BY {$options[0]} DESC ", $options[1], 0 );


If $categories is empty though, you'll get a MySQL syntax error, so you may want to add a special check for that.

19
javier
Re: help with mysql query in latest downloads block
  • 2004/3/30 10:43

  • javier

  • Not too shy to talk

  • Posts: 184

  • Since: 2002/8/6 1


Now work fine :):)

what happen when i wan put more than 1 block? sorry for not ask before.
My idea is have 3 or 4 blocks showing the latest files from each category,
when i tried to put a second block i get the following msg:

Fatal error: Cannot redeclare class xoopstree in c:\phpdev5\www\site\class\xoopstree.php on line 33

grettings





20
Mithrandir
Re: help with mysql query in latest downloads block

change
include (path/to/xoopstree.php)
to
include_once (path/to/xoopstree.php)

Login

Donat-O-Meter

Stats
Goal: $15.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $15.00
Make donations with PayPal!

Latest GitHub Commits