PHP - Seperate Array By 5's Into Individual Div Containers
I figure I'd use array_chunk to divide my array by 5's, but how can I get each set of five to be enclosed in div tags. My array is a list of images in a directory which I need inserted into a format like the example code on this page. http://flowplayer.org/tools/demos/scrollable/index.html. Thanks for any help.
Similar Tutorialsi have checkboxes on the database page and if checked they send to the shopping basket i have the items selected to display but like this
Array ( [0] => Imagine DragonsImagine DragonsRockI Bet My LifeKIDinaKORNER1.25Brand new single from the incredible Imagine Dragons )
I am having problems displaying individual data I am using $filename[0] to display the first data, any ideas where i am going wrong. <?php $active_keys = array(); foreach($_POST['img'] as $key => $filename) { if(!empty($filename)) { $active_keys[] = $key; } echo "". $filename[1]; } ?> Hi again all, Why does the foreach loop im doing, put the array values from collection, into seperate table rows rather than 1 row per whole array? <?php class registration{ public $fields = array("username", "email", "password"); public $data = array(); public $table = "users"; public $dateTime = ""; public $datePos = 0; public $dateEntryName = "date"; public $connection; function timeStamp(){ return($this->dateTime = date("Y-m-d H:i:s")); } function insertRow($collection){ //HERE foreach($this->fields as $row => $value){ mysql_query("INSERT INTO $this->table ($value) VALUES ('$collection[$row]')"); } mysql_close($this->connection->connectData); } function validateFields(){ $this->connection = new connection(); $this->connection->connect(); foreach($this->fields as $key => $value){ array_push($this->data, $_POST[$this->fields[$key]]); } $this->dateTime = $this->timeStamp(); array_unshift($this->data, $this->dateTime); array_unshift($this->fields, $this->dateEntryName); foreach($this->data as $value){ echo "$value"; } $this->insertRow($this->data); } } $registration = new registration(); $registration->validateFields(); ?> I end up with 3 rows row 1: username row 2: email row 3 : password rather than row 1:username email password. I've got my code working OK in that the correct results are drawn from the database. What I have here in the code is an array consisting of an image, accompanied by its title and thirdly a link to activate a quiz associated with the image. Everything works fine, except because the page is dynamic, I always have an unknown number of sets of data (image, title and link) which I want to display so that each set of data takes up a new row. The code I have here, while displaying the correct data, places all of the results into the same row. Any suggestions are most welcome. Code: [Select] <?php // Query the database $query1 = mysql_query("SELECT title FROM topics WHERE managerId='".$managerId."' AND egroup1='"."1"."' ORDER BY title ASC"); $query2 = mysql_query("SELECT url_small FROM topics WHERE managerId='".$managerId."' AND egroup1='"."1"."' ORDER BY title ASC"); $query3 = mysql_query("SELECT title FROM topics WHERE managerId='".$managerId."' AND egroup1='"."1"."' ORDER BY title ASC"); while($row1 = mysql_fetch_array($query3)) { $linkname .= $row1['title']."<br />\n"; } ?> <table> <tr> <td> <?php while ($row2 = mysql_fetch_array($query2)) { $thumbnail.= $row2['url_small']; echo "<img src='wood_tool_images/{$row2['url_small']}' alt='' /><br />\n"; } ?> </td> <td height="200"> <?php echo $linkname ?> </td> <td> <?php while ($row1 = mysql_fetch_array($query1)) { $quizname.= $row1['title']; echo "<a href='../{$row1['title']} Safety Quiz/{$row1['title']} Safety Quiz.php'>Take This Quiz</a><br />\n"; } ?> </td> </tr> </table> I have a database query set up that returns an array. I then cycle through the rows in a foreach statement that wraps each value in a <td> tag to output it to a table. It works really great, but now I need to access two of the values and add some info to them. The first field returned is an image filename and I want to wrap it in an image tag that also concatenates the image path location to the value. All the images are stored in the same location, so basically I want to take the first value form the array and add the path to where the images are and wrap the whole thing in an <img> tag. The other field I need to modify is the last value in the array which is actually an email address. For that field I want to make them an active email link so I need to wrap an <a>href=mailto: </a> tag around the value. How could I modify this code so I could add the necessary tags to these elements of the array? Here is the code I am running: Code: [Select] $query = "Select member_image as 'Image', member_name as 'Name', city as 'City', phone as 'Phone', email as 'Email' FROM directory"; //connect to database $conn=db_connect(); //call function do_query to run the query and output the table do_query($conn, $querey); The functions called are as follows: Code: [Select] function db_connect() { $conn = new mysqli("localhost", "username", "password", "databasename"); } function do_query($conn, $query); { $result = mysqli_query($conn, $query); WHILE ($row = mysqli_fetch_assoc($result)) { If (!$heading) //only do if header row hasn't been output yet { $heading = TRUE; //so we only do it once echo "<table>\n<tr<>\n"; foreach ($row as $key => $val) { echo "<th>$key</th>"; } echo "</tr>\n"; } echo "<tr>"; foreach ($row as $val) { echo "<td> $val </td>"; } echo "</tr>\n"; } //close the while echo "</table>\n"; } Hey there, Thanks for reading this thread. I've come across a problem where I cannot get the text to echo properly upon retrieval from the database, here is a example; Now this is where I echo the text: function ListPosts($PageLimit) { $Posts = mysql_query("SELECT * FROM posts"); while($Post = mysql_fetch_array($Posts)) { echo("<div class=\"art-Post\"> <div class=\"art-Post-tl\"></div> <div class=\"art-Post-tr\"></div> <div class=\"art-Post-bl\"></div> <div class=\"art-Post-br\"></div> <div class=\"art-Post-tc\"></div> <div class=\"art-Post-bc\"></div> <div class=\"art-Post-cl\"></div> <div class=\"art-Post-cr\"></div> <div class=\"art-Post-cc\"></div> <div class=\"art-Post-body\"> <div class=\"art-Post-inner\"> <h2 class=\"art-PostHeader\">{$Post['post_subject']}</h2> <div class=\"art-PostContent\"> <p>{$Post['post_contents']}</p> </div> <div class=\"cleared\"></div> </div> <div class=\"cleared\"></div> </div> </div>"); } } Hi I need to take the number off of the end of a url and do some processing with it. so for example: www.something.com/something/10001 i will need to seperate them into 2 different variables, for example: $var1 = www.something.com/something/ $var2 = 10001 is this possible? Thanks Hi there, I'm making an online clothing store for the brick and mortar shop we have and would like the customer to be able to refine their search by size, colour etc. The size options will be XS, S, M etc etc where XS is 0, S is 1 and so on. So when they select XS it will add ?size=0 to the URL, if they select XS and S it will be ?size=0;1 What I need to know is how to make some PHP code which can recognise the ; is a break and know that both sizes are selected. Hope that makes sense and thanks in advance Ok so I'm coding up a file tree for a script and I've got the system setup so that when a user clicks on a folder it adds that folder to the path. The path is stored in a variable, but I'd like to allow the user to be able to go down multiple directories at once. To do this I'm going to seperate each folder name in the path and link to it so as an example: $path = './home/public_html/folder1/folder2'; how can I separate each of those so I can make a link to that folder so that: /home goes to $path = './home/'; /public_html goes to $path = './home/public_html'; etc... --- Basically just seperate the slashes into an array and seperate each of them off based on how far along it is but I don't know how to do that... I want to retrieve items from the DB and seperate them using a comma... while i know how to actually do that, what i want is to automatically have stop adding comas at the last item... so if there are 4 items i want it to show a comma after each item except the last one (1, 2, 3, 4). Does anyone know of a function or can give me an example on how i can do this. Hello: I have a DB table with this structu Code: [Select] CREATE TABLE `gallery_category` ( `category_id` bigint(20) unsigned NOT NULL auto_increment, `category_name` varchar(50) NOT NULL default '0', PRIMARY KEY (`category_id`), KEY `category_id` (`category_id`) ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; What I am trying to do id pull this data into my "Edit Product" page and populate a SELECT menu with it. I want the user to be able to re-assign a product to a new category if they chose to do so. I want to add the data (and update the DB) to this area: Code: [Select] <div style="float: left; width: 550px;"> <select name='category_name'> <option></option> </select> </div> This is the full page code that allows users to update product info: Code: [Select] <?php include('../include/myConn.php'); include('../include/myCodeLib.php'); include('include/myCheckLogin.php'); include('include/myAdminNav.php'); include('ckfinder/ckfinder.php'); include('ckeditor/ckeditor.php'); $photo_id = $_REQUEST['photo_id']; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $photo_title = mysql_real_escape_string($_POST['photo_title']); $photo_price = mysql_real_escape_string($_POST['photo_price']); $photo_caption = mysql_real_escape_string($_POST['photo_caption']); $sql = " UPDATE gallery_photos SET photo_title = '$photo_title', photo_price = '$photo_price', photo_caption = '$photo_caption' WHERE photo_id = $photo_id "; mysql_query($sql) && mysql_affected_rows() ?> <?php } $query=mysql_query("SELECT photo_title,photo_price,photo_caption FROM gallery_photos") or die("Could not get data from db: ".mysql_error()); while($result=mysql_fetch_array($query)) { $photo_title=$result['photo_title']; $photo_price=$result['photo_price']; $photo_caption=$result['photo_caption']; } ?> <!DOCTYPE HTML> <html> <head> </head> <body> <div id="siteContainer"> <p> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') echo "<span class=\"textError\">". $photo_title ." successfully updated!</span>" ?> </p> <p> <form method="post" action="<?php echo $PHP_SELF;?>"> <input type="hidden" name="POSTBACK" value="EDIT"> <input type='hidden' name='photo_id' value='<?php echo $photo_id; ?>' /> <div style="float: left; width: 120px; margin-right: 30px;"> Category: </div> <div style="float: left; width: 550px;"> <select name='category_name'> <option></option> </select> </div> <div style="float: left; width: 120px; margin-right: 30px;"> Title: </div> <div style="float: left; width: 550px;"> <input type="text" name="photo_title" size="45" maxlength="200" value="<?php echo $photo_title; ?>" /> </div> <div style="clear: both;"><br /></div> <div style="float: left; width: 120px; margin-right: 30px;"> Price: </div> <div style="float: left; width: 550px;"> <input type="text" name="photo_price" size="45" maxlength="200" value="<?php echo $photo_price; ?>" /> </div> <div style="clear: both;"><br /></div> Description:<br /> <textarea cols="107" rows="1" name="photo_caption"><?php echo $photo_caption; ?></textarea> <div style="clear: both;"><br /></div> <br /> <input type="submit" value="Submit" /> </form> </p> </div> </body> </html> How can I do this? I'm stumped ... Thanks! Here's the query: Code: [Select] $sql = mysql_query("SELECT * FROM resources WHERE gameCat = '' ORDER BY systemCat,order_id"); I want something to happen when the systemCat changes in the results. Like this: Code: [Select] if($row['systemCat'] CHANGES){ echo '<div id="seperator"></div>'; } Any ideas? Thank you! Hi, I have a challenging dilema. A client keeps track of his stock using a microsoft access database in store. His ecommerce website which is hosted elsewhere uses php and mysql. Is it possible to to integrate the 2 so that when someone buys a product from the website, the store MS access database is updated to reflect this and vice versa? If so how would I go about it? Thanks in advance. P.S: I'm extremely tempted to suggest that he should stop using his ms access db and instead reccommend that I set him up a suitable backend on his website for keeping stock control, then he just login to that in the store. hmm im having some trouble tackling this problem i have a database table with topicname then 3 columns with 3 pdfs in each one all the files are stored in a directory called topicfiles in the server so like 3 topicnames with 3 files in each one with this page i want to make i want to display each topic name with the files under it calling it from the server like Code: [Select] topic 1 file1.pdf file2.pdf file3.pdf topic 2 file4.pdf file5.pdf file6.pdf topic 3 file71.pdf file8.pdf file9.pdf i tried using dhandler to access all files in the folder and only managed to display all of the files in rows using foreach loop was thinkin of using mysql query to access the topic name and then each file for that topic but not sure hmmm I want the user to input there name, then have a php script to find the memeber in a members database and then grab the whole row by the user name. so if my db has 3 colums id, user, password, then want it to take out all three fields based on the users name. Can anyone help me? I forgot my password for my old account so had to create a new one. New laptop.
Anyway, I've searched and searched but can't find a jQuery, javascript or anything else to do what I want to do. I want to fade out all the different paragraphs of a div one letter at a time starting with the first.
Here is something CLOSE though the string has to be input. I'm pulling data in from a database with PHP. So not sure if I can target individual letters in different paragraphs.
$(function () { var string = " David"; var q = jQuery.map(string.split(''), function (letter) { return $('<span>' + letter + '</span>'); }); var dest = $('#fadeIn'); var c = 0; var i = setInterval(function () { q[c].appendTo(dest).hide().fadeIn(1000); c += 1; if (c >= q.length) clearInterval(i); }, 1000); });I know I can get my target from a div then split it into characters with something like this: function arrayMe(string) { // For all matching elements $(string).each(function() { var myStr = $(this).html(); myStr = myStr.split(""); var myContents = ""; for (var i = 0, len = myStr.length; i < len; i++) { myContents += '' + myStr[i] + ''; } $(this).html(myContents); }); }Then call the function: $('document').ready(function() { var myStringType = $('.sample-text'); arrayMe(myStringType); });Where my div as a class of sample-text. (These are just code snippets I have pulled from the net in my search for an answer). But using the fade in which nice in jsfiddle, How can I put all these together to fade out my text a single letter at a time? I'm not sure if different paragraphs will work or not or if I'm going to have to have one long paragraph (bad for my application). Thanks for the help here guys. You've always come through for me before. It's just been awhile since I've been stumped. Hi all, I have used this script to pull twitter updates to my website and it works great: http://www.inkplant.com/code/pull-twitter-feed-into-your-site.php I was wondering if anyone could help me modify it so that it links to the individual twitter posts such as: http://twitter.com/user/status/4528454817693440 Thanks! This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=313049.0 I have been banging my head against a wall for a few days over this and think that I have read so many alternative ways, I have got myself confused! What I am trying to do is post some information into the database and on success, provide certain variables back to my script (for example last_insert_id) as I would like to show a success message an add an option to a select on that page. I am trying to get this part working without the mysql first just so I understand it. Currently I can post the data, have that received successfully in the processing page (addDetail.php) and send back output from that page........ insert.php $("#sub").click(function() { var name = $("#name").val(); var town = $("#town").val(); jQuery.ajax({ type: "POST", url: "postScripts/addDetail.php", data: 'name='+name+'&town='+town, success: function(html) { $(".modal-body").prepend( "Returned: " +html ); } }); return false })addDetail.php $name = $_POST['name']; $town = $_POST['town']; //Check $_POST data echo "<pre>"; print_r($_POST) ; echo "</pre>"; $return["name"] = $name; $return["town"] = $town; echo json_encode($return); Result in insert.php Returned: Array ( [name] => The Name [town] => The Town ) {"name":"The Name","town":"The Town"}This works fine to bring back everything on the processing page in one go but I want to bring back separated variables so I can use them individually. I thought that changing "Returned: " +htmlto "Returned: " +html.namewould allow me to bring back just that variable but it comes back undefined. This is the closest I have got as other methods I tried either brought nothing back or just [objectObject]. How would I be able to bring back both 'name' and 'town' as separated values so I can use them individually in my script? Thanks in advance Steve Edited by MargateSteve, 29 September 2014 - 08:41 AM. Hey everyone I'm pulling data from my db and then trying to store each value to its own var. the problem is the amount of values is always changing. here is what I have that isnt working $result = mysql_query("SELECT thismonth FROM list"); while($row = mysql_fetch_array($result)) { echo $row[0] . "<br>"; // this prints out all the values perfectly } no I just dont know how to store them so i can use them later. |