PHP - How Do I Display A String (x) Times?
I have a string, and I have a variable
$var = 5; $str = '<img src="img.jpg" />'; i want to display a $str (the image) $var amount of times (5). how can I do this? Similar TutorialsHey guys I have a client who wants to upload images then have them display on his page... obviously that process is not an issue at all. The catch is he wants the image to change at midnight and display the next image in the sequence, then display it until midnight strikes, and then the next in the sequence is displayed. Is there any code type that will recognise a set time/date and display coressponding images in a database? I realise I made need to add a field for an ID number/date ID for the code to identify which image to display, but not sure what code will/wont work Can some one point me in the right direction would be much appreciated Thanks Tom Hello all, I'm collecting date/time information via a form and would like to convert the info into something that I can stick in my MySql database (a timestamp???). I'm collecting the current month (variable name: month-- of the form "mm"), day (variable name: day -- of the form "dd"), year (variable name: year -- of the form "yyyy"), time of day (variable name: time -- of the form "h:00"), and before or after noon (variable name: ampm -- of the form "am" or "pm"). Any suggestions as to how to change this into a quantity that I can store as a value and then use to compare to other date/times would be appreciated. Thanks! Let's say I have a variable called $big_paragraph I want to display the variable IF it contains the word "hello". The word may or may not be there AND it could be anywhere in that paragraph (separated by a space before and after it to signify that it is a word). So I can't use substr since it assumes I know the position. Thanks. The below might be a noob question but, I concatenate two spaces in the below string $new_hebrew_date_string = $hebrewMonthName . ' ' . $hebrewDay . "%"; yet when I execute echo "<br />new_hebrew_date_string is $new_hebrew_date_string<br />"; printf("hebrew_date_string is: %s <br />", $new_hebrew_date_string); Only one space is output in between $hebrewMonthName and $hebrewDay regardless of how many spaces I pad the string with. Strangely enough, the string $new_hebrew_date_string is correctly padded w/spaces when I pass it as a parameter to a mySQL stored procedure. Any ideas anyone? Thank you. Hi, I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it to the path for uploads. Here is uploadify.php as it currently looks: Code: [Select] <?php session_name("MyLogin"); session_start(); $targetFolder = '/songs/' . $_SESSION['name']; // Relative to the root if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name']; // Validate the file type $fileTypes = array('m4a','mp3','flac','ogg'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; } } echo $targetFolder; ?> I added Code: [Select] echo $targetFolder; at the bottom so that I could make sure that the string returned was correct, and it is, i.e. '/songs/nick'. For some reason though, uploads are not going to the correct folder, i.e. the username folder, but instead are going to the parent folder 'songs'. The folder for username exists, with correct permissions, and when I manually enter Code: [Select] $targetFolder = '/songs/nick';all works fine. Which strikes me as rather strange. I have limited experience of using php, but wonder how if the correct string is returned by the session variable, the upload works differently than with the manually entered string. Any help would be much appreciated. It's the last issue with a website that was due to go live 2 days ago! Thanks, Nick Hey there, Thanks for taking the time to read my thread. My issue is that I can't think of a way to edit a XML file using PHP's XML functionality and then assign the edited contents to a string instead of saving the file. Because my issue is that I have to edit the XML file based upon a string brought from a remote location then give it back to that remote location using a string again, to be exact I am doing it via Linux command line utilizing SSH2. This is what I managed to complete on my own. function CheckIVMPConfig($ServerID) { global $Panel; if(is_numeric($ServerID) && $this->IsValidServer($ServerID)) { // We select the game server that the FTP account was created for. $Servers = mysql_query("SELECT * FROM control_servers WHERE server_id = '".mysql_real_escape_string($FTPAccount['ftp_server'])."'"); $Server = mysql_fetch_array($Servers); // Here we select the Box ID that the game server is on. $Boxs = mysql_query("SELECT * FROM control_machines WHERE machine_id = '".$Server['server_machine']."'"); $Box = mysql_fetch_array($Boxs); // Now we select the required package for the box. $Packages = mysql_query("SELECT * FROM control_packages WHERE package_id = '".$Server['server_package']."'"); $Package = mysql_fetch_array($Packages); // Retrive the file. $Config = $CProtocol->exec("cat /home/{$Server['server_id']}/{$Package['package_config']}"); $Parse = SimpleXMLElement($Config); foreach($Parse as $Entry) // loop through our books { if($Entry->port != $Server['server_port']) { // edit the value } else if($Entry->maxplayers > $Server['server_slots']) { // edit the value } } } } This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326004.0 Hello all, I'm trying to change the end of a javascript call based on the end of the url string. The common part of all the url strings is sobi2Id=, I'm trying to do this with strstr but am having no luck. I'm new to php so my syntax knowledge is terrible! at the moment i've got Code: [Select] <?php $url = $_SERVER['REQUEST_URI']; $tag = strstr ($url, 'sobi2Id='); echo $tag; ?> but this returns an unexpected T_STRING, expecting ',' or ';' Can anyone debug this? I may well be being really silly! I need help with a query.
I've got a table that stores references to calls that come in to our office. It has a datetime field, and for the purposes of the query, it's the only thing in this table that is important.
I've got another table that stores appointment information. The appointment start time is also a datetime field. For this query, this start time is the only thing in this table that is important.
I need to know how many times in the last year there was a day when we had at least 150 calls come in and made at least 1 appointment.
SELECT COUNT(*) FROM appointments a LEFT JOIN ( SELECT DATE(time) FROM calls WHERE <there are at least 150 calls on a day> ) c ON DATE(a.start_time) = c.time WHERE a.start_time >= CURDATE() - INTERVAL 1 YEARTo make things difficult, I guess the time would have to be converted to a day, because I'm looking for all days where there was an appointment, and the datetime field is too specific. I've been looking online for 30 mins or so, and was hoping somebody here could point me in the right direction. I'm not making much progress by myself. Edited by sKunKbad, 06 October 2014 - 01:17 PM. Hello friends, i'm getting error due to using an function for 3 times in same time if i've 3 results and i want to base36_encode the 3 output it only encode one and then gives me error Cannot redeclare base36_encode() (previously declared) here is the code // this is the encode function // function base36_encode($base10){ return base_convert($base10,10,36); } // i'm getting output here as 3 times (id) // $id = base36_encode($line[id]); echo "$id<br>"; the out but should be like this id1 id2 id3 all have been base36 encoded but it only show the 1st one id1 and the rest gives me the error above... so how can i make it works for all results not only the 1st one thanks everybody Hi all I am trying to edit a piece of code to change possible times for a booking system. This is the code I have: $count=0; for($b=$startTime;$b<$endTime;$b++){ if($count==$tempVar2){ $availability .= "</td><td align='left' valign='top'>"; } if(in_array($b,$reservedArray)){ $availability .= $b.":00 ".($b<12?"am":"pm")." - ".($b+1).":00 ".($b+1<12?"am":"pm")." - Booked.<br>"; } else { $availability .=$b.":00 ".($b<12?"am":"pm")." - ".($b+1).":15 ".($b+1<13?"am":"pm")."- <input type=\"checkbox\" value=\"".$b."\" name=\"time[]\" ><br>"; } $count++; } It gives me the following times: 09:00 am - 10:15 am 10:00 am - 11:15 am 11:00 am - 12:15 am 12:00 pm - 13:15 pm 13:00 pm - 14:15 pm 14:00 pm - 15:15 pm 15:00 pm - 16:15 pm 16:00 pm - 17:15 pm How can I change it so I can have the following times available: 10:00 am - 10:30 am 10:45 am - 11:15 am 11:30 am - 12:00 pm 12:15 pm - 12:30 pm etc... Many thanks for you help Pete. Hello All, I have tried to find a solution for this issue for days. The script was working fine until yesterday when all of a sudden I get this warning. Quote Warning: imagecreatefrompng(http://domain.com/images/broadcast1.png) [function.imagecreatefrompng]: failed to open stream: Connection timed out in /home/domain/public_html/logo/logo1.php on line 8 line 8 is: $image_1 = imagecreatefrompng($file_1); Where $file_1 = "http://domain.com/images/broadcast1.png"; The exact code is working perfectly fine in a different server I have, both servers are running Centos with PHP5 + GD fully enabled. The image http://domain.com/images/broadcast1.png (~5Kb) is loading very fast when open through a browser. Please please help me resolve this, I have tried many different things and even uninstall and install GD again but n luck. Thank you so much for your help. Hi everyone, I'm trying to add up the current time with a specified amount of seconds and insert it in a database afterwards. When I add say: 500 seconds to the current time it adds a whole lot more and I get a number few thousands higher than I want. Can anyone help me???. Gr Ryflex Well I'm hoping someone will have some fun with this. My database has a list of times for a given date, and a schedule for each time. I'm trying to change the input backgrounds for rows between 2 different times. Like this: 8:00 enter some data 8:10 enter some data 8:20 enter some data etc. What I want is to change the background color of any input field between say 9:00 and 10:00, but leave everything else white. I can change the color, just can't figure out how to compare the times. Here's part of the code: Code: [Select] while($row = mysql_fetch_array( $result )) { $opentimeID = date("g:i",strtotime(1530)); //not sure if these statements are correct. $closetimeID = date("g:i",strtotime(1730)); if (strtotime($row['Time']) //...not sure how to finish this statement to compare the time in the database row to $opentime and $closetime. { echo "<tr><td>"; echo date("g:i ", strtotime($row[Time])); echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player1]' name='player1[$i]' style ='background-color: #FFFF66;'>"; echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player2]' name='player2[$i]' style ='background-color: #FFFF66;'>"; echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player3]' name='player3[$i]' style ='background-color: #FFFF66;'>"; echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player4]' name='player4[$i]' style ='background-color: #FFFF66;'>"; echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player5]' name='player5[$i]' style ='background-color: #FFFF66;'>"; } else { echo "<tr>"; echo "<td>"; echo date("g:i ", strtotime($row[Time])); echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player1]' name='player1[$i]'>"; echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player2]' name='player2[$i]'>"; echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player3]' name='player3[$i]'>"; echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player4]' name='player4[$i]'>"; echo "</td><td>"; echo "<input type='text' size='20' value= '$row[Player5]' name='player5[$i]'>"; } Thanks for any advice! Hello PHP Freaks, I am using a basic payment frame system, and it requires me to pass in a GMT time in this format, in a hidden form. "YYYYMMDDHHMMSS" I have found a lot of examples in PHP on how to format the above tag, but what would be the easiest way to generate it as is? To make things a little more complicated, there are different users in different GMT times, and based on the state they select it needs to + or - hours from the current time to get the GMT time. The formulas to calculate the results are as follows, just after the best approach in PHP to calculate: State #1: CURRENT_TIME + 10 HOURS = GMT TIME (echo as YYYYMMDDHHMMSS) and assign to $GMT_TIMESTAMP State #2: CURRENT TIME + 9.5 HOURS = GMT TIME (echo as YYYYMMDDHHMMSS) and assign to $GMT_TIMESTAMP What would be the best way to tackle this ? At the moment I have select boxes where the user can pick the state, then click SUBMIT. Thankyou in advance, D Hi guys, i got the following code i wrote which displays a small pop up on screen if the user has mail, and display a little icon. The problem is it displays a new icon for each new mail message. How can i make it so it only display 1 icon no matter how many unread mail the user has. Or even better if not too complicated display a number next too the image? Code: [Select] <? require'xxxxxxxxxxxxxxxxx.php'; mysql_select_db("membership") or die( "Unable to select database"); $sql=("SELECT * FROM user_alerts WHERE user_id = '".($_SESSION['user_id'])."'") or die (mysql_error()); if ($query=@mysql_query($sql)) { if (mysql_num_rows($query) > 0) { while ($req=mysql_fetch_array($query)) { if ($req['messageRead'] == 'NO') { ?> <div> <img src="xxxxxxxxxxxxxx.png" width="32" height="32" alt="unread mail" /> <a href="http://www.xxxxxxxxxxxx/account=account">You have Mail!</a> <div id="boxes"> <div style="top: 199.5px; left: 551.5px; display: none;" id="dialog" class="window"> <h2>You have new mail!</h2> <br /> <p>Visit your account page to read it.</p> <br> <a href="#" class="close">Close Window</a> </div> <!-- Mask to cover the whole screen --> <div style="width: 1478px; height: 602px; display: none; opacity: 0.8;" id="mask"></div> </div> </div> <? } } } } You can ignore most of the div stuff but that's pretty much it. It should check my database for any entries with the users session id in the column called 'user_id'. and only show the image if it then finds an entry with 'NO' in the 'messageRead' column. It currently shows the images for each entry it finds. Thanks for any help Hello, I am having a heck of a time trying to get time right on my website lol When a user logs in, they select what timezone they are in (UTC -1,-2,-3,-4,-5,-6....) Now this is great an all, but with daylight savings time my times are off by one hour in either direction. How do sites like this get times to work for users so easily? Thanks! weee I have an array of appointment start times throughout a day. All appointments last 30 mins. I also have a list of times that staff are available to meet these appointment times (can be in any format, array etc.) I need to ensure the appointment times are fully covered by members of staff. E.g. Code: [Select] $appointmentStart[] = "09:30"; $appointmentStart[] = "10:00"; $appointmentStart[] = "11:00"; $appointmentStart[] = "12:30"; $appointmentStart[] = "13:30"; $appointmentStart[] = "15:00"; $appointmentStart[] = "17:00"; $staffMembers[] = "09:00*12:00"; $staffMembers[] = "13:00*16:00"; $staffMembers[] = "15:00*18:00"; In the above case, no, there are not enough staff members to cover this as nobody works from 12:00 to 13:00. I only really need a yes or no. Don't worry about staff breaks, they never work more than 3 hours each at a time. Thanks in advance for any help. I only see one "mysql_query($memberquery);" Yet the record is inserted 4 times when I check the db. Anyone see why? Thank you for your time! Code: [Select] <?php $link_register = 1; session_start(user); include("header.php"); $firstname = $_SESSION['firstname']; $middleinitial = $_SESSION['middleinitial']; $lastname = $_SESSION['lastname']; $phone = $_SESSION['phone']; $email = $_SESSION['email']; $street = $_SESSION['street']; $city = $_SESSION['city']; $state = $_SESSION['state']; $categoryArray = $_SESSION['categoryArray']; $gender = $_SESSION['gender']; $con = mysql_connect("localhost", "root", ""); if (!$con) { die("Could not connect: ". mysql_error()); } //The database is selected with the mysql_select_db() function. mysql_select_db("hobbyclub", $con); //put the data insert into a varaible so it can be checked later $memberquery = "INSERT INTO member (firstname, middleinitial, lastname, phone, email, street, city, state, gender) VALUES ('$firstname', '$middleinitial', '$lastname', '$phone', '$email', '$street', '$city', '$state', '$gender')"; // if ($categoryArray){ // foreach ($categoryArray as $category){ // $categoryString .= "'$".$category."',"; // } // } // $categoryquery = "INSERT INTO category (categoryname) VALUES('$categoryString')"; // $categoryquery = "INSERT INTO category (categoryname) VALUES(".$categoryString.")"; //insert the data mysql_query($memberquery); ?> The commented out block of code is just me trying to figure out how to insert an array into the db. |