Jump to content

More on: Arrays, Queries and Loops


radar

Recommended Posts

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..

[code]
<?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...
}
?>
[/code]

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..

[code]

<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>
[/code]

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..
Link to comment
https://forums.phpfreaks.com/topic/19641-more-on-arrays-queries-and-loops/
Share on other sites

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

Anyway, to get you started..

[code]<?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);
}
?>[/code]

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

[code]<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>[/code]

btw.. don't hardcode HTML into you app.. that's why you are using templates in the first place.
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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.