PHP - Nested For Loop Problem
Hi, first of all thanks in advance for the help. I'm a newbie college student and am having a little problem with a project for a class that I can't figure out.
I'm trying to construct a loop that creates an array for a javascript image gallery. First I call for the categories and I want to then pull all the images from that category into the array and then loop through all the categories in the database. The code below just cycles through the first category and then quits after pulling the images from that category. Code: [Select] <?php // SQL Query for Categories $sql="SELECT CategoryID, CategoryName FROM pro2category"; $result = mysql_query($sql); if(empty($result)) { $num_results = 0; } else { $num_results = mysql_num_rows($result); } ?> <?php for($i=0; $i<$num_results; $i++) { $row = mysql_fetch_array($result); $CategoryID = $row["CategoryID"]; $CategoryName = $row["CategoryName"]; ?> var <?php echo $CategoryID ?> = new Array(); <!-- Images inside Array --> <!-- Images inside Array --> <!-- Images inside Array --> <!-- Images inside Array --> <?php $sql="SELECT ImageID, ImageName, ImageNumber, URL, CategoryID FROM pro2image WHERE CategoryID='$CategoryID'"; $result = mysql_query($sql); if(empty($result)) { $num_results = 0; } else { $num_results = mysql_num_rows($result); } ?> <?php for($i=0; $i<$num_results; $i++) { $row = mysql_fetch_array($result); $ImageID = $row["ImageID"]; ?> <?php echo $CategoryID ?>Array[<?php echo $i ?>] = "http://cgtweb2.tech.purdue.edu/356/zrodimel/Project2/admin/upload/<?php echo $ImageID ?>.jpg"; <?php } ?> <?php } ?> thanks for the help Zach Similar TutorialsI'm a bit confused here on for loops. I don't quite understand why this script outputs what it does and I'd like it if someone could explain it to me. Code: (php) [Select] <?php for ($i = 1; $i < 3; $i = $i + 1) { for ($j = 1; $j < 3; $j = $j + 1) { echo "'i' is {$i}, 'j' is {$j}<br />"; } } ?> Result: Code: [Select] 'i' is 1, 'j' is 1 'i' is 1, 'j' is 2 'i' is 2, 'j' is 1 'i' is 2, 'j' is 2 Hi there, im trying to nest two do loops. The first loop works fine but the last loop doesnt seem to work at all. Code: [Select] <? $colname_Planet = "-1"; if (isset($_GET['recordID'])) { $colname_Planet = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']); } mysql_select_db($database_swb, $swb); $query_Planet = sprintf("SELECT * FROM planet WHERE PlanetName = %s", GetSQLValueString($colname_Planet, "text")); $Planet = mysql_query($query_Planet, $swb) or die(mysql_error()); $row_Planet = mysql_fetch_assoc($Planet); $totalRows_Planet = mysql_num_rows($Planet); $plans = $row_Planet['PlanetName']; $colname_Fleet = "-1"; if (isset($_GET['recordID'])) { $colname_Fleet = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']); } mysql_select_db($database_swb, $swb); $query_Fleet = sprintf("SELECT * FROM fleet WHERE PlanetName = '$plans'"); $Fleet = mysql_query($query_Fleet, $swb) or die(mysql_error()); $row_Fleet = mysql_fetch_assoc($Fleet); $totalRows_Fleet = mysql_num_rows($Fleet); $fleetships = $row_Fleet['FleetName']; $colname_Ships = "-1"; if (isset($_GET['recordID'])) { $colname_Ships = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']); } mysql_select_db($database_swb, $swb); $query_Ships = sprintf("SELECT * FROM ships WHERE FleetName = '$fleetships'"); $Ships = mysql_query($query_Ships, $swb) or die(mysql_error()); $row_Ships = mysql_fetch_assoc($Ships); $totalRows_Ships = mysql_num_rows($Ships); ?> <?php do { ?> <?php echo $row_Fleet['FleetName']; ?> <?php echo $row_Fleet['PlanetName']; ?> <?php do { ?> <?php echo $row_Ships['ShipName']; ?> <?php } while ($row_Ships = mysql_fetch_assoc($Ships)); ?> <?php } while ($row_Fleet = mysql_fetch_assoc($Fleet)); ?> If you can spot anything wrong, please let me know. Thanks Hello everybody, I hope someone can help me. I've got a database table with subscriber info linked to various tenders. The current layout of the table is as follows (this is dummy data): Subscriber Category Email Tender Info Dummy Company 1 Advertisting email@email.com Tender 1 Dummy Company 1 Advertisting email@email.com Tender 2 Dummy Company 1 Advertisting email@email.com Tender 3 Dummy Company 1 Advertisting email@email.com Tender 4 Dummy Company 2 Marketing email2@email.com Tender 5 Dummy Company 2 Marketing email2@email.com Tender 6 What I'm trying to do, is to send Company 1 an email with the info for all 4 tenders. If I do a normal loop, it sends 4 emails, each mail having the info only for one tender. Here's my code: Code: [Select] //Select subscriber and email address, grouped to only have one entry per sub $subs = "SELECT subscriber, email FROM tenders_temp GROUP BY subscriber"; $query = mysql_query($subs); while ($subsrs = mysql_fetch_array($query)) { //Select all tenders info $tender = "SELECT * FROM tenders_temp WHERE subscriber = '".$subsrs['subscriber']."'"; $restender = mysql_query($tender); //Send email $msg = "<html><body> <table width='100%' border='0' cellspacing='0' cellpadding='10'>"; while ($rstend = mysql_fetch_array($restender)) { $msg .= " <tr> <td valign='top'><strong>SUBSCRIBER:</strong></td> <td colspan='3'>".$rstend['subscriber']."</td> </tr> <tr> <td valign='top'><strong>CATEGORY:</strong></td> <td colspan='3'>".$rstend['tender_interests']."</td> </tr> <tr> <td width='16%' valign='top'><strong>REFERENCE: </strong></td> <td width='34%'>".$rstend['reference']."</td> <td width='15%'><strong>CLOSING:</strong></td> <td width='35%'>".$rstend['closedate']." ".$rstend['closetime']."</td> </tr> <tr> <td valign='top'><strong>DESCRIPTION:</strong></td> <td colspan='3'>".$rstend['summary']." ".$rstend['description']." ".$rstend['detail']."</td> </tr> <tr> <td valign='top'><strong>CONTACT:</strong></td> <td colspan='3'>".$rstend['organization']."; ".$rstend['contact']."; Phone: ".$rstend['dial_code']." ".$rstend['telno']."; Email: ".$rstend['email']."</td> </tr> <tr> <td valign='top'><strong>DOCUMENTATION:</strong></td> <td colspan='3'>".$rstend['documentation']."</td> </tr> <tr> <td> </td> <td> </td> <td colspan='2'> </td> </tr> <tr> <td> </td> <td> </td> <td colspan='2'> </td> </tr>"; } $msg .= " </table> </body></html>"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n"; $headers .= "From: info@tenders24.com\r\n"; $headers .= "Reply-To: info@tenders24.com\r\n"; $headers .= "Return-Path: info@tenders24.com\r\n"; $headers .= "Organization: Tenders24\r\n"; $headers .= "X-Priority: 3\r\n"; mail($subsrs['email'], "Tenders24", $msg, $headers); } Looking at this code, in theory it should work. The first query groups the entries to have one email address, then the second loop, takes each entry and loops the number of tenders inside the email. I'm getting an error with this tho. Code: [Select] Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Can anybody please help?? Thanks in advance! Karen I think the problem is with echo "<td>".$row["countnow($i)"]."</td>"; it's not showing anything, any ideas how to fix it? Code: [Select] $i = 1; While ($i <25) { ?> <tr> <td><?php echo $i; ?></td> <?php $sql = "SELECT * FROM `systems` WHERE `solarSystemName` LIKE $sname" or die (mysql_error()); $result = mysql_query($sql); while ($row = mysql_fetch_array($result)){ echo "<td>".$row["countnow($i)"]."</td>"; } ?> <tr> <?php $i++; } Hello i am new here, and new to php too. I try to learn php from about 20 days, and i am getting stuck in something, somebody asked me to make a program that will produce the following output, i have to use a nested for loop: 1 22 333 4444 55555 ........etc The code for is: Code: [Select] for($a=1;$a<10;$a++) { echo "<br>"; for ($b=0;$b<$a;$b++) echo $a; }I do know this is something elementary, but really i cannot understand how it works is there any saint that will comment the code and explain step by step whats happening there? Thank you. Hi guys, Was wondering if anyone can help me with this. Here's what I'm trying to do: I've retrieved values from table a from mysql and post them on a form. Code: [Select] echo "<tr><td>" .$row['id']. "</td><td>" .$row['name']. "<input type='hidden' name=name[] value=" .$row['name']. "></td><td><select name='item[]'><option value ='' selected='selected'>Please Select</option><option value ='1'>1</option><option value ='2'>2</option><option value ='3'>3</option></td></tr>"; and now i'm trying to display these information one more time on a different page. So I did the usual retrieval Code: [Select] $name = $_POST['name']; $item = $_POST['item']; Then I'm using foreach loop to retrieve the item values. Code: [Select] foreach ($item as $getitem => $value) { echo "<tr><td>"; echo $value; echo "</td></tr>"; } Here is where I'm stumped. What's the best way to associate the name to the item. while loop? Thanks for the help. hello. i finally got my nested list working but its only go 2 levels. how do i make it unlimited levels ? this is a nested list Code: [Select] <ul> <li><a href="#">list</a></li> <li><a href="#" class="sub">sub title</a> <ul class="subcat" style="margin-left: 15px"> <li><a href="#">sub title</a></li> </ul> </li> </ul> this is not the actual code but this is how it works at the moment Code: [Select] <ul> if($Level == "list"){ <li><a href="#">list</a></li> }elseif($Level == "subList"){ <li><a href="#" class="sub">sub title</a> <ul class="subcat" style="margin-left: 15px"> <li><a href="#">sub title</a></li> </ul> </li> } </ul> Hi, I'm developing a "gallery" script so that I can manage my photos online, and I'm having a problem I can't seem to figure out. Hoping someone can help... So here's my problem. I have two main tables for my application (amongst several others but for all intents and purposes they aren't needed). One is "albums" and the other "photos". Here's the structure for both: Code: [Select] Albums CREATE TABLE IF NOT EXISTS `kill4silence_photos_albums` ( `id` int(255) NOT NULL AUTO_INCREMENT, `parent_id` int(255) NOT NULL, `user_id` int(255) NOT NULL, `cover` int(255) NOT NULL, `name` varchar(50) NOT NULL, `description` text NOT NULL, `location` varchar(255) NOT NULL, `time` varchar(50) NOT NULL, `date` varchar(50) NOT NULL, `timestamp` int(255) NOT NULL, `last_updated_date` varchar(50) NOT NULL, `last_updated_time` varchar(50) NOT NULL, `last_updated_timestamp` int(255) NOT NULL, `views` int(255) NOT NULL, `tags` longtext NOT NULL, `downloads` int(255) NOT NULL, `download_disabled` int(1) NOT NULL, `comments_disabled` int(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=156 ; ----------------------------------------------------------------------------------------- Photos CREATE TABLE IF NOT EXISTS `kill4silence_photos_photos` ( `id` int(255) NOT NULL AUTO_INCREMENT, `album_id` int(255) NOT NULL, `user_id` int(255) NOT NULL, `name` varchar(50) NOT NULL, `caption` varchar(200) NOT NULL, `time` varchar(50) NOT NULL, `date` varchar(50) NOT NULL, `timestamp` int(255) NOT NULL, `file_name` varchar(5000) NOT NULL, `file_type` varchar(100) NOT NULL, `file_ext` varchar(25) NOT NULL, `location` varchar(200) NOT NULL, `photo_time` varchar(50) NOT NULL, `photo_date` varchar(50) NOT NULL, `views` int(255) NOT NULL, `tags` longtext NOT NULL, `downloads` int(255) NOT NULL, `downloads_disabled` int(1) NOT NULL, `comments_disabled` int(1) NOT NULL, `visible` int(1) NOT NULL, `last_updated_date` varchar(50) NOT NULL, `last_updated_time` varchar(50) NOT NULL, `last_updated_timestamp` int(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=204 ; Now basically how this works is when a new album is created, it is given a parent_id of '0' where the parent_id is the identifer of it's "parent" album. Say, I have five albums, each nested within each other like so. 1, 2, 3, 4, 5. On the page, it would look like, Album 1 (link that takes you to Album 2) Album 2 (link that takes you to Album 3) And so on... I use $_GET to send you to the next nested album. Each album's query string looks like this: Code: [Select] photos.php?album={$id} No matter what album you're in (be it the "father" parent album or a nested album) Now, what I want to do is construct a method to add to my "photos" class, that creates an array of all parent album id's depending on the current nested album, so I can use that array to display a "navigation" type thingy-ma-jigger at the top of each page. For example: Current album is "Ghosts" Navigation would look like: Paranormal Activity -> Experiences -> Ghosts Where "Ghosts" and "Experiences" are albums nested in "Paranormal Activity" I figure you'd have to go about this using a loop of some kind, but I can't for the life of me figure it out. The only thing I can think of to do that doesn't entirely solve this problem is get the parent id of the current album. So as of right now, if "Ghosts" is currently being displayed, I can output a link taking you to "Experiences", but I can't do so to get "Paranormal Activity". I mean I could, but I'd have to loop through twice to get both ID's. I need a method that will loop through infinitely until there are no more parent albums to be found. Hope this all makes sense. Here's my code for viewing an album, just so you can get a clear picture (I'm using the Smarty extension case the HTML code confuses you) Code: [Select] <div id='view_album'> <!--<a href='photos.php?album={$PARENT_ALBUM_ID}'>« Back to {$PARENT_ALBUM_NAME}</a>--> <div class='album_name'> {$ALBUM_NAME} </div> <div class='album_info'> Created by <a href=''>{$USERNAME}</a> (<a href="photos.php?album={$PARENT_ALBUM_ID}">{$PARENT_ALBUM_NAME}</a>) {$DATE_FANCY} • Updated {$LAST_DATE_FANCY} {if strlen($LOCATION) > 0} • Taken at {$LOCATION} {/if} {if $smarty.const.PHOTOS_ADMIN_ACCESS == true} • <a href='photos.php?album={$ALBUM_ID}&action=edit'>Edit Album</a> • <a href='photos.php?album={$ALBUM_ID}&action=delete'>Delete Album</a> • <a href='photos.php?album={$ALBUM_ID}&action=upload&max=1&submit=false'>Upload Photos</a> {/if} </div> <!--Start albums--> {$i= 0} {$max_columns = 5} {$column_width = 100 / {$max_columns}} <table width='100%'> {foreach $ALBUMS_ARRAY as $id => $id} {if $i == 0} <tr> {/if} <td width='20%' align='center'> <div class='album_graphic_container'><a href='photos.php?album={$id}'> {if {albums::info ("id", "=", {$id}, "cover")} == 0} <a href="photos.php?album={$id}"><img src='photos/images/icons/album_default.png'></a> {else} <img src='photos/covers/{$id}/default.jpg' style="width: 100%;"/> {/if} </div> <div class='album_graphic_info'> <a href='photos.php?album={$id}'>{albums::info ("id", "=", {$id}, "name")}</a> <br> {albums::info ("id", "=", {$id}, "num_albums")} Albums • {albums::info ("id", "=", {$id}, "num_photos")} Photos <br> <a href='' style='font-size: 100%;'>{albums::info ("id", "=", {$id}, "num_comments")} Comments</a> </div> </td> {$i = $i + 1} {if $i == $max_columns} </tr> {$i = 0} {/if} {/foreach} {if $i < $max_columns} {$j = 0} {for $k = $i; $k < $max_columns - 1; $k++} {if $j == 0} <td width='{$column_width}%' align='center'> <div class='album_graphic_container'> <a href='photos.php?album={$ALBUM_ID}&action=compose'> <img src='photos/images/icons/album_default.png'> </a> </div> <div class='album_graphic_info'> <a href='photos.php?album={$ALBUM_ID}&action=compose'>+ Add New Album</a> <br> <br> </div> </td> {/if} {$j = 1} <td width='{$column_width}%' align='center'> </td> {/for} {else} {/if} </table> <!--Start photos--> <div class='view_album_lft'> {if {albums::info ("id", "=", {$ALBUM_ID}, "num_photos")} == 0} {else} <!--<div class='view_album_photos_header'>"; Photos In <a href=''>" . albums::info ("id", "=", $_GET["album"], "name") . "</a> (" . albums::info ("id", "=", $_GET["album"], "num_photos") . ")"; </div>";--> {$p = 0} {$p_max_columns = 6} {$p_column_width = 100 / $p_max_columns} <table width='100%'> {foreach $PHOTOS_ARRAY as $id => $id} {if $p == 0} <tr> {/if} <td width='{$p_column_width}%' align='center'> <div class='album_graphic_container'> <a href='photos.php?album={$ALBUM_ID}&photo={$id}'><img src='{photos::info ("id", "=", $id, "src_thumb_medium")}' style='width: 100%;'></a> </div> <div class='album_graphic_info'> {photos::info ("id", "=", {$id}, "views")} Views <br> {photos::info ("id", "=", {$id}, "num_comments")} Comments </div> </td> {$p = $p + 1} {if $p == $p_max_columns} </tr> {$p = 0} {/if} {/foreach} {if $p < $p_max_columns} {for $q = $p; $q < $p_max_columns; $q++} <td width='{$p_column_width}%'> </td> {/for} {/if} </table> {/if} </div> <div class='album_info_2_lft'> {if {likes::determine ("album", {$ALBUM_ID}, $smarty.const.PHOTOS_USER_LOGGED)} == -1} {$NUM_LIKES} Likes • <a href="photos.php?album={$ALBUM_ID}&action=like">Like this album</a> | {$NUM_DISLIKES} Dislikes • <a href="photos.php?album={$ALBUM_ID}&action=dislike">Dislike this album</a> {/if} {if {likes::determine ("album", {$ALBUM_ID}, $smarty.const.PHOTOS_USER_LOGGED)} == 1} {$NUM_LIKES} Likes • <a href="photos.php?album={$ALBUM_ID}&action=unlike">Unlike this album</a> | {$NUM_DISLIKES} Dislikes • <a href="photos.php?album={$ALBUM_ID}&action=dislike">Dislike this album</a> {/if} {if {likes::determine ("album", {$ALBUM_ID}, $smarty.const.PHOTOS_USER_LOGGED)} == 0} {$NUM_LIKES} Likes • <a href="photos.php?album={$ALBUM_ID}&action=like">Like this album</a> | {$NUM_DISLIKES} Dislikes • <a href="photos.php?album={$ALBUM_ID}&action=undislike">Undislike this album</a> {/if} </div> <div class='album_info_2_rt'> {$DOWNLOADS} Downloads • <a href="photos.php?album={$ALBUM_ID}&action=download">Download this album</a> </div> <br clear="all" /> <!--<div class='view_album_rt'> <div class='view_album_rt_header'> Share This Album </div> <div class='view_album_rt_header'> Download This Album </div> <a href=''>Low Quality ({albums::info ("id", "=", {$ALBUM_ID}, "album_size_low")})</a> <br> <a href=''>Medium Quality ({albums::info ("id", "=", {$ALBUM_ID}, "album_size_medium")})</a> <br> <a href=''>High Quality ({albums::info ("id", "=", {$ALBUM_ID}, "album_size_high")})</a> <br> <a href=''>Full Size Quality ({albums::info ("id", "=", {$ALBUM_ID}, "album_size_full")})</a> </div> <br clear='all'>--> <div class='view_album_comments_container'> <div class='view_album_comments_header'> All Comments ({$ALBUM_NUM_COMMENTS}) </div> <div class='view_album_comments_add'> {if !{$PHOTOS_USER_LOGGED}} You must <a href='login.php'>login</a> or <a href='register.php'>sign up</a> in order to post comments {else} {if $COMMENTS_DISABLED == 0} <div class='view_album_comments_single_wrapper'> <div class='view_album_comments_single_lft'> <img src='members/{users::info ($smarty.const.PHOTOS_MEMBERS_FIELD_ID, "=", $smarty.const.PHOTOS_USER_ID, "avatar_src")}'> </div> <div class='view_album_comments_single_rt'> <form action='photos.php?album={$ALBUM_ID}&comment=new&action=add' method='post'> <input type='hidden' name='parent_id' value='0' /> <textarea name='body' placeholder="Write your response" class='view_album_comments_add_textarea'></textarea> <span style="float: right;"><input type="submit" class="fb_button_blue" value="Post Comment" /></span> </form> </div> <br clear='all'> </div> {else} Comments for <a href=''>{$ALBUM_NAME}</a> has been disabled {/if} {/if} </div> {foreach $COMMENTS_ARRAY as $id => $id} <div class='view_album_comments_single_wrapper'> <div class='view_album_comments_single_lft'> <img src='members/{users::info ($smarty.const.PHOTOS_MEMBERS_FIELD_ID, "=", {comments::info ("id", "=", {$id}, "user_id")}, "avatar_src")}'> </div> <div class='view_album_comments_single_rt'> <div class='view_album_comments_single_rt_username'><a href=''>{comments::info ("id", "=", {$id}, "username")}</a></div> <div class='view_album_comments_single_rt_body'>{comments::info ("id", "=", {$id}, "body")}</div> <div class='view_album_comments_single_rt_info'> {comments::info ("id", "=", {$id}, "date_fancy")} • <a href="">Like</a> | <a href="">Dislike</a> {if $smarty.const.PHOTOS_USER_LOGGED == true} {if $smarty.const.PHOTOS_ADMIN_ACCESS || $smarty.const.PHOTOS_USER_ID == {comments::info ("id", "=", {$id}, "user_id")}} • <a href="">Delete</a> {/if} • <a href="">Report</a> {/if} </div> </div> <br clear="all" /> </div> {/foreach} <div id='view_album_comment_report'> <div id='view_album_comment_report_body'> <span class='view_album_comment_report_body_header'>Report Comment</span> </div> </div> </div> </div> Need more info, just ask. Thanks. Hi I have searched around for a solution to this and either fail to grasp how to get it to work or just cannot find the correct solution. I have the following XML file: Code: [Select] <?xml version="1.0" encoding="UTF-8"?> <root> <product> <id>153</id> <images> <image id="1"> <url>http://www.mysite.com/product/images/1322.jpg</url> <title> <en>Book 1</en> </title> </image> <image id="2"> <url>http://www.mysite.com/product/images/1321.jpg</url> <title> <en>Book 2</en> </title> </image> <image id="3"> <url>http://www.mysite.com/product/images/1316.jpg</url> <title> <en>Book 3</en> </title> </images> </product> <product> <id>154</id> <images> <image id="1"> <url>http://www.mysite.com/product/images/1322.jpg</url> <title> <en>Book 1</en> </title> </image> <image id="2"> <url>http://www.mysite.com/product/images/1321.jpg</url> <title> <en>Book 2</en> </title> </image> <image id="3"> <url>http://www.mysite.com/product/images/1316.jpg</url> <title> <en>Book 3</en> </title> </images> </product> </root> $xml = 'example.xml'; // URL for feed. try{ $feed = new SimpleXMLElement($xml, null, true); }catch(Exception $e){ echo $e->getMessage(); exit; } $sql = 'INSERT INTO images (`id`, `url`) VALUES '; foreach($feed->property as $property){ $sql .= sprintf( "\n('%d', '%s'),", $property->id, mysql_real_escape_string($property->images->image->url) ); } $sql = rtrim($sql, ',') . ';'; What I need to do is loop through each of the image url nodes and insert them into my DB with the relevant id. Can somebody point me in the right direction with this please its driving me nuts! Regards GT hello. i have a list that is pulling info from a db but the sub levels are not showing correctly. basically there are titles that could be in any order then under each title there are lists that could be in any order then some of the lists might also have nested lists which could be in any oder. its not the full html yet but I'm stuck because it echoes out the titles fine but the links are not being listed under each title. all the links are being listed under the first title only. Code: [Select] $PCa = PageContent::find_by_pageContID($PCidA); foreach ($PCa as $PCas) { $title = $PCas->title; $link = $PCas->link; echo' <div class="arrowlistmenu">'; if (!empty($title)) { echo' <h3 class="menuheader expandable">'."{$title}".'</h3>'; } if (!empty($link)) { echo' <ul class="categoryitems"> <li><a href="#">'."{$link}".'</a></li> </ul>'; } echo'</div>'; } this is an example of the html. Code: [Select] <div class="NAV"> <h3>CAT TITLE</h3> <ul class="CAT ITEM"> <li><a href="#">LINK</a></li> </ul> <h3>CATT TITLE</h3> <ul class="CAT ITEM"> <li><a href="#">LINK</a></li> <li><a href="#" class="SUB CAT">NESTED LEVEL TITLE</a> <ul class="SUB CAT ITEM" style="margin-left: 15px"> <li><a href="#">LINK</a></li> </ul> </li> <li><a href="#">LINK</a></li> </ul> </div> thanks Hi Everyone, I'm trying to use a while loop to dynamically include() .php files if a preg_match condition concerning the file name returns true, e.g. if ( $hDirectory = opendir($_SERVER["DOCUMENT_ROOT"])) { while (false !== ($strFileName = readdir($hDirectory))) { if ( pathinfo($strFileName, PATHINFO_EXTENSION ) == "php" ) { if ( preg_match("/frm_/", $strFileName) ) { include_once $strFileName; } } echo $strFileName; } closedir($hDirectory); } But, it doesn't seem to work as I thunked it would - the loop iterates several times but then unexpectedly exits, which is wrong because there are hundreds of .php files with 'frm_' in the filename!. Thoughly, as I did expect, should I comment out the include() statement all files names get echoed! and things are happy!!!! Analogiciously, I'm doing this because I'm lazy and want to be able to 'drop' .php files into the same directory and have my script automagically include them in my project save me from writing another freaking include statement! Am going about this the wrong way? If so, how did y'all get around the tedious task of having to write hundreds of bloody include() statements in your projects? I've seen this question asked a few times in Google-land, but not answered, which leds me to believe I'm doing something deliciously-evil. Cheers, Daniel I have a while loop nested inside of another while loop to populate a drop-down select box for each result from the parent while loop. The inner loop only gets run once though... any ideas on how to fix this without it being extremely data heavy? Hi All, Can any body let me know what is proper way to write below code? Quote while($row = mysql_fetch_array($result)) { for ($colq=0; $colq<=$col_no;$colq++) { while($col = mysql_fetch_array($result_display_sequences)) { for ($b=0; $b<=$seq_num;$b++) { echo $col[$b] . " "; while($asso = mysql_fetch_array($result_column_associated)) { for ($c=0; $c<=$asso_num;$c++) { echo $asso[$c] . " "; if ($col[$b] == $asso[$c]) { echo "<td>" . $row[$colq] . "</td>"; } } } } } } } I want to match two values before display the result but somehow at first level its work perfect but then its didnt increase value $b as it should. So i lil but confuse now what am i doing wrong with it. Sorry i am new and trying something hard assignment while test my skill. i do get result as below 2 2 3 4 5 6 7 8 9 10 11 3 4 5 6 7 8 9 10 11 Thanks in Advance. I've searched but can't seem to find anything I can apply to this situation. Most of the resources are dedicated to dropdown menu's from the same table. I have two tables 'regions' and 'cities' and I am looking to create a menu that lists all the cities within a region then moves on to do the same for the rest of the regions in that state: State1 Region1 City1 City2 City3 Region2 City1 City2 City3 Region3 Etc My tables: States table: stateID, state Regions table: regionID, region, stateID Cities table: cityID, city, regionID I currently have two pages- select region, then select city... I'd like to consolidate to one step after choosing a state. I know I need a nested loop, (while?), and to count the results somehow to retrigger loop; also not sure how to handle two mySQL querries in the nested loop. I'm having trouble wrapping my mind around it. Thank you. I have a problem with nested forms.. when i click the submit button at the bottom of the page i want it to take to display.php and when i click the upload button on the upload form code i do not want to refresh it. But right now when i click on upload button it takes me to display.php. Can someone help me out with the code? Code: [Select] <? include("db.php"); include("upload.php"); error_reporting(E_ALL ^ E_WARNING); ini_set("display_errors", 1); <script type="text/javascript"> function initUpload() { /*set the target of the form to the iframe and display the status message on form submit. */ document.getElementById('uploadform').onsubmit=function() { document.getElementById('uploadform').target = 'target_iframe'; document.getElementById('status').style.display="block"; } } //This function will be called when the upload completes. function uploadComplete(status){ //set the status message to that returned by the server document.getElementById('status').innerHTML=status; } window.onload=initUpload; </script> <style type="text/css"> .color { font-weight:bold; color:black; } </style> <div class="color"> <body bgcolor="white"> <center><h4><font color="blue">CREATE NEWSLETTER</font></h4></center> <table align="center" bgcolor="silver"> <form action="display.php" method ="post"> <tr> <td>Site: </td> <td> <select name="new_id"> <option value="">=============</option> <?php foreach($acronym as $key=>$value){ ?> <option value="<?php echo $value['site_id']; ?>"><?php echo $value['acronym']; ?></option> <?php }?> </select> </td> </tr> <tr> <td> Title: </td> <td><input type="text" size ="40" name="newsletter_title" /></td> </tr><tr> <td>Greeting:</td> <td><textarea rows="10" cols="80" name="greeting" ></textarea></td> </tr> <td> URL Title: </td> <td><input type="text" size ="40" name="url_title" /></td> </tr> <tr> <td> URL: </td> <td><input type="text" size ="40" name="newsletter_url" />Begin url with http://</td> </tr> <tr> <td align="center"> <b><font color="#214754" size="3">Banners</b></font> </td> </tr> <tr> <td>Banner Image URL: </td> <td><input type="text" size ="40" name="banner_url1" /> Banner Link: <input type="text" size ="40" name="banner_link_url1" /> </td> </tr> <tr> <td>Banner Image URL: </td> <td><input type="text" size ="40" name="banner_url2" /> Banner Link: <input type="text" size ="40" name="banner_link_url2" /> </td> </tr> <tr> <td>Banner URL: </td> <td><input type="text" size ="40" name="banner_url3" /> Banner Link: <input type="text" size ="40" name="banner_link_url3" /> </td> </tr> <tr> <td>Banner URL: </td> <td><input type="text" size ="40" name="banner_url4" /> Banner Link: <input type="text" size ="40" name="banner_link_url4" /> </td> </tr> <tr> <td align="center"> <b><font color="#214754" size="3">Threads</b></font> </td> </tr> <select name="category1"> <option value="">==========</option> <option value="registry">Registry</option> <option value="reviews">Reviews</option> <option value="classifieds">Classifieds</option> </select> </td> </tr> <tr> <td> Title: </td> <td><input type="text" size ="40" name="registry_title1" /></td> </tr> <tr> <td> Image: </td> <td><input type="text" size ="40" name="registry_img1" /></td> </tr> <tr> <td> URL: </td> <td><input type="text" size ="40" name="registry_url1" />Begin url with http://</td> </tr> <tr> <td height='12'></td> </tr> <tr> <td> Title: </td> <td><input type="text" size ="40" name="registry_title2" /></td> </tr> <tr> <td> Image: </td> <td><input type="text" size ="40" name="registry_img2" /></td> </tr> <td> <form id="uploadform" method="post" enctype="multipart/form-data" action="upload.php"> <input name="file" id="file" size="27" type="file" /><br /> <input type="submit" name="action" value="Upload" /> <span id="status" style="display:none">uploading...</span> <iframe id="target_iframe" name="target_iframe" src="" style="width:0;height:0;border:0px"></iframe> </form> </td> <tr> <td> URL: </td> <td><input type="text" size ="40" name="registry_url2" /></td> </tr> <tr> <td> <input type="submit" name="submit" value="submit" /> </td> </tr> </form> </table> </div> A WHILE loop in a FOR loop problem Script about links and sublinks from 1 table. In fact 2 questions about that. 1) In the FOR loop I have for example to do the loop 3 times. (needs to find 3 results withing the loop with if and else) When first time, he's gonna search within the WHILE loop that holds (for example) 10 records of the DB in a variable. He needs to search for rowid number 5, he found it He goes out of the WHILE loop and goes searching again but now for rowid number 2 Now it seem that the WHILE loop start searching for number 2 but won't start from his first row in the variable (10 rows from the db ). He start at row number 6 instead of beginning all over again !!! -> so the order of the numbers of rows MUST be in an ascending order, ortherwise he won't find them all ! But the numbers I have are NOT in an ascending order !!! Why doesn't the WHILE loop begin again from his row 1 in the variable ? FOR loop { WHILE loop { content here, break; } } 2) even when I get all the result in an ascending order, he won't go doing a second search but with a different rowid number that he gets from the FOR loop. It is giving me back indeed the right new rowid number, but the WHILE loop is doing nothing. I have put many echo "..."; and other stuff for checking but can't find the cause ! Here's the code : Code: [Select] // $ResultShow = 10 rows from mysql db if(isset($ResultShow)){ if (mysql_num_rows($ResultShow) >= 1){ //$linksuborder = "2,3,4"; $array1 = explode(",", $linksuborder); sort($array1); for ($n = 0; $n < count($array1); $n++){ // searchin for the right row id in the variable $ResultShow where we find the numbers for next loop $r1 = each($array1); While($Row2 = mysql_fetch_array($ResultShow)) { if($Row2["linkid"] == $r1['value']) // found it, now look for the numbers that we'll put in an array { echo "---here the content---"; // linksuborder is where numbers from row id's are stored like 5,2,8 //now put them in an array $array2 = explode(",", $Row2["linksuborder"]); sort($array2); for ($n2 = 0; $n2 < count($array2); $n2++){ $r2 = each($array2); ////// here searching for the sublinks ////// While ($Row3 = mysql_fetch_array($ResultShow)) { if($Row3["linkid"] == $r2['value']) // search for the right row id within the variable $ResultShow { echo "---here the content---"; break; // found it, so no need to do the rest of the loop } // end if } //end while ////// end searching for sublinks ////// } // end for } // end if else { echo "--- content here ---"; } } // end while } // end for } //end if } // end if Table : linkid linksuborder linktitle 1 2,3,4 2 9,7,8 mainlink1 3 10 mainlink2 4 mainlink3 5 6 7 sublink3 8 sublink2 9 sublink1 10 sublink4 -> linksuborder 2,3,4 are the row id's for the mainlink -> than we put the numbers 9,8,7 (also row id's) mentioned in row linkid 2 also in a new array -> now we can search for the sublinks -> get the details from row linkid 9, than 7, than 8 -> First mainlink is compleet, now go to row linkid 3 to do it all over again for the next mainlink... RESULTS from an sorted array -> sort($linksuborder); ------------------------------------------------------------- mainlink1 : sublink1, sublink2, sublink3 mainlink2 : **no result back but it should * mainlink 3 : **no result back but it should * All,
I am taking the output for every title in my Database and displaying it in a box. Within that box I am providing the opportunity to open another box with further content inside. The problem with the code below is that when you click on the expand button it expands in all the boxes, not just the one you are clicking in. I don't understand why this is happening when everything else is ok - any fixes and explanations are greatly appreciated:
// GOING THROUGH THE DATA if($result->num_rows > 0) { //echo "<hr />"; while($fetch=mysqli_fetch_array($result)) { $title=$fetch['title']; $feed_rss=$fetch['url']; $content_id=$fetch['content_id']; $source_image=$fetch['source_image']; $item_id = $fetch['item_id']; $item_title = $fetch['item_title']; $item_date = $fetch['fetch_date']; $item_description = $fetch['item_description']; $item_url = $fetch['item_url']; ///////////////////////////////////////////////////////////////////////////////// // ?> <div class="box col5"> <?php $query_string = "cid={$content_id}&t={$item_id}&item_title={$item_title}"; $url_query_string = "http://www.disciply.com/article/index.php?" . $query_string; /*Start of dynamic content open*/ echo "<p>$title</p>"; echo "<img src=$source_image />"; echo "<p>item_url = $item_url</p>"; ?> <div class="panel_button" style="display: visible;"><img src="../images/expand.png" alt="expand"/> <a href="#"><?php echo $item_title; ?></a></div> <div class="panel_button" id="hide_button" style="display: none;"><img src="../images/collapse.png" alt="collapse" /> <a href="#">Hide</a> <object type="text/html" data='<?php echo $item_url;?>' width="100%" height="800px" style="overflow:auto;border:5px ridge blue"> </object> </div> </div> Edited by genista, 19 July 2014 - 10:33 PM. This is the email verification script im using.. //email verify $activationKey = mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand(); $sql="INSERT INTO account_info (activation_key, status) VALUES ('$activationKey', 'verify')"; if (!mysql_query($sql)){ exit('Error: ' . mysql_error()); } else { //Send activation Email $to = $_POST['email']; $subject = "NarutoRPG.com Registration"; $message = "Welcome to our website! You, or someone using your email address, has completed registration at narutoRPG.com. You can complete registration by clicking the following link:\rhttp://www.arzania.com/verify.php?$activationKey\r\r If this is an error, ignore this email and you will be removed from our mailing list.\r\rRegards,\ narutoRPG.com Team"; $headers = 'From: ashyiscool2@gmail.com' . "\r\n" . 'Reply-To: ashyiscool2@gmail.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); //User isn't registering, check verify code and change activation code to null, status to activated on success $queryString = $_SERVER['QUERY_STRING']; $query = "SELECT * FROM account_info"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ if ($queryString == $row["activation_key"]){ echo "Congratulations!" . " " . $row["username"] . " is now the proud new owner of a NarutoRPG.com account. Login to begin to play."; $sql="UPDATE account_info SET activation_key = '', status='activated' WHERE (id = $row[id])"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } } } } } include "footer.php"; ?> For some reason, when the person is registered it shows everyones name who registered, for example.. You've been successfully registered!Congratulations! tonyhh is now the proud new owner of a NarutoRPG.com account. Login to begin to play.Congratulations! tonyh is now the proud new owner of a NarutoRPG.com account. Login to begin to play.Congratulations! tony is now the proud new owner of a NarutoRPG.com account. Login to begin to play.etc...etc.. How can you make it only repeat the users name who registered, not everyone? hi The output of this code is: 1950 1951 1952 .... script Code: [Select] <?php for ($i = 1950; $i < 2012; $i++) { echo "<option value='$i' class='dr'>".$i.'</option>'; } ?> but i need something like: Insert a date 1950 1951 1952 .... how can i solve that? welll. i can do <option value='null' class='dr'> year</option> |