PDA

View Full Version : Help with queries


harmor19
07-07-2006, 02:30 AM
I have two table; one is for categories, the other for links.
What I want to do is show the category then show the relative links.
Basically I would like to work like categories and forums.
You have the "News And Announcements" category then follows the forums.

Paul M
07-07-2006, 04:38 AM
So what exactly is your question ?

harmor19
07-07-2006, 05:06 AM
I am upgrading my "Custom Navbar Links" hack and I would like to add seperators.

I have two table; custom_links_cat and custom_droplinks

custom_links_cat

catid
title
link_perms


custom_droplinks

linkid
catid
url
name
....


My hack is like "Quick Links" but user defined. Hopefully the image will explain what I want.

harmor19
07-07-2006, 09:10 PM
I need help. I got it to do what I wanted but it only gets the first catid it comes across instead of all of them.


$getcats = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "custom_links_cat");
while($cat = $db->fetch_array($getcats))
{

$getdroplinks = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "custom_droplinks WHERE catid='$cat[catid]' ");
while($dlink = $db->fetch_array($getdroplinks))
{
$custom_droplinks .= "<tr><td class='thead'>".$cat['title']."</td></tr>
<tr><td class='vbmenu_option'>$img<a href='".$dlink['url']."' target='$new' title='".$dlink['alt']."'>".$dlink['name']."</a></td></tr>";

eval('$custom_droplinks = "' . fetch_template('custom_droplinks') . '";');
}
}

harmor19
07-11-2006, 09:10 PM
Please help.

harmor19
07-12-2006, 04:40 AM
what's wrong with this code
getdroplinks = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "custom_links_cat clc
LEFT JOIN " . TABLE_PREFIX . "custom_droplinks cdl ON (clc.catid=cdl.catid)
WHERE clc.catid=cdl.catid ORDER BY clc.catid ASC");

while($dlink = $db->fetch_array($getdroplinks))
{
if($dlink['new_window'] == 1)
{
$new = "_blank";
}
else
{
$new = "";
}

if(!empty($dlink['image']))
{
$img = "<img src='".$dlink['image']."' width='16' height='16' />";
}
else
{
$img = "";
}

$dlink['link_perms'] = explode(",", $dlink['link_perms']);

if(in_array($vbulletin->userinfo['usergroupid'], $dlink['link_perms']) )
{
$custom_droplinks .= "<tr><td class='thead'>".$dlink['title']."</td></tr>
<tr><td class='vbmenu_option'>$img<a href='".$dlink['url']."' target='$new' title='".$dlink['alt']."'>".$dlink['name']."</a></td></tr>";
}
eval('$custom_droplinks = "' . fetch_template('custom_droplinks') . '";');
}

Screenshot of what it's producing below

Paul M
07-12-2006, 07:13 AM
Everytime you loop round (for each record) the code adds the header and the link, there is nothing to check if the header is the same as the previous record.

harmor19
07-12-2006, 07:21 AM
So how would I check it?

harmor19
07-17-2006, 12:09 AM
I finally got it.
If you people didn't help because you thought I wasn't trying then you all wrong


$getdroplinks = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "custom_links_cat clc
LEFT JOIN " . TABLE_PREFIX . "custom_droplinks cdl ON (clc.catid=cdl.catid) ");

$prev_cat = '0';

while($dlink = $db->fetch_array($getdroplinks))
{

if($dlink['new_window'] == 1)
{
$new = "_blank";
}
else
{
$new = "";
}

if(!empty($dlink['image']))
{
$img = "<img src='".$dlink['image']."' width='16' height='16' />";
}
else
{
$img = "";
}

if($dlink['catid'] != $prev_cat)
{
$custom_droplinks .= "<tr><td class='thead'>".$dlink['title']."</td></tr>";
}

$dlink['link_perms'] = explode(",", $dlink['link_perms']);


if(in_array($vbulletin->userinfo['usergroupid'], $dlink['link_perms']) )
{
$custom_droplinks .= "$header
<tr><td class='vbmenu_option'>$img<a href='".$dlink['url']."' target='$new' title='".$dlink['alt']."'>".$dlink['name']."</a></td></tr>";
}

eval('&$custom_droplinks = "' . fetch_template('custom_droplinks') . '";');

$prev_cat = $dlink['catid'];
}

ShadyB
01-30-2007, 09:09 PM
Can I rename the title on the navbar saying Extras?