PHP - Category Listing : Date Filter
Hey all,
I just joined this forum so thank you! I am a regular contributor over at CssCreator.com, but i got stuck at a php problem and so came here to seek some guidance from you folks! I am working on a new site project at foliageoutdoors.com/newsite. This site is a travel company that i work for and its got fixed departure tours to different destination. 1 destination can i have multiple departures (batch). So i have split my table structure like this - Destination id, title, description, etc Batch id, destination_id, datefrom, dateto, charges, etc Here is my problem : When i go to a listing, I want to show all destinations with batches starting from tomorrow+. I have written the sql queries, but they are not doing what i want. It would really help if someone can help me out with this! I want someone to look at the complete code, so please PM / reply me and i will share the file. Code: [Select] <?php $todaysdate = date("Y-m-d H:i:s"); $category = $_GET['title']; $getcategory = "SELECT destination.*, batch.* FROM `destination` LEFT JOIN batch ON destination.id = batch.destination_id WHERE destination.category = '".$category."' GROUP BY batch.destination_id"; $result = mysql_query($getcategory); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Foliage Outdoors.com | <?php echo $category; ?></title> <link rel="stylesheet" href="http://<? echo $topsiteurl; ?>/css/structure.css" type="text/css"/> <link rel="stylesheet" href="http://<? echo $topsiteurl; ?>/css/category.css" type="text/css"/> </head> <body> <div id="maincontainer"> <div id="header"> <?php include_once($_SERVER['DOCUMENT_ROOT'].'/newsite/includes/header.php') ?> </div> <div id="bodycontainer"> <? while ($db_row = mysql_fetch_assoc($result)) { $id = $db_row['id']; $desc = $db_row['desc']; $siteurl = $_SERVER['SERVER_NAME']; $title = $db_row['title']; $url = $db_row['url']; $photo = $db_row['photo']; $highlights = $db_row['highlights']; echo("<div class='camp'><div class='title'><img src='http://".$topsiteurl.'/images/destinations/'.$photo.".jpg' class='Destination Images' alt = '".$photo."' /> <a href=http://".$topsiteurl.'/destinations/destinations.php?id='.$id.">".$title."</a></div> <div class='description'>".$highlights."</div>"); $getbatch ="SELECT * FROM batch WHERE destination_id = ".$id." AND date_from > '".$todaysdate."'"; $result2 = mysql_query($getbatch); echo ("<div class='dates'>Batch Dates:<br />"); while ($db_row=mysql_fetch_assoc($result2)){ $batchfrom = $db_row['date_from']; $newDate = date("j-F-Y", strtotime($batchfrom)); $batchto = $db_row['date_to']; $EndwDate = date("j-F-Y", strtotime($batchto)); $code = $db_row['code']; $campfor = $db_row['campfor']; $diff = abs(strtotime($EndwDate) - strtotime($newDate)); $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)); if ($newDate != '') { echo ("".$newDate." - ".$EndwDate."||".$days."(days)<br />"); } else { echo ("<div>Sorry! There are no batches scheduled currently! Contact us for a custom tour</div>"); }}; echo ("</div><div class='gallery'>Photo-Gallery | Video Gallery</div></div>");} mysql_close(); ?> </div> </div> </div> </body> </html> Regards, Mihir. Similar TutorialsI have an image gallery with different categories, at the moment the list of categories is simple and just looks like this... General (10) I would like to be able to upload an image when making new categories and display it like this... Can anybody help me with this, here are the pages of code... This is the page that displays the category listing... Code: [Select] <?php include("config.inc.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Roy Neale - Gallery</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/prototype.js"></script> <script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script> <script type="text/javascript" src="js/lightbox.js"></script> <link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" /> </head> <body> <div id="head"> <div id="headmain"> <div id="headleft"> <image src="images/bannertop.jpg"> </div> <div id="headright"> <div class="navimage"><image src="images/gallery3.png" onmouseover="this.src='images/gallery2.png'" onmouseout="this.src='images/gallery3.png'"></image><!--start navimage--> </div><!--end navimage--> <div class="navimage"><image src="images/about.png" onmouseover="this.src='images/about2.png'" onmouseout="this.src='images/about.png'"></image><!--start navimage--> </div><!--end navimage--> <div class="navimage"><image src="images/contact.png" onmouseover="this.src='images/contact2.png'" onmouseout="this.src='images/contact.png'"></image><!--start navimage--> </div><!--end navimage--> </div> </div> </div> <div id="mid"> <div id="midleft"> <p> </p> <p> </p> <p> </p> Login <p> </p> <p align="center"><form action="gallery.php" method="post" name="loginform"> <label>Username: </label><input name="username" type="text" class="userpass" size="25" maxlength="25" /> <label>Password: </label><input name="password" type="password" class="userpass" size="25" maxlength="25" /> <p><label></label><input name="submit" type="submit" class="logbutton" value="LOGIN" /></p> </form></p> </div> <div id="midright"> <div id="midrighttop5"> </div> <div id="midrightbottom4"> <?php // initialization $result_array = array(); $counter = 0; $cid = (int)($_GET['cid']); $pid = (int)($_GET['pid']); // Category Listing if( empty($cid) && empty($pid) ) { $number_of_categories_in_row = 3; $result = mysql_query( "SELECT c.category_id,c.category_name,COUNT(photo_id) FROM gallery_category as c LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id GROUP BY c.category_id" ); while( $row = mysql_fetch_array( $result ) ) { $result_array[] = "<a href='gallery.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")"; } mysql_free_result( $result ); $result_final = "<tr>\n"; foreach($result_array as $category_link) { if($counter == $number_of_categories_in_row) { $counter = 1; $result_final .= "\n</tr>\n<tr>\n"; } else $counter++; $result_final .= "\t<td>".$category_link."</td>\n"; } if($counter) { if($number_of_categories_in_row-$counter) $result_final .= "\t<td colspan='".($number_of_categories_in_row-$counter)."'> </td>\n"; $result_final .= "</tr>"; } } // Thumbnail Listing else if( $cid && empty( $pid ) ) { $number_of_thumbs_in_row = '1'; $result = mysql_query( "SELECT photo_id,photo_caption,photo_filename FROM gallery_photos WHERE photo_category='".addslashes($cid)."'" ); $nr = mysql_num_rows( $result ); if( empty( $nr ) ) { $result_final = "\t<tr><td>No Gallery found</td></tr>\n"; } else { while( $row = mysql_fetch_array( $result ) ) { $result_array[] = "<a href='".$images_dir."/full_".$row[2]."' rel=\"lightbox\"><img src='".$images_dir."/tb_".$row[2]."' border='3' style='margin: 4px;' bordercolor='silver' alt='".$row[1]."' /></a>"; } mysql_free_result( $result ); $result_final = "<tr>\n"; foreach($result_array as $thumbnail_link) { if($counter == $number_of_thumbs_in_row) { $counter = 1; $result_final .= "\n</tr>\n<tr>\n"; } else $counter++; $result_final .= $thumbnail_link; } if($counter) { if($number_of_photos_in_row-$counter) $result_final .= "\t<td colspan='".($number_of_photos_in_row-$counter)."'> </td>\n"; $result_final .= "</tr>"; } } } // Full Size View of Photo else if( $pid ) { $result = mysql_query( "SELECT photo_caption,photo_filename FROM gallery_photos WHERE photo_id='".addslashes($pid)."'" ); list($photo_caption, $photo_filename) = mysql_fetch_array( $result ); $nr = mysql_num_rows( $result ); mysql_free_result( $result ); if( empty( $nr ) ) { $result_final = "\t<tr><td>No Photo found</td></tr>\n"; } else { $result = mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes($cid)."'" ); list($category_name) = mysql_fetch_array( $result ); mysql_free_result( $result ); $result_final .= "<tr>\n\t<td> <a href='gallery.php'>Categories</a> > <a href='gallery.php?cid=$cid'>$category_name</a></td>\n</tr>\n"; $result_final .= "<tr>\n\t<td align='center'> <br /> <img src='".$images_dir."/".$photo_filename."' border='0' alt='".$photo_caption."' /> <br /> $photo_caption </td> </tr>"; } } // Final Output echo <<<__HTML_END <table width='100%' border='0' align='left' style='margin: 6px;' style='padding: 5px;'> $result_final </table> </div> </div> </div> <div id="foot"> <div id="footmain"> <div id="footmainr"> <image src="images/copyright.png"> </div> </div> </div> </body> </html> __HTML_END; ?> And this is the page where i add new categories... Code: [Select] <?php include("config.inc.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Roy Neale - Gallery</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="head"> <div id="headmain"> <div id="headleft"> <image src="images/bannertop.jpg"> </div> <div id="headright"> <div class="navimage"><a href="gallery.php"><img border="0" image src="images/gallery3.png" onmouseover="this.src='images/gallery2.png'" onmouseout="this.src='images/gallery3.png'"></image></a><!--start navimage--> </div><!--end navimage--> <div class="navimage"><image src="images/about.png" onmouseover="this.src='images/about2.png'" onmouseout="this.src='images/about.png'"></image><!--start navimage--> </div><!--end navimage--> <div class="navimage"><image src="images/contact.png" onmouseover="this.src='images/contact2.png'" onmouseout="this.src='images/contact.png'"></image><!--start navimage--> </div><!--end navimage--> </div> </div> </div> <div id="mid"> <div id="midleft"> </div> <div id="midright"> <div id="midrighttop3"> </div> <div id="midrightbottom2"> <?php if (isset($_POST['submit'])): $category_name = $_POST['category_name']; mysql_query( "INSERT INTO gallery_category(`category_name`) VALUES('".addslashes( $category_name )."' )" ); if (@mysql_query($sql)) { echo('<p>New category added</p>'); } else { echo('<p>New category added</p>'); } ?> <p><a href="<?=$_SERVER['PHP_SELF']?>">Add another category</a></p> <?php else: // Allow the user to enter a new category ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <p><br /> New Category: <input type="text" name="category_name" size="20" maxlength="255" /><br /> <input type="submit" name="submit" value="SUBMIT" /></p> </form> <?php endif; ?> <p><a href="preupload2.php">Back to Upload</a></p> </div> </div> </div> <div id="foot"> <div id="footmain"> <div id="footmainr"> <image src="images/copyright.png"> </div> </div> </div> </body> </html> I assume i just need to edit a few mysql queries add another upload form and a few new fields or tables to my database, but i dont know how yet. good day dear experts,
<?php /** * OSM Overpass API with PHP SimpleXML / XPath * * PHP Version: 5.4 - Can be back-ported to 5.3 by using 5.3 Array-Syntax (not PHP 5.4's square brackets) */ // // 1.) Something is wrong an OSM Overpass API Endpoint // $Something is wrong = 'node ["addr:postcode"~"RM12"] (51.5557914,0.2118915,51.5673083,0.2369398)->.point; ( node (around.point:100000) ["amenity"~"school"]; way (around.point:100000) ["amenity"~"school"]; ); out;'; $context = stream_context_create(['http' => [ 'method' => 'POST', 'header' => ['Content-Type: application/x-www-form-urlencoded'], 'content' => 'data=' . urlencode($Something is wrong), ]]); # please do not stress this service, this example is for demonstration purposes only. $endpoint = 'http://overpass-api.de/api/interpreter'; libxml_set_streams_context($context); $start = microtime(true); $result = simplexml_load_file($endpoint); printf("Something is wrong returned %2\$d node(s) and took %1\$.5f seconds.\n\n", microtime(true) - $start, count($result->node)); // // 2.) Work with the XML Result // # get all school nodes with xpath $xpath = '//node[tag[@k = "amenity" and @v = "school"]]'; $schools = $result->xpath($xpath); printf("%d School(s) found:\n", count($schools)); foreach ($schools as $index => $school) { # Get the name of the school (if any), again with xpath list($name) = $school->xpath('tag[@k = "name"]/@v') + ['(unnamed)']; printf("#%02d: ID:%' -10s [%s,%s] %s\n", $index, $school['id'], $school['lat'], $school['lon'], $name); }
FATAL ERROR syntax error, unexpected 'is' (T_STRING) on line number 11
well at the moment i try to make up my mind what is going on here i have a table that shows payments made but want to the payments only showing from a set date(06/12/14) and before this date i dont want to show
this is my sql that doesnt seem to work and is showing dates before the specified date.
.
"SELECT * FROM payments2014, signup2014, editprop2014 WHERE signup2014.userid = payments2014.payment_userid AND editprop2014.prop_id = signup2014.prop_id AND signup2014.userid !='page1' AND signup2014.userid !='page6' AND signup2014.userid !='page4' AND payments2014.payment_transaction_status !='none' AND payments2014.payment_transaction_status !='CANCELLEDa' AND payments2014.payment_type !='deposit' AND payments2014.payment_paid_timestamp NOT LIKE '%2012%' AND payments2014.payment_paid_timestamp NOT LIKE '%2011%' AND payments2014.payment_paid_timestamp >= '06/12/14' ORDER BY payments2014.payment_id DESC"i have some other parts in the statment but this one that should be filtering is host_payments2014.payment_paid_timestamp >= '06/12/14'thanks in advance I'm not sure why but I copied the correct syntax from the wp codex page for it to display the date and title which it displays the titles for the categories however it only displays the date for the headlines category and don't know why. Any answers? <?php get_header(); ?> <div id="left"> <div id="col1"> <img id="lp" src="../images/lp.jpg" alt="Latest Promo"> <img class="newslogos" src="../images/headlines.jpg" alt="DW Headlines"> <div class="mininews"> <?php //The Query query_posts('category_name=headlines'); //The Loop while (have_posts()) : the_post(); ?> <h3 class="date"><?php the_date(); ?></h3> <h4 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4> <?php endwhile; //Reset Query wp_reset_query(); ?> </div> <!-- End of main news div (headlines) --> <img class="newslogos" src="../images/rumors.jpg" alt="DW Rumors"> <div class="mininews"> <?php //The Query query_posts('category_name=rumors'); //The Loop while (have_posts()) : the_post(); ?> <h3 class="date"><?php the_date(); ?></h3> <h4 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4> <?php endwhile; //Reset Query wp_reset_query(); ?> </div> <!-- End of main news div (rumors) --> <img class="newslogos" src="../images/columns.jpg" alt="DW Columns"> <div class="mininews"> <?php //The Query query_posts('category_name=columns'); //The Loop while (have_posts()) : the_post(); ?> <h3 class="date"><?php the_date(); ?></h3> <h4 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4> <?php endwhile; //Reset Query wp_reset_query(); ?> </div> <!-- End of main news div (columns) --> </div> <!-- End of col1 --> </div> <!-- End of left --> <div id="right"> </div> <?php get_footer(); ?> I have a script that allows me to sort user submitted data either by category OR by date and I'd like to accomplish both at the same time, so my question is how can I do that? This is my script: <?php $select_category = $_REQUEST['sort_category']; $sort_date_var = $_REQUEST['sort_date']; // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (($select_category == 'All') || (!isset($select_category)) && (!isset($sort_date_var))) { // Retrieve the chosen category from MySQL $query3 = "SELECT * FROM con"; $data3 = mysqli_query($dbc, $query3); //Loop through the array of data while ($row3 = mysqli_fetch_array($data3)) { echo "<table class='knuffixTable'>"; // Display the score data echo "<tr><td class='knuffix_name'>"; echo "<strong>" . htmlentities($row3['name']) . "</strong><br /></td></tr>"; echo "<tr><td class='knuffix_contribution'><pre>" . $row3['contribution'] . "</pre><br /></td></tr>"; echo "<tr><td class='knuffix_categoryDate'>" . $row3['category'] . " | " . date('M d, Y', strtotime($row3['contributed_date'])) . " </td></tr>"; echo "</table>"; } mysqli_close($dbc); } if ($select_category) { // Retrieve the chosen category from MySQL $query2 = "SELECT * FROM con WHERE category = '$select_category'"; $data2 = mysqli_query($dbc, $query2); //Loop through the array of data while ($row2 = mysqli_fetch_array($data2)) { echo "<table class='knuffixTable'>"; // Display the score data echo "<tr><td class='knuffix_name'>"; echo "<strong>" . htmlentities($row2['name']) . "</strong><br /></td></tr>"; echo "<tr><td class='knuffix_contribution'><pre>" . $row2['contribution'] . "</pre><br /></td></tr>"; echo "<tr><td class='knuffix_categoryDate'>" . htmlentities($row2['category']) . " | " . date('M d, Y', strtotime($row2['contributed_date'])) . " </td></tr>"; echo "</table>"; } mysqli_close($dbc); } // SORT DATE BLOCK if ($sort_date_var) { // Retrieve the chosen category from MySQL $query4 = "SELECT * FROM con ORDER BY contributed_date $sort_date_var"; $data4 = mysqli_query($dbc, $query4); //Loop through the array of data while ($row4 = mysqli_fetch_array($data4)) { echo "<table class='knuffixTable'>"; // Display the score data echo "<tr><td class='knuffix_name'>"; echo "<strong>" . htmlentities($row4['name']) . "</strong><br /></td></tr>"; echo "<tr><td class='knuffix_contribution'><pre>" . $row4['contribution'] . "</pre><br /></td></tr>"; echo "<tr><td class='knuffix_categoryDate'>" . htmlentities($row4['category']) . " | " . date('M d, Y', strtotime($row4['contributed_date'])) . " </td></tr>"; echo "</table>"; } mysqli_close($dbc); } ?> The first block is the default state where ALL the data is being shown when the site is being visited. The second block sorts by category and the third by date. The problem is that only ONE of the last two blocks work at a time and I would like to have a combination of date and category sorting. Thanks for all the suggestions. I have designed a simple page to get meeting room details to display on our dashboards. I would like to filter for today's date (start date) and then sort by room name (name) if possible: (if you believe this could be written better (the server is on php 5.4) then also please let me know:
$ch = curl_init($url);
$response = strip_tags($response);
{ ?>
</body> Hello, I have been searching and trying all sorts of ways to get my sub categories drop down to show the correct info after selecting a category from the main drop down but im getting stuck. It's pulling the categories and sub categories from the mysql database fine but no matter which main category i pick it keeps showing the same result in the sub category. My brother said i need to use some sort of onchange do this so the sub category list refreshs but everything i have tried doesn't work.. PLEASE could some one help. MANY MANY THANKS This is the category form Code: [Select] <select name="job_cats" style="width:165px"> <?PHP $query1 = "SELECT * FROM job_cats"; $result1 = mysql_query($query1) or die ("query 1 failed"); $count1 = mysql_num_rows($result1); for ($i = 0; $i < $count1; $i++) { $row1 = mysql_fetch_array($result1); $job_cats_title1 = $row1['title']; $job_cats_id1 = $row1['id']; echo '<option value="'.$job_cats_id1.'">'.$job_cats_title1.'</option>'; echo $job_cats_id1; } ?> </select> this would echo this in the main category list: cat1 cat2 cat3 cat4 this is the sub category form Code: [Select] <select name="job_sub_cats" style="width:165px"> <?PHP $query1 = "SELECT * FROM job_sub_cats WHERE job_cats_id = $job_cats_id1"; $result1 = mysql_query($query1) or die ("query 1 failed"); $count1 = mysql_num_rows($result1); for ($i = 0; $i < $count1; $i++) { $row1 = mysql_fetch_array($result1); $sub_cats_id1 = $row1['id']; $sub_cats_title1 = $row1['subTitle']; $cats_id1 = $row1['job_cats_id']; echo '<option value="'.$sub_cats_id1.'">'.$cats_id1.'</option>'; } ?> </select> this should echo this: 1 2 3 4 but it keeps echoing just the number 4. THANKS PLEASE HELP ricky Hey, I'm using a script which allows you to click on a calendar to select the date to submit to the database. The date is submitted like this: 2014-02-08 Is there a really simple way to prevent rows showing if the date is in the past? Something like this: if($currentdate < 2014-02-08 || $currentdate == 2014-02-08) { } Thanks very much, Jack Hope I am in the right area. I am working on a project which is sort of a business directory. I have a category table, a sub-category table then the actual account table. So a user clicks on the category, then selects the sub-category to view information of accounts in that category, and then be able to click to see the full profile. Here's where I am getting stuck. A user may be listed in more than one sub. As an example, let's say a parent is Cars, then subs might be New, Used, Parts, etc. Now a particular user might be listed under all three subs. How can I link them? I have my cat/sub linked via parent/child id's. However, how can I get the user to be linked to multiple subs? Would I need to create a separate table to do similar to parent/child of the categories? If so, then how would I insert the multiple id's into the table? I assume at this point that I would use drop downs for the subs. I am having a real hard time wrapping my head around this so any help is greatly appreciated. An array of "categories" is given: $categories = array( array("id" => 1, "title" => "Pants", "children" => array( array("id" => 2, "title" => "Boots", "children" => array( array("id" => 3, "title" => "Leather"), array("id" => 4, "title" => "Textile"), ), ), array("id" => 5, "title" => "Sneakers"), ), ), array( "id" => 6, "title" => "Sort", "children" => array( array( "id" => 7, "title" => "Balls", ), ), ), );
I need to write a function searchCategory ($categories, $id) that returns the name of the category by the category ID. So I am having some difficulties with a category system. I want my code to search the database an unlimited amount of times to the very last directory and then display it in tree view on my screen. I'm having some trouble because I am having to specify how many depths the code will search. How can I get it to do this on it's own? Currently my code does this... <?php // Establish SQL Connection. $mysqli = mysqli_connect( $sql['host'], $sql['user'], $sql['pass'], $sql['db'] ) or die( "DARN"); $query = $mysqli->query( "SELECT * FROM folders ORDER BY name ASC" ); $num_rows = $query->num_rows; echo "Found <b>" . $num_rows . "</b> row(s) in the database!<br>"; while ( $row = mysqli_fetch_array( $query ) ) { // DO NOT REMOVE $id = $row['id']; $name = $row['name']; $parent = $row['parent']; /***************************************************************************************************/ if ( $parent == 0 ) { echo $id . " " . $name . " " . $parent . "<br>"; $query2 = $mysqli->query( "SELECT * FROM folders WHERE parent = " . $id . " ORDER BY name ASC" ); while ( $row2 = mysqli_fetch_array( $query2 ) ) { echo " " . $row2['name'] . "<br>"; } } } ?>I know it's messy, doing the best I can. DB looks a little like this... +----+---------+--------+ I have the following result that I am getting from a source. Code: [Select] SimpleXMLElement Object ( [CategoryID] => 1 [Name] => Other [Order] => 0 [link] => http://www.link.com?sub=1 ) SimpleXMLElement Object ( [CategoryID] => 1233916011 [Name] => ceramic [Order] => 1 [ChildCategory] => SimpleXMLElement Object ( [CategoryID] => 1234016011 [Name] => dish [Order] => 1 ) [link] => http://www.link.com?sub=13476 ) SimpleXMLElement Object ( [CategoryID] => 1233917011 [Name] => laminate [Order] => 2 [link] => http://www.link.com?sub=98247 ) I need to get it into a database with the following structure Code: [Select] id categoryID cName cOrder clink cparent By using Code: [Select] foreach($this->resp->Store->CustomCategories->CustomCategory as $cat) { $sub = $cat->CategoryID; $ord = $cat->Order; $linkto = "$stlink?fsub=$fsub"; $nm = htmlspecialchars($cat->Name); $par=$cat->ChildCategory->Order; $query = "INSERT INTO Cat (categoryID,cName,cOrder,clink,cparent) VALUES ('$sub','$nm','$ord','$linkto','$par')"; $result = @mysql_query ($query); // Run the query. } I can get Code: [Select] id categoryID cName cOrder clink cparent 1 1 Other 0 http://www.link.com?sub=1 0 2 1233916011 ceramic 1 http://www.link.com?sub=13476 0 2 1233917011 laminate 2 http://www.link.com?sub=98247 0 But I need to get the ChildCategory in there w/ cparent like Code: [Select] id categoryID cName cOrder clink cparent 1 1 Other 0 http://www.link.com?sub=1 0 2 1233916011 ceramic 1 http://www.link.com?sub=13476 0 3 1234016011 dish 1 1 <--- like this 4 1233917011 laminate 2 http://www.link.com?sub=98247 0 any help appreciated... Hey guys I have found this peice of code and messed around with it. I got it to work with Thickbox and I would like to know how to seperate my images aka files to every 4th column. Heres the code I found and tweaked. The images would look great if it was every 4th column they break. Also where would I place he echo command if I want it to display information about that image. Heres the code... Code: [Select] <? /** * Change the path to your folder. * * This must be the full path from the root of your * web space. If you're not sure what it is, ask your host. * * Name this file index.php and place in the directory. */ // Define the full path to your folder from root $path = "images/default/"; // Open the folder $dir_handle = @opendir($path) or die("Unable to open $path"); // Loop through the files while ($file = readdir($dir_handle)) { if($file == "." || $file == ".." || $file == "default.php" ) continue; echo "<a href=\"images/default/$file\" class=\"thickbox\"><img src=\"images/default/$file\" height=\"150\" width=\"150\" border=\"0\"></a>"; } // Close closedir($dir_handle); ?> I have a mysql database set up with 4 fields - id, month, day, event. The database will be filled with something like: month=Jan, day=4 and event=Meeting. All are text fields. The display will be Jan. 4: Meeting I can set up the PHP to display the database in a unordered list. The code for this is: <?php $result = @mysql_query("SELECT id, month, day, event FROM homecalendar"); if (!$result) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); } while ($row = mysql_fetch_array($result)) { echo '<li>' . $row['month'] . $row['day'] .': ' . $row['event'] . '</li>' ; } ?> How can I limit the code to display items for only the current month and the next month? I am trying to have an event with each performance listed for the event underneath. I have worked with the MySQL Forum and have gotten to the point where my coding for MySQL is complete, but it still will not work. I was told from the MySQL Forum group that I need to now post these in this forum... Here's how I tried the coding: Code: [Select] <p class="categoryHeader">Theatre</p><?php $last_eventtitle = NULL; // remember the last EventTitle while ($Row = mysqli_fetch_assoc($TheatreResult)){ $eventtitle = $Row['EventTitle']; if($last_eventtitle != $eventtitle){ // a new or the first EventTitle was found echo '<p>'; if($Row['Ranking']<10){ echo '<img src="http://www.myalaskacenter.com/images/logos/acpa/weblogo-small_nowords.jpg" alt="Alaska Center for the Performing Arts" width="80" height="80" border="0" align="right">'; } if ($Row['FreeEvents']==TRUE){ echo '<img src="http://www.myalaskacenter.com/images/free.gif" alt="Free Event" width="67" height="64" align="right" border="0">'; } echo '<a href="' . $Row['ShoWareEventLink'] . '"><img src="https://alaskapac.centertix.net/UPLImage/' . $Row['thumb'] . '" alt="' . $Row['EventTitle'] . '" title="' . $Row['EventTitle'] . '" align="left" border="0" style="padding-right:5px"><span class="Heading3_blue"><br />' . $Row['EventTitle'] . '</span>'; echo '<br />Presented by <a href="' . $Row['website'] .'" target="_blank">' . $Row['Presenter'] . '</a><br />'; if($last_eventtitle != NULL){ // not the first EventTitle, close out the previous section echo '<br />'.date("l, F j, Y", strtotime($Row['startDateTime']). ' at ' . date("g:i a", strtotime($Row['startDateTime']))).' - <a href="'.$Row['VenueSite'].'" target="_blank">'.$Row['VenueName'].'</a>'; } $last_eventtitle = $eventtitle; // save the new EventTitle // output the heading/start a new section echo '<br />'.date("l, F j, Y", strtotime($Row['startDateTime']). ' at ' . date("g:i a", strtotime($Row['startDateTime']))).' - <a href="'.$Row['VenueSite'].'" target="_blank">'.$Row['VenueName'].'</a>'; echo '<br /><br /></p><hr>'; } } ?> Now it lists the first performances correctly; although it does NOT list the correct number of performances and the first performance is sometimes listed twice -- so almost there. See webpage http://www.myalaskacenter.com/centermail/_upcomingevents.php. For example, Anchorage Youth Symphony only has one performance, but it lists 2; while It's a Wonderful Life has 17 performances, but it lists only 2. What am I doing wrong still? Hi friends, i want to ask a question. i have two page: "slider.php" and "mansethaberler.php" i extract two data from the database, named "addnews_headline" and "addnews_image" in slider.php. i create link to extracted "headline" from the database. See i added first image. when i clicked the link, link is heading to the second page "mansethaberler.php" and in "mansethaberler.php" with "SELECT" i extract from database "headline" and "image". Now i want to do that. When i clicked the link in "slider.php" i want to listing the image and headline in "mansethaberler.php". "mansethaberler.php" <?php $veri = $db->query("SELECT * FROM haberlerekle ORDER BY haberekle_id",PDO::FETCH_ASSOC)->fetchAll(); ?> <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12"> <?php foreach ($veri as $haber) { ?> <div style="border:1px solid black; height:50px; background-color:#17a2b8; color:white; line-height:50px; text-align:center;"><?php echo $haber["habereklesayfasi_baslik"]; ?></div> <div class="row no-gutters"> <img class="col-lg-12 mt-2" src="upload/images/<?php echo $haber["haberekle_resim"]; ?>" style="max-height:444px;"> </div> </div> <div class="col-lg-12 ml-auto mt-1 mb-1" style="padding-left:7px;"><?php echo $haber["haberekle_konu"]; } ?></div> "slider.php" <img src="upload/images/<?php echo $row["haberekle_resim"]; ?>" width="832" height="502"> <!-- upload/images/ ile <?php ?> tag'leri arasında boşluk olursa link kırılıyor. Resim çıkmıyor. --> <div class="carousel-caption"> <p><a href="mansethaberler.php"><?php echo $row['haberekle_baslik']; ?></a></p> </div>
Edited August 19, 2020 by CodingStudent i forgot to put the most important codes directory listing: hi guys, im using a PHP script to output a list of documents in different directory's using a single index.php (apart from the style obv), its not a major issue but bugging me as to how to get it to ignore the "up" link for directory navigation. its outputting the below: . .. this is annoying me... is it possible to get it to ignore these and not output them? Code: [Select] <link rel="stylesheet" type="text/css" href="style.css"> <span class="note"> <?php echo "directoryname3"; ?></span> <?php $dir="directoryname3"; if ($dir_list = opendir($dir)) { while(($filename = readdir($dir_list)) !== false) { ?> <p><a href="<?php echo $filename; ?>"><?php echo $filename; ?></a></p> <?php } closedir($dir_list); } ?> <br><br> <span class="note"> <?php echo "<b>directoryname3</B>"; ?></span> <?php $dir="directoryname3"; if ($dir_list = opendir($dir)) { while(($filename = readdir($dir_list)) !== false) { ?> <p><a href="<?php echo $filename; ?>"><?php echo $filename; ?></a></p> <?php } closedir($dir_list); } ?> <br><br> <span class="note"> <?php echo "<b>directoryname3</B>"; ?></span> <?php $dir="directoryname3"; if ($dir_list = opendir($dir)) { while(($filename = readdir($dir_list)) !== false) { ?> <p><a href="<?php echo $filename; ?>"><?php echo $filename; ?></a></p> <?php } closedir($dir_list); } ?> <br><br> <span class="note"> <?php echo "<b>directoryname</B>"; ?></span> <?php $dir="directoryname"; if ($dir_list = opendir($dir)) { while(($filename = readdir($dir_list)) !== false) { ?> <p><a href="<?php echo $filename; ?>"><?php echo $filename; ?></a></p> <?php } closedir($dir_list); } ?> Ok so I don't even know where to start with this idea so I thought I would poke around here for some inspiration. On my server I have a Directory. In that directory I have roughly 300 folders with 5,000 files + 1 index.php (so 5,001 files but I want to ignore the index.php in the listings) per directory. Anyway what I am trying to do is list all the files and load them into a database. What my ideal goal would be is device a script that I would put in the root directory with the 300 or so subdirectories and let it run through the directories automatically one by one, listing all the files in them and then storing them in the database. I'd break it down more but that part I can figure out on my own cause I do want to do more than just store the file names and corresponding directory its in in the DB. My issue is I can find anything or figure anything out that will cycle through all directories, thats what I need to figure out first. Hi friends, I have two mysql db tables, photos and album, I would like to list photos by album how do i do that ? CREATE TABLE `album` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `album_name` varchar(95) NOT NULL, `album_desc` text NOT NULL, PRIMARY KEY (`id`) ); CREATE TABLE `photos` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `album_id` int(11) NOT NULL, `thumb_name` varchar(255) NOT NULL, `photo_name` varchar(250) NOT NULL, PRIMARY KEY (`id`) ) |