PHP - Check If A Number Is In A Times Table
Hi Guys just need some advice really
I would like to know if there is a way I can check if a number is in a times table for example if(3 is in 4 times table){ do bla bla } the result for above will be false as 4 times table does not contain 3 if(12 is in 4 times table){ do bla bla } the above would be true Thanks guys Similar TutorialsHello, I'm new! I am trying to populate a list of locations based on ratings. I can populate the list just fine but it's displaying every record in the table. Is there a way of only looping 4 times so as to just display the top 4 records? Here's the code: Code: [Select] $result = mysql_query("SELECT * FROM locations ORDER BY rating DESC"); while($row = mysql_fetch_array($result)) { echo $row['name']; echo "<br>; } Thankyou in advance for any help
I want to run this loop until it has created 50 or a 100 links, max. At present it continues running even though no inputs are being added to the database. I suspect, it keeps looping through and collecting duplicates and then not adding them to the database. I see this as two options, I either limit the number of loops or must find someway for the pages that have already been crawled to be skipped. I am busy doing a php course and the lecturer is not answering questions about how the code could be improved. I figure that if you are going to do something in a training course it should be able to do what it needs to and if it doesn't it needs a little alteration. function followLinks($url) { global $alreadyCrawled; global $crawling; global $hosta; $parser = new DomDocumentParser($url); $linkList = $parser->getLinks(); foreach($linkList as $link) { $href = $link->getAttribute("href"); if((substr($href, 0, 3) !== "../") AND (strpos($href, "imagimedia") === false)) { continue; } else if(strpos($href, "#") !== false) { continue; } else if(substr($href, 0, 11) == "javascript:") { continue; } $href = createLink($href, $url); if(!in_array($href, $alreadyCrawled)) { $alreadyCrawled[] = $href; $crawling[] = $href; getDetails($href); } } array_shift($crawling); foreach($crawling as $site) { followLinks($site); } Edited January 29 by guymclarenza added info How do you make php code repeat for a certain amount of times. I am only new to php and I am trying to make the code below repeat 6 times instead of repeating all the matching elements in the database. From my other coding experience I would use a for loop but as I am new to php I am not really sure how to implement the for and while loops together. I was trying to add an integer that incremented until it hit 6 and then would exit the while loop but I couldn't get it to work. This is probably a simple problem and any help would be appricated. Thanks. Code: [Select] <?php $subject_set = mysql_query("Select * FROM movies WHERE media = 'Movies' ORDER BY dateadded DESC", $connection); if (!$subject_set){ die("Database connection failed: " . mysql_error()); } while ($subject = mysql_fetch_array($subject_set)){?> <div class="par_element"> <div class="repeat_horizontal"> <div class="repeat_hor_picture"> <a href="<?=$subject['link']?>"> <img src=" <?=$subject['picture']?>" /></a> </div> <a href=" <?=$subject['link']?>"><?= $subject['title']?>.</a> </div> <?php } ?> E.g. 18:00 - 22:30 $a = "18:00"; $b = "22:30"; this would return 4.5 (hours) 22:00 - 01:00 would return 3 hours i HAVE FOLLOWING VALUES IN FEED TABLE
a1a a1b a1c a1d ......
7 8 7 7
8 9 8 8
9 7 7 8
7 8 10 9
6 4 6 7
7 8 8 5
9 7 7 6
This in an array ( select a1a,a1b,a1c,a1d from feed where .....)
1) I want to know how many times each values has occured in the array ( eg: 7 occured 10 times, 8 occured 8 times)
2) How many 7's, 8's, 9's are there in a1a, howmany .....in a1b
Number of times each values occured OVERALL in array as well as also under each head
Please help
Code: [Select] if ($month <= 9){ if ($list_day <= 9){ $event_day = $year.'-'."0".$month.'-'."0".$list_day; if(isset($events[$event_day])) { foreach($events[$event_day] as $event) { $calendar.= '<div class="event">'.$event['event_date'].'</div>'; } } } Right, using a mysql query the value from $event['event_Date'] prints out in a div. I need a number count of the amount of times this value is printed. any help? hello,
i have an event reservation system. i need to make sure that every time someone is booking a new time, it's not overlap another reservation.
for example lets say i have an event reserved starting at X and ending at Y
X = Wed Sep 10 2014 07:30:00 GMT+0000 Y = Wed Sep 10 2014 08:00:00 GMT+0000and now im reserving a new event start = Wed Sep 10 2014 09:30:00 GMT+0000 end = Wed Sep 10 2014 09:30:00 GMT+0000how can i check if they are not crushing? lets say the first event starts at 12:00 and end 14:00, i need to make sure that the new event is not held between these hours. it need to be started and end before 12:00 or after 14:00. thanks in advance! Hello, I'm working on an error form, and I want to check if the user inserted a number into the name field, and if so return an error. I thought this might of worked, but it doesn't: Code: [Select] if(is_int($_POST['name'])){ $arrErrors['name'] = 'Invalid name, remove numbers.'; } Many thanks Hello, I'm currently creating a little script, and want to assign a random number to a row in the MySQL table as soon as it will be inserted. But that number may not have been used before. How will I do this? I tried if else thingies, but then the code would be very long (just in case it randomly picks 10 times after each other a number that exists). $randomnumber = rand(10000000, 99999999); if(mysql_num_rows(mysql_query("SELECT * FROM table WHERE randomnumber='".$randomnumber."')) == 1) { $randomnumber = rand(10000000, 99999999); if(mysql_num_rows(mysql_query("SELECT * FROM table WHERE randomnumber='".$randomnumber."')) == 1) { $randomnumber = rand(10000000, 99999999); }else { // Insert into database } }else { // Insert into database } I hope you understand my problem. Regards, Hi, I'm totally new to PHP and I'm afraid I don't understand a lot yet. However, I need to make this: when you fill in a number in a form, it should be displayed whether the number is odd or even. I tried the following code, which is obviously not working and I have no idea on how to fix this. Code: [Select] <?php $var = $_POST['var']; for ($i = 0; $i < $var; $i++) { if ($i % 2 == 0) { print("even"); } else { print("odd"); } } ?> I was wondering if anyone knows a good way to check for an even number of each character in a string. For example if the string is "abbacc" then it will return true as there are two of each character. However if the string is "ababc" it will return false as there is only 1 c. Thanks for any help Ok, I need some serious help here. I have a jQuery .load method that retrieves a single users name from a database. However... I also need to incorporate error checking into the script that the .load method access, so that, if the user enters a name in the field that is not in the database, it will insert it into the database, and then then pull it back out again to be returned by the ajax call. This is the jQuery that performs the call: Code: [Select] $('#submit').click(function(e) { var user = $('#user').val(); var checkurl = "indexData.php"; $('#username').load(checkurl, 'user=' + user); e.preventDefault(); }); This is the script form indexData.php: Code: [Select] <?php $db = mysql_pconnect('localhost', 'joeme0', 'Galatians2'); if (!$db) { die('Could not connect: ' . mysql_error()); } mysql_select_db('joeme0_brave'); $name = $_POST['name']; $checkQuery = "select name from users where name='$name'"; $checkResult = mysql_query($checkQuery); if ($checkResult > 1) { $insQuery = "insert into users (id, name) values ("", '$name')"; $insResult = mysql_query($insQuery); if ($insResul 0) { $query="select name from users where name='$name'"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { echo $row['name']; } } else { echo "Cold not insert your name into the database"; } } else { $query="select name from users where name='$name'"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { echo $row['name']; } } ?> So far I can get it to pull out a name that is manually entered into the database no problem. But I can't get it to insert a name that isn't in the database, and then query the database a second time to pull that same name back out again. The page is pretty simple. The user comes to the page, enters their name in the text field, either clicks the submit button or presses the enter key. The scripts fire off the ajax call to the database, check to see if the name exists, if not enter it and pull it back out (this is where I have the problem), if so, pull it out and display it back on the page. hi friends could someone help with this criteria? i want to restrict entry to db if the post value number was entered into db less than 31 days ago?
if($homePhone == '') { $qry = "SELECT * FROM table WHERE homePhone='$homePhone '";in db i store time in datetime current timestamp like 2013-07-13 21:19:15 could someone help me out? Edited by lovephp, 12 July 2014 - 11:36 AM. As I title says; I need to have an image showed the number of times, the value of a table/field.. How can I do this? Hi, How can I check if a variable only has these characters: - number (0-9) - decimal point (.) - positive (+) - negative (-) - dollar ($) I tried is_numeric, but it doesn't like negative values... I need to add the variable value to another variable. I have to accept numbers (including negative and decimals)... ex: 0.1 = TRUE -.1 = TRUE 12 = TRUE 1000.00 = TRUE 12a = FALSE thanks 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! I'm getting the dreaded " Invalid parameter number: number of bound variables does not match number of tokens" error and I've looked at this for days. Here is what my table looks like:
| id | int(4) | NO | PRI | NULL | auto_increment | | user_id | int(4) | NO | | NULL | | | recipient | varchar(30) | NO | | NULL | | | subject | varchar(25) | YES | | NULL | | | cc_email | varchar(30) | YES | | NULL | | | reply | varchar(20) | YES | | NULL | | | location | varchar(50) | YES | | NULL | | | stationery | varchar(40) | YES | | NULL | | | ink_color | varchar(12) | YES | | NULL | | | fontchosen | varchar(30) | YES | | NULL | | | message | varchar(500) | NO | | NULL | | | attachment | varchar(40) | YES | | NULL | | | messageDate | datetime | YES | | NULL |Here are my params: $params = array( ':user_id' => $userid, ':recipient' => $this->message_vars['recipient'], ':subject' => $this->message_vars['subject'], ':cc_email' => $this->message_vars['cc_email'], ':reply' => $this->message_vars['reply'], ':location' => $this->message_vars['location'], ':stationery' => $this->message_vars['stationery'], ':ink_color' => $this->message_vars['ink_color'], ':fontchosen' => $this->message_vars['fontchosen'], ':message' => $messageInput, ':attachment' => $this->message_vars['attachment'], ':messageDate' => $date );Here is my sql: $sql = "INSERT INTO messages (user_id,recipient, subject, cc_email, reply, location,stationery, ink_color, fontchosen, message,attachment) VALUES( $userid, :recipient, :subject, :cc_email, :reply, :location, :stationery, :ink_color, :fontchosen, $messageInput, :attachment, $date);"; And lastly, here is how I am calling it: $dbh = parent::$dbh; $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); if (empty($dbh)) return false; $stmt = $dbh->prepare($sql); $stmt->execute($params) or die(print_r($stmt->errorInfo(), true)); if (!$stmt) { print_r($dbh->errorInfo()); }I know my userid is valid and and the date is set above (I've echo'd these out to make sure). Since the id is auto_increment, I do not put that in my sql (though I've tried that too), nor in my params (tried that too). What am I missing? I feel certain it is something small, but I have spent days checking commas, semi-colons and spelling. Can anyone see what I'm doing wrong? When displaying data from a mysql table, what php code can I use to display the number of columns in said table? Like, say I'm displaying comments by users. I want to be able to put "displaying 'thismany' comments". Any suggestions? Hi, I have a problem regarding counting rows in a mysql table. Here is the code: Code: [Select] <?php require_once('includes/connection.inc.php'); $conn = dbConnect('read'); $check = 'SELECT COUNT(*) FROM images'; $checkRes = $conn->query($check) or die(mysqli_error()); if($checkRes <= 0) { header('Location: empty_blog.php'); // redirect to another page } else { // do something else... } ?> The error I'm getting: "Notice: Object of class mysqli_result could not be converted to int in C:\xampp\htdocs\photoblog\index.php on line 6" Any help is greatly appreciated! How do you do this? Thanks in advance. |