Jump to content


Photo

More on: Arrays, Queries and Loops


  • Please log in to reply
4 replies to this topic

#1 radar

radar
  • Members
  • PipPipPip
  • Advanced Member
  • 645 posts
  • LocationSLC

Posted 04 September 2006 - 05:41 AM

Okay so this time on this subject I've got a table called links.. and again this is in my administration console and im working on a part where I can go through and validate all links before they are posted on the site for public to view....

In my table which is called links I have 5 colums...

links_id
links_status
links_url
links_image
links_name

So I figured I would use a foreach on this but not sure how I would with 5 different options that I need only 4...  after the query that is...  So here is my query..

<?php
$queued = mysql_query("SELECT * FROM links WHERE links_status = 'queued'");
$cnt = mysql_num_rows($queued);
$queueds = mysql_fetch_assoc($queued);
if ($cnt == "" || $cnt == "0") {
$tpl->assign('queued_link_list', '<tr><td width="100%" bgcolor="#FFFFFF" class="style7">There are 0 links waiting in queue</td></tr>');
} else {
// here is where I need help...
}
?>

So I need to come up with a script -- a loop to go through all links that are in queued status which has already been selected and turned into an assoc array via the string $queueds...  Now the list should be in something like $queued_link_list which will contain all the HTML for the table codes etc that will display the proper information.. here is how i have the code set up right now..

This is only HTML and Im not sure where to begin on this..


<tr>
            <td width="331" bgcolor="#FFFFFF" class="style7">queued_link_site</td>
            <td width="172" bgcolor="#FFFFFF" class="style7">queued_link_image</td>
            <td width="205" bgcolor="#FFFFFF" class="style7">queued_link_name</td>
            <td width="44" bgcolor="#FFFFFF"><img src="../templates/cesite/images/b_approve.gif" alt="approve" width="16" height="16" /> <img src="../templates/cesite/images/b_drop.gif" alt="deny" width="16" height="16" /></td>
          </tr>

Okay so i just put in some basic info there...  queued_link_site will be a link to the site address for the entry in the list..

queued_link_image will be a link to the image (if any) which should open in a new browser window preferrably one sized to the image...

queued_link_name is just the name of the site -- this will show in the link field if there is no image set.. 

then the b_approve.gif will change the status to approved or something like that...  and b_drop.gif will delete the link from the database because it didnt meet the qualifications that are to be defined at a later date...

So any help on this would be appreciated..  Thank you guys in advanced -- Im sure i'll be asking a lot of questions while i go through this site but by the time im done i should know all there is to know.. since i am making my whole site from scratch..  im even coding the forums.. or going to attempt to anyway..

edit: fixed display problems in my post..

#2 Moon-Man.net

Moon-Man.net
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 04 September 2006 - 05:55 AM

If you want, you could talk to me on MSN, or email nathan.metcalf(AT)weatherbeeta.com.au
But i cant stay on the forums.
Cheers,
Nathan

#3 radar

radar
  • Members
  • PipPipPip
  • Advanced Member
  • 645 posts
  • LocationSLC

Posted 04 September 2006 - 05:57 AM

I have msn and every other messenger client too -- my msn is justin (AT) morphicdesigns (dot) (com)

if you can help -- that'd be awesome..

#4 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 04 September 2006 - 09:01 AM

Which template engine you using? (I'm guessing Smarty?)

Anyway, to get you started..

<?php
$queued = mysql_query("SELECT * FROM links WHERE links_status = 'queued'");
if (!mysql_num_rows($queued)) {
    $quededs_link_html = array();
    while ($row = mysql_fetch_assoc($queued)) {
        $quededs_link_html[] = array(
                'href' => $row['links_url'],
                'img' => $row['links_image'],
        );
    }
    $tpl->assign('quededs_link_html', $quededs_link_html);
}
?>

and if it is Smarty, your template can now use the following to display the above:

<table>
    {if isset($links)}
        {section name=link loop=$links}
        <tr><td><a href="{$links[link].href}"><img src="{$links[link].img}"></a></td></tr>
        {/section}
    {else}
    <tr><td width="100%" bgcolor="#FFFFFF" class="style7">There are 0 links waiting in queue</td></tr>
    {/if}
</table>

btw.. don't hardcode HTML into you app.. that's why you are using templates in the first place.

#5 radar

radar
  • Members
  • PipPipPip
  • Advanced Member
  • 645 posts
  • LocationSLC

Posted 04 September 2006 - 09:33 AM

Actually I made my own template engine...  It was tough but yeah...  I ended up figuring it out and getting it done... 

The only HTML i'd hardcode is html thats never going to change.. such as on this..

Right now i am working on my admin.php and that I've got set to always be on the default style...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users