17. januar 2006 - 12:43
Der er
4 kommentarer og 1 løsning
underligt problem i sql streng
min streng ser sådan ud (udklip): WHERE cat.published = 1 AND cat.section = $sectionid Problemet er $sectionid Hvis jeg skriver cat.section = 1 virker det fint nok, eller vælger et andet gyldigt tal. Henter jeg tallet via $sectionid bliver min sql ikke udført, men kommer heller ikke med fejl. laver jeg en echo $sectionid udskriver den tallet 1 som den skal så derfor forstår jeg sgu ikke lige hvad der går galt her...
Annonceindlæg fra Timegrip
17. januar 2006 - 13:04
#2
Et par linier kode :) $sectionid = "1"; if ($option=="com_content" && $task=="view") { $id = intval( mosGetParam( $_REQUEST, 'id', null ) ); $query = "SELECT catid FROM #__content WHERE id=$id"; $database->setQuery( $query ); $catid = $database->loadResult(); $queries = array( 'kategorinavn' => 'SELECT cat.id AS catid, cat.title, cat.published, con.id AS contentid FROM #__categories cat LEFT JOIN #__content con ON (cat.title = con.title) WHERE cat.published = 1 AND cat.section = $sectionid GROUP BY cat.title ORDER BY cat.title', 'sidenavn' => "SELECT id AS contentid, catid, title FROM #__content WHERE catid = $catid AND state=1 AND access<2 ORDER BY title ASC" ); echo "<table class=\"$moduleclass_sfx\" cellpadding=\"$cellpadding\" cellspacing=\"$cellspacing\" width=\"$width\">"; foreach($queries as $headline => $stmt) { echo "<tr>"; echo "<td colspan=\"$antaltd\" class=\"$moduleclass_sfx\"><b>${$headline}</b></td>"; echo "</tr>"; echo "<tr>"; $database->setQuery( $stmt ); $rows = $database->loadObjectList(); for ( $i=1; $i <= count( $rows); $i++ ) { $row = $rows[$i-1]; if ($row->contentid == "") { echo "<td class=\"$moduleclass_sfx\" width=\"$tdwidth\">{$row->title}</td>"; if(($i%$antaltd) == 0) { echo "</tr>"; echo "<tr>"; } } else { echo "<td class=\"$moduleclass_sfx\" width=\"$tdwidth\"><a href=".sefRelToAbs("index.php?option=com_content&task=view&id={$row->contentid}&catid={$row->catid}")." class=\"$moduleclass_sfx\">{$row->title}</a></td>"; if(($i%$antaltd) == 0) { echo "</tr>"; echo "<tr>"; } } } echo "</tr>"; } echo "</table>"; }
17. januar 2006 - 13:09
#4
jow, det skyldes du har brugt apostroffer til at angive strengen. Det har den effekt, at variablen ikke bliver parset $sectionid = 1; echo '$sectionid'; echo "$sectionid"; producerer to helt forskellige resultater