Small PHP/SQL problem

GEC: Discuss gaming, computers and electronics and venture into the bizarre world of STGODs.

Moderator: Thanas

Post Reply
User avatar
Tolya
Jedi Council Member
Posts: 1729
Joined: 2003-11-17 01:03pm
Location: Poland

Small PHP/SQL problem

Post by Tolya »

I have a bit of a problem with my wife's website. About two years ago it was coded based on wordpress by a webdeveloper. Right now, Im picking up the admin's mantle, retro-ing the code and trying to figure it out myself so I can do all the necessary modifications. I've ran into a bit of a problem which is way beyond my expertise (html and css coding is mostly my thing, only started learning php).

Here is the problem.

The website in question is http://www.olakalinowska.pl and it is built on wordpress, with the postloop and branding modified to produce the current result. There is a script on the main page which takes all the galleries from a specified album ID and produces a collapsible menu - if you hover on one of the title bars, it will produce a sub-menu with links to specific galleries.

The thing is, the ordering of the galleries seems random. At first I thought it goes by gallery ID, but it does not, if you look at it. I don't think it utilizes any sort of array result ordering.

What I would like it to do is to follow the ordering on the wordpress ngg gallery in the CMS. Any help would be greatly appreciated.
<div class="float-me">
<!-- start slub -->
<div id="main-page-slub">
<a class="div-href" href="/slub/">śluby i chrzty</a>
<div class="menu">
<ul>
<li>
<a href="/slub/">śluby i chrzty</a>
<ul id="album-list-slub">
<?php
$aid = 4;
$query = 'SELECT * FROM wp_ngg_album WHERE id = '.$aid.' LIMIT 1'; //album ludzie
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$sort = $row['sortorder'];
}

$gals_ids = implode(',', (unserialize($sort)));

$query = 'SELECT * FROM wp_ngg_gallery WHERE gid IN ('.$gals_ids.')'; //wszystkie galerie z albumu ludzie
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo ('<li><a href="/slub/?album='.$aid.'&gallery='.$row['gid'].'">'.$row['title'].'</a></li>');
}
?>
</ul>
</li>
</ul>
</div>
</div>
<!-- stop slub -->
<div class="shadow-right"></div>
<div style="clear: both;"></div>
<div class="shadow-bottom"></div>

<div style="clear: both;"></div>
</div>
This was suggested to me on a php forums, unfortunately it does not work.
$query = 'SELECT * FROM wp_ngg_gallery WHERE gid IN ('.$gals_ids.') ORDER BY '.$sort.'';
I've been able to go as far as below, but it only sorts ascending by gallery id and I would have to rework all the gallery id's in the database (I actually lost a record today trying to do this)
$query = 'SELECT * FROM wp_ngg_gallery WHERE gid IN ('.$gals_ids.') ORDER BY gid';
Hmm, help?
User avatar
Tolya
Jedi Council Member
Posts: 1729
Joined: 2003-11-17 01:03pm
Location: Poland

Re: Small PHP/SQL problem

Post by Tolya »

UPDATE:

Starting to crack this nut. It seems the proposed solution isn't working because the sortorder column in wp_ngg_album is weird.

$aid = 4 is a:5:{i:0;s:2:"26";i:1;s:2:"24";i:2;s:2:"14";i:3;s:2:"25";i:4;s:2:"18";}

So the order by function does indeed work fine but the contents of the returned sortorder are unintelligible. Still, no idea how to go around this, the sorting by sortorder is the thing I need, I just need code to extract the gid's in commas.
User avatar
Tolya
Jedi Council Member
Posts: 1729
Joined: 2003-11-17 01:03pm
Location: Poland

Re: Small PHP/SQL problem

Post by Tolya »

Okay, found the solution, a bit heavy handed one, but it works.

I added a field in the sql database named odr, assigned integers 1-5 to specific rows and then ORDERed BY odr. Simple, not very elegant, but works for now.
Post Reply