PHP - Showing Results While Loop Continues....?
So I have 2 queries, that has the potential to return alot of data, foreach loops running. The first shows each group heading, and the foreach nested is calling another query specific to the group heading. The result currently is a lengthy delay in results showing. (Now this may/may not be the most ideal code practise in this instance however... short term solution discussion please).
For Each State Read Each States Details from DB For Each State Listing Display Details Next Next Is there a command or other where I can say, Display HTML page as it stands while it continues to process the FOREACH loops? EG: For Each State Read Each States Details from DB For Each State Listing Display Details REFRESH HTML DISPLAYED Next Next Similar TutorialsI am working to echo the results in a while or for loop... Both of my sample codes work, but the results are wrong! The while loop ONLY echos a result IF the first record in the postings table matches the id passed (does not display a result unless the first record has a match) The if loop displays ALL listings with the same name (counts them all) so there are no unique listings! <?php $posts_by_city_sql = "SELECT * FROM postings WHERE id='$_GET[id]'"; $posts_by_city_results = (mysqli_query($cxn, $posts_by_city_sql)) or die("Was not able to grab the Postings!"); /* While Loop */ while($posts_by_city_row = mysqli_fetch_array($posts_by_city_results)) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } /* For Loop */ $posts_by_city_row = mysqli_fetch_array($posts_by_city_results); for ($i=0; $i<sizeof($posts_by_city_row); $i++) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } ?> Results with for loop (there are 7 total unique book names, but it's just counting the first match on id 7 times like below): AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners I am working on building a code that will check the results returned from and xml pull to see if they match the database and print back pass or fail on the screen, it works for the first result but then fails to display anything else. any help on where I went wrong would be helpful. Code: [Select] <?php function pass($name, $level) { $sql1 = "SELECT * FROM `reqskills` WHERE `level` > 0 and `name` = '$name'"; $result1 = mysql_query($sql1); while($row1 = mysql_fetch_array($result1)) { if($level >= $row1['level']) { echo "Pass"; } Else { echo "Fail"; } } } $API = "address removed"; $xml = simplexml_load_file($API); $sql = "SELECT * FROM `reqskills` WHERE `level` > 0"; $result = mysql_query($sql); echo "<table width=100%"; echo "<tr><td>Skill</td><td>Level</td><td>Pass</td></tr>"; while($row = mysql_fetch_array($result)) { ?> <tr> <td><?php echo $row['name'] ?></td> <td><?php echo $row['level'] ?></td> <td><?php foreach ($xml->result->rowset[0] as $value) { $typeID = $value['typeID']; $sql = "select * from `invTypes` WHERE `typeID` = $typeID"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { echo pass($row['typeName'],$value['level']); }} echo "</td></tr>"; } echo"</table>"; ?> Does anybody know how to show the below php results in a table format? <?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ $fname = $_POST['fname']; $lname = $_POST['lname']; $skill = $_POST['skill']; //connect to the database $db=mysql_connect ("127.0.0.1", "root", "") or die ('I cannot connect to the database because: ' . mysql_error()); //select the database to use $mydb=mysql_select_db("resource matrix"); //query the database table $sql="SELECT DISTINCT First_Name, Last_Name, l.Resource_ID FROM ((resource l inner join resource_skill ln on l.Resource_ID = ln.Resource_ID) inner join skill n on ln.Skill_ID = n.Skill_ID) WHERE First_Name LIKE '$fname' OR Last_Name LIKE '$lname' OR Skill_Name LIKE '$skill'"; //run the query against the mysql query function $result=mysql_query($sql); //create while loop and loop through result set while($row=mysql_fetch_array($result)){ $First_Name =$row['First_Name']; $Last_Name=$row['Last_Name']; $Resource_ID=$row['Resource_ID']; //display the result of the array echo "<ul>\n"; echo "<li>" . "<a href=\"a.php?id=$Resource_ID\">" .$First_Name . " " . $Last_Name . "</a></li>\n"; echo "</ul>"; } } else{ echo "<p>Please enter a search query</p>"; } } Code: [Select] if (isset($_POST['update'])) { $signature = $_POST['signature']; $type = $_POST['type']; $name = $_POST['name']; $b=0; While ($b < $i) { echo $signature[$b]."<br>"; echo $type[$b]."<br>"; echo $name[$b]."<br><br>"; $b++; }} I did echo '<pre>'; print_r($_POST); echo '</pre>'; The results are Code: [Select] Array ( [sname] => [notes] => [signature] => Array ( [0] => 1-1 [1] => 1-2 [2] => 1-3 ) [type] => Array ( [0] => Test1 [1] => Test2 [2] => Test3 ) [name] => Array ( [0] => Testa [1] => Testb [2] => Testc ) [update] => Update ) But for some reason nothing is showing up on the screen. I am writing a CRON job that will execute daily. First it will identify from a MySql table the date in a field 'FAPforSale_repost35' If the date is the today date it will then execute commands to delete photo images in a directory, delete the directory, and finally remove the record from the database.
I am on step one which is to build the array of records that match the days date. When I run the code, there are no errors but I am not getting results even though the records in the test table are set for today. Below is the select
<?php define( "DIR", "../zabp_employee_benefits_processor_filesSm/", true ); require( '../zipconfig.php' ); require( DIR . 'lib/db.class.php' ); require_once( $_SERVER['DOCUMENT_ROOT'] . '/_ZABP_merchants/configRecognition.php' ); require_once( $_SERVER['DOCUMENT_ROOT'] . '/_ZABP_merchants/libRecognition/MailClass.inc' ); $todayRepost35 = date("Y-m-d"); echo $todayRepost35; function repostEndSelect() { global $db; $this->db = $db; $data = $this->db->searchQuery( "SELECT `FAPforSale_IDnumber`, `FAPforSale_image1`, `FAPforSale_image2`, `FAPforSale_image3`, `FAPforSale_repost35` FROM `FAP_forSaleTest` Where `FAPforSale_repost35` = '$todayRepost35' "); $this->FAPforSale_IDnumber = $data[0]['FAPforSale_IDnumber']; $this->FAPforSale_image1 = $data[0]['FAPforSale_image1']; $this->FAPforSale_image2 = $data[0]['FAPforSale_image2']; $this->FAPforSale_image3 = $data[0]['FAPforSale_image3']; $this->FAPforSale_repost35 = $data[0]['FAPforSale_repost35']; echo $this->FAPforSale_IDnumber; echo $this->FAPforSale_image1; echo $this->FAPforSale_image2; echo $this->FAPforSale_image3; echo $this->FAPforSale_repost35; } // ends function... echo( ' Finished...' ); ?>Thanks in advance for any suggestions or direction. Chapter two will be when I start testing the commands to delete. Hi people. I am creating a carpet website for a good friend of mine as a favour. I am storing the carpets info in a MYSQL database and am currently trying to relay the info on a page. I have the array kind of done but it is not producing the results I want. Let me explain further: The columns in my database under the table "carpets" a id (auto incremented) colour type title price description imageloc ------ under the type I have various types of carpet (6-ish). They a Twist, Striped etc etc... Heres the php problem. I have all the images there and ready on the page and want to link them all with linking commands. i.e: the main page is at: http://www.ircdirect.co.uk/FTPServers/supremecarpets/index.php the carpets results page is at: http://www.ircdirect.co.uk/FTPServers/supremecarpets/carpetlist.php on the index.php page I want to link them so that for example: If he looks for a striped carpet he clicks "striped" and is shows carpetlist.php but with the striped carpets displayed. example link: <A HREF="carpetlist.php?type=striped">IMAGE HERE</A> I have tried various coding on the carpetlist.php and cant seem to get it to work. here is the snippets: <?php // Make a MySQL Connection $query = "SELECT * FROM carpets GROUP BY type"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH=100% />"; echo "<TR />"; echo "<TD WIDTH=23 /><IMG SRC=images/main/search/topleft.png /></TD />"; echo "<TD BACKGROUND=images/main/search/top.png /> </TD />"; echo "<TD WIDTH=23 /><IMG SRC=images/main/search/topright.png /></TD />"; echo "</TR />"; echo "<TR />"; echo "<TD BACKGROUND=images/main/search/left.png />"; echo " "; echo "</TD />"; echo "<TD BACKGROUND=images/main/search/bg.png />"; echo "<FONT FACE=VERDANA SIZE=1 />"; echo $row['title']; echo "</TD />"; echo "<TD BACKGROUND=images/main/search/right.png />"; echo " "; echo "</TD />"; echo "</TR />"; echo "<TR />"; echo "<TD WIDTH=23 /><IMG SRC=images/main/search/bottomleft.png /></TD />"; echo "<TD BACKGROUND=images/main/search/top.png /> </TD />"; echo "<TD WIDTH=23 /><IMG SRC=images/main/search/bottomright.png /></TD />"; echo "</TR />"; echo "</TABLE />"; echo "<BR />"; } ?> It displays ALL the results which is not what I want. I want only striped carpets, blue carpets etc.... Help is needed and VERY much appreciated! Kind Regards, Ian Hi
I have 2 tables that I am searching infor for. One holds the phone info and the other the repairs that are available.
I have the code below and it displays on the webpage in a table for the phone information and then another table the repairs but they seem to be separate tables and headers. inbetween them is the phone and the details which separates the repairs but its not in a table.
Hopefully the code below will explain better.
What I would like it the phone details in one table and then a table full of all the repairs (I am not bothered about a new heading for each repair).
$result = mysql_query("SELECT * FROM phone, phonerepairs WHERE phone.model_no='".$_POST['model']."' AND phone.phone = phonerepairs.phone"); while($row = mysql_fetch_array($result)) { echo '<td width="70" align="center"><img src="'.$row['icon'].'" width="66"></td>'; echo '<td width="100" align="center">'.$row['model_no'].'</td>'; echo '<td width="130" align="center">'.$row['model'].'</td>'; echo '<td width="50" align="center">'.$row['year'].'</td>'; echo '<td width="150" align="center">'.$row['capacity'].'</td>'; echo '</tr>'; echo '</table><br>'; echo '</p>'; echo '<p>'; echo '<div id="pageheading"><h3><div id="title">Repairs we carry out for '.$row['model'].'</div></h3></div>'; echo '<table width="99%" cellpadding="5" cellspacing="0" border="1">'; echo '</p>'; echo '<p>'; echo '<tr>'; echo '<td align="center"><strong>Image</strong></td>'; echo '<td align="center"><strong>Fault</strong></td>'; echo '<td align="center"><strong>Repair</strong></td>'; echo '<td align="center"><strong>Cost</strong></td>'; echo '</tr>'; echo '<tr>'; echo '<td width="70" align="center"><img src="'.$row['icon'].'" width="66"></td>'; echo '<td width="100" align="center">'.$row['fault'].'</td>'; echo '<td width="130" align="center">'.$row['description'].'</td>'; echo '<td width="50" align="center">£'.$row['cost'].'</td>'; echo '</tr>'; echo '</table><br>';Thanks in advance Martyn This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=330251.0 Our product is running on LAMP(PHP) architecture. For MySQL operation PDO library has been used. We are in the process of moving the product to a new Linux server. On the new server we are facing MySQL query output related issue. At the end of the post I have listed the server configuration details of both the servers and the sample PHP program with the output. It works fine in server 1 but when the same code moved to Server 2, the output is not correct. Would appreciate any points to solve this problem The following piece of code is tested and output is also given. <?php /*** mysql hostname ***/ $hostname = 'localhost'; /*** mysql username ***/ $username = 'ram'; /*** mysql password ***/ $password = 'tellmehow'; try { $dbh = new PDO("mysql:host=$hostname;dbname=inhouse", $username, $password); $sql = "SELECT first_name,last_name,user_id,email FROM users LIMIT 1"; $stmt = $dbh->prepare($sql,array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => TRUE)); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_OBJ); $stmt->closeCursor(); /*foreach($result as $key=>$val) { echo $key.' - '.$val.'<br />'; }*/ print_r($result); $dbh = null; } catch(PDOException $e) { echo $e->getMessage(); } ?> Output for server 1: stdClass Object ( [first_name] => super [last_name] => admin [user_id]=>1 [email] => ram@greynium.com ) output for server 2: stdClass Object ( [first_name] => super [last_name] => admin [users] => ram@greynium.com ) On server 2 I am not getting the output for field 'user_id' from the table 'users'. For the field 'email' from 'users' table, it is displaying the name of the table itself (users). Not sure what is wrong. The configuration of the servers are given below Server 1 -------- OS Details: Linux 2.6.9-5.ELsmp PHP Details: PHP 5.2.3 (cli) (built: Aug 28 2007 11:48:30) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies with Suhosin v0.9.22, Copyright (c) 2007, by SektionEins GmbH PDO details: PDO PDO support => enabled PDO drivers => sqlite2, sqlite, mysql PDO Driver for MySQL, client library version => 5.0.37 PDO Driver for SQLite 3.x => enabled Server 2 --------- OS Details: Linux 2.6.18-8.el5 PHP Details: eAccelerator requires Zend Engine API version 220060519. The Zend Engine API version 220090626 which is installed, is newer. Contact eAccelerator at http://eaccelerator.net for a later version of eAccelerator. PHP 5.3.2 (cli) (built: Jul 6 2010 17:57:31) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies PDO Details: PDO PDO support => enabled PDO drivers => mysql, sqlite, sqlite2 PDO Driver for MySQL => enabled PDO Driver for SQLite 3.x => enabled I was wondering how does one go about showing results from SELECT query in columns in a html table. I have a list of products in a table, and would like to show them on the page in 4 columns. I have done many searches on google to try and find the sulution, but the majority of what im finding instead is about displaying a table from phpmyadmin as a table in html. If its a large operation to do this, I would be very happy if someone could poiint me in the direction of a tutorial maybe. Here is the code I have so far to display the products, but for some reason, it only show 1 row instead of all the rows from my table. Code: [Select] <?php $dbhost = "localhost"; $dbuser = "user"; $dbpass = "pass"; $dbname = "dbname"; mysql_connect ($dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $result = mysql_query("SELECT * FROM mcproducts"); while($row = mysql_fetch_array($result)) { $products_local_id = $row['products_local_id']; $productname = $row['product_name']; $thumburl = $row['image_from_url']; $productlink = $row['product_local_url']; $thumbnail = $row['product_image_small']; $currencysymbol = $row['product_currency']; $price = $row['product_price']; $flagicon = $row['product_country_from']; } ?> <html> <head> <link href="style/stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="displaybox"> <div class="productimage"> <a href="<?php echo $productlink; ?><?php echo $products_local_id; ?>"><img src="<?php echo $thumburl; ?><?php echo $thumbnail ?>" width="150" height="150"></a> </div> <div class="productdescription"> <div class="pro_name"> <a href="<?php echo $productlink ?><?php echo $products_local_id; ?>"><?php echo $productname; ?></a> </div> <div class="pro_description"> </div> <?php if ($flagicon=="Ireland") { $flagicon = "<img src=\"flags/ireland.jpg\">"; } elseif ($flagicon=="UK") { $flagicon = "<img src=\"flags/uk.jpg\">"; } else echo ""; ?> <div class="pro_description"><?php echo $flagicon; ?><?php echo $currencysymbol ?> <?php echo $price ?></div> </div> </div> </body> </html> Many thanks, DB i have built pages that paginate with 10 rows per page (some pages show more but for the moment i want to focus on this particular page)
//Define Some Options for Pagination $num_rec_per_page=10; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * $num_rec_per_page; $results = mysql_query("SELECT * FROM `ecmt_memberlist` WHERE toonCategory='Capital' AND oldMember = 0 ORDER BY CONCAT(MainToon, Name) LIMIT $start_from, $num_rec_per_page") or die(mysql_error()); $results_array = array(); while ($row = mysql_fetch_array($results)) { $results_array[$row['characterID']] = $row; }The above sets the variables for the pagination and below the results are echo with 10 rows per page then i show the pagination links: <?php $sql = "SELECT * FROM `ecmt_memberlist` WHERE toonCategory='Capital' AND oldMember = 0 ORDER BY CONCAT(MainToon, Name)"; $rs_result = mysql_query($sql); //run the query $total_records = mysql_num_rows($rs_result); //count number of records $total_pages = ceil($total_records / $num_rec_per_page); ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="center"><div style="width:100%; text-align:center;"> <ul class="pagination"> <li class="selected"> <?php echo "<a href='capitalmember.php?page=1'>".'«'."</a> ";?> </li> <? for ($i=1; $i<=$total_pages; $i++) { echo "<li><a href='capitalmember.php?page=".$i."'>".$i."</a></li> "; }; ?> <li class="selected"> <? echo "<a href='capitalmember.php?page=$total_pages'>".'»'."</a> "; // Goto last page ?></li> </ul></div> <?php $pageNr = $page; // Get Current Page Number $from = $pageNr * $rowsPerPage; // 3 * 10 = 30 // 3 * 10 = 30 $to = $from + $rowsPerPage; // 30 + 10 = 40 echo $pageNr; /* Result: From page 30 to 40 */ ?></td> </tr> </table>this works great and shows me 10 results per page, what i need to work out and work on next is: echo the number of results above the records (for example: "showing records 1 to 10" and then on page 2 "showing records 11 to 21" and page 3 "showing records 22 to 32" how can i work out the maths for this echo? i was thinking along the lines of; <?php $pageNr = $page; // Gets Current Page Number $from = $pageNr * $rowsPerPage; // 3 * 10 = 30 $to = $from + $rowsPerPage; // 30 + 10 = 40 // Now Show Results echo $from; // Echo from echo $to // Echo to ?>but i'm still working on this.. then i need to look at shortening the amount of page links on the page if for example i have 500 records it shows me links 1 to 50 and eats up the page.... Appreciate any help and light onto my problems. Many thanks Edited by jacko_162, 11 January 2015 - 05:43 PM. I am using html5 and all the pages have h2 headings as titles. They all show up in google search results fine. The only thing that doesn't show up fine are some of the descriptions under each heading. Some meta descriptions show up fine under the correct heading title, while rest shows ALL the heading tags AS description under each search result.
For eg.
Cars
www.mywebsite.com/category?id=5&name=cars Hello dear friends, I've made littel code that fetch the categories name from an software website $text= file_get_contents('http://win.softpedia.com/'); // it make win.softpedia as text code $start = strstr("$text",'<ul id="windows_cat">'); // search inside to that start point $end = strpos("$start",'" title="'); // end at it to that end point $cat = substr($start,66,$end-66); echo "$cat<hr>"; it will show now the categories but it only shows the 1st one Antivirus/ how then loop it to find next and next and so on to show me the list of the categories ! thanks I'm trying to list all titles from one table, and then list subgroup titles from a subgroup table. I only want to list the subgroups if the user have selected "Group4". Now the while loop is only listing the first subgroup title, and not the next ones. the first while loops keeps on looping after Group4, so this seems to work fine. And the Group4 title is showing two times, and I would like it to only show one time. I'm using a JavaScript to show the subgroups. <script type="text/javascript"> function vis (it, box) { var vis = (box.checked) ? "block" : "none"; document.getElementById(it).style.display = vis; } </script> <?php $query = mysql_query("SELECT groupID, Title FROM Group"); while ($row = mysql_fetch_array($query)) { if($row[Title] == "Group4"){ ?> <input type="checkbox" id="group" value= "<?$row[groupID]?>" name="group[]" onclick="vis('div1', this) "/><label for="<?$row[groupID]?>"><? echo $row[title]?></label> <br/> <?php $query2 = mysql_query("SELECT gID, title FROM subgroup"); while ($row2 = mysql_fetch_array($query2)) { ?> <div class="rad" id="div1" style="display:none"> <input type="checkbox" id="group" value="<?$row2[groupID]?>" name= "group[]" ><label for="<?$row2[title]?>"><? echo $row2[title]?></label> <br/> </div> <?php } } ?> <input type="checkbox" id="group" value="<?$row[groupID]?>" name= "group[]" ><label for="<?$row[title]?>"><? echo $row[title]?></label> <br/> <?php } ?> Hello all, I've built a database of coupons. Each coupon is assigned to a category (so all electronics coupons display under electronics). On my category list I'd like to display how many coupons is in each category. Currently this function displays my category list: function fetch_categories() { mysql_connect(SQL_HOST_NAME, SQL_USER_NAME, SQL_PASSWORD) or die(mysql_error()); mysql_select_db(SQL_DATABASE) or die(mysql_error()); $result = mysql_query("SELECT * FROM categories ORDER BY category_name")or die(mysql_error()); echo '<div id="category_list">'; echo '<ul class="cat_list">'; while($row=mysql_fetch_assoc($result)){ //get total of discounts in each category $count_result = mysql_query("SELECT * FROM category_relations, discounts WHERE category_relations.member_of = '$row[id]' AND discounts.active = '1'")or die(mysql_error()); $num_rows = mysql_num_rows($count_result); echo '<span class="numrows">('.$num_rows.')</span>'; echo '<li><a href="index.php?cat_ID='.$row['id'].'">'.$row['category_name'].' </a></li>'; } echo '</ul>'; echo '</div>'; } The above is a debug version so it's not all formatted correctly. However right now, that exports "3" for Airlines when right now, I have only one discount in the entire database. This is my category_relations table: Code: [Select] -- -- Table structure for table `category_relations` -- CREATE TABLE IF NOT EXISTS `category_relations` ( `id` int(10) NOT NULL, `member_of` int(10) unsigned NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- -- Dumping data for table `category_relations` -- INSERT INTO `category_relations` (`id`, `member_of`) VALUES (2, 2), (1, 1), (3, 1), (4, 1); And this is my discounts table: Code: [Select] -- -- Table structure for table `discounts` -- CREATE TABLE IF NOT EXISTS `discounts` ( `id` smallint(5) NOT NULL AUTO_INCREMENT, `redeem` tinyint(3) NOT NULL, `discount_title` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `short_description` tinytext CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `eligibility` blob NOT NULL, `url` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `coupon_code` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `start_date` datetime DEFAULT NULL, `end_date` datetime DEFAULT NULL, `long_description` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `logo` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `business_name` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `phone` varchar(80) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `store_location_street` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `store_location_city` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `store_location_state` char(2) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `store_location_zip` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `categories` blob NOT NULL, `level` tinyint(5) NOT NULL, `active` tinyint(1) NOT NULL, `user_id` varchar(2555) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), KEY `level` (`level`,`active`), KEY `user_id` (`user_id`(333)) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ; -- -- Dumping data for table `discounts` -- INSERT INTO `discounts` (`id`, `redeem`, `discount_title`, `short_description`, `eligibility`, `url`, `coupon_code`, `start_date`, `end_date`, `long_description`, `logo`, `business_name`, `phone`, `store_location_street`, `store_location_city`, `store_location_state`, `store_location_zip`, `categories`, `level`, `active`, `user_id`) VALUES (1, 0, '$2.00 Off Transportation', '', 0x4172726179, 'www.baysideshuttle.com', '', '2010-01-01 00:00:00', '2011-01-01 00:00:00', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer varius ipsum id justo pellentesque laoreet. Curabitur tempus tincidunt...', NULL, 'Bayside Airport Shuttle', '850-123-3456', NULL, NULL, NULL, NULL, 0x4172726179, 0, 1, '24'); It seems to be completely ignoring my active check. How can I fix this, or is there a better way to do this query? Hello, I have a database that contains a column with a int value for number of slots reserved, and what I want to do is fetch the value of each column and add them together to create one whole number. For example, in my database under preserved I have two separate values of 2 and 4.. I would like to take those two values and add them up into 6 through php... here is what I have so far: $slots = mysql_query("SELECT * FROM treservations WHERE reservation_date='$reservation_date' AND reservation_hour='$reservation_hour'") or die(mysql_error()); while ($row = mysql_fetch_assoc($slots)) { $row["preserved"]; } mysql_free_result($slots); Any help would be GREATLY appreciated.. if I need to add additional code please let me know. Thank you! I am using a foreach loop to get the results of an array. My problem is that I need the results combined into one string. How can I accomplish this? 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. I am trying to create a script that will show a block of images for every nine items in an array. So it doesn't need to show the block of images for every 9 items, but every time the counter hits 9 show a block of images. Make sense? I am stumped as all get out. Thanks for all the help in advance! |