jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
Set a hidden field if the user is updating the information. In your process script, check for that hidden field, if it is there, update, if not insert.
-
This script uses php and javascript, and I set it to 30 seconds for you. It uses sessions so that if you refresh the page, it will keep the countdown. After reaching 0 it will remain, until a page refresh, then it returns to the 30 second countdown. <?php session_start(); $timestamp = time(); $diff = 30; if(isset($_SESSION['ts'])) { $slice = ($timestamp - $_SESSION['ts']); $diff = $diff - $slice; } if(!isset($_SESSION['ts']) || $diff > 30 || $diff < 0) { $diff = 30; $_SESSION['ts'] = $timestamp; } //Below is demonstration of output. Seconds could be passed to Javascript. $diff; //$diff holds seconds less than 3600 (1 hour); $hours = floor($diff / 3600) . ' : '; $diff = $diff % 3600; $minutes = floor($diff / 60) . ' : '; $diff = $diff % 60; $seconds = $diff; ?> <div id="strclock">Clock Here!</div> <script type="text/javascript"> var hour = <?php echo floor($hours); ?>; var min = <?php echo floor($minutes); ?>; var sec = <?php echo floor($seconds); ?> function countdown() { if(sec <= 0 && min > 0) { sec = 59; min -= 1; } else if(min <= 0 && sec <= 0) { min = 0; sec = 0; } else { sec -= 1; } if(min <= 0 && hour > 0) { min = 59; hour -= 1; } var pat = /^[0-9]{1}$/; sec = (pat.test(sec) == true) ? '0'+sec : sec; min = (pat.test(min) == true) ? '0'+min : min; hour = (pat.test(hour) == true) ? '0'+hour : hour; document.getElementById('strclock').innerHTML = hour+":"+min+":"+sec; setTimeout("countdown()",1000); } countdown(); </script>
-
Unable to display items located in another TABLE
jcbones replied to crzbadboy's topic in PHP Coding Help
Being that you want to show multiple images per listing, I don't think a join would work to well for you. You can however do it this way. $sql = "select * from listings where `price` = '$_REQUEST[q]' or `mls`='$_REQUEST[q]' or `seller`='$_REQUEST[q]' or `class`='$_REQUEST[q]' or `status`='$_REQUEST[q]' order by `price` asc"; $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { while($row = mysql_fetch_assoc($result) { echo $rowstuff; $images = "SELECT * FROM images WHERE mls = '{$row['mls']}'"; $re = mysql_query($images); if(mysql_num_rows($re) > 0) { while($image = mysql_fetch_assoc($re)) { echo $imagestuff; } } } } -
IF exchange placements - what have I done wrong?
jcbones replied to jasper1106's topic in PHP Coding Help
Try it this way: //top of script. $ranks = array('Cadet','Sergeant','2nd Lieutenant','1st Lieutenant','Captain','Major','Lt. Colonel','Colonel'); //inside the while loop, replace these lines. $tableData .= " <tr bgcolor='#FFFFFF' align='center'>\n"; $tableData .= '<td>' . $ranks[$rank] . '</td>' . "\n"; -
Fatal error: Cannot redeclare limitatexto() (previously declared in...
jcbones replied to Beppis's topic in PHP Coding Help
OR, you are including that page twice inside another script. -
Unable to display items located in another TABLE
jcbones replied to crzbadboy's topic in PHP Coding Help
What are your fields in LISTINGS, and what are your fields in IMAGES, and which fields should connect the two? Are there mulitple rows in IMAGES for each LISTING? -
Lets start simple. Since you have a page for each department, make the calendar a separate script, and include it into each page. Then query the database for events on each department page, and set your variables for the calendar. In this way, you don't have to capture the department from the URL at all. Get me a sandwich department $deptName = 'Get me a sandwich'; $smmonth = date('m'); $smyear = date('Y'); $tquery = "select * from events where month='$smmonth' and year='$smyear' and deptid='$deptName'" ; echo $tquery; include_once('mycalendar.php');
-
You should be accessing that column as: entrantstuff. Or, just remove "AS entrantstuff".
-
Error_log: Invalid argument supplied for foreach()
jcbones replied to Serellyn's topic in PHP Coding Help
I suspect you thought I missed an arrow, but I didn't. //Incorrect: $items[$row['artistname']] => $row['artistID']; //Correct: $items[$row['artistname']] = $row['artistID']; This would be the only reason, that I can think of, for PHP to see a double arrow on that line. -
What is difference between php date and mysql NOW() ??
jcbones replied to eevan79's topic in PHP Coding Help
Correct, NOW() is synonym for CURRENT_TIMESTAMP(), and CURDATE() is synonym for CURRENT_DATE(). -
Unable to display items located in another TABLE
jcbones replied to crzbadboy's topic in PHP Coding Help
You are asking the database to pull from the listings and images table via the variable $_SESSION, which is a superglobal ARRAY, and therefore, you are looking for an id named 'Array'. 2 suggestions. Make sure you are getting the query you want, by echoing the query out. $images = "select * from images where id='$_SESSION'"; $sqlimages = mysql_query($images); echo $images; I suspect you will not get what you think you should be getting. And, Don't write PHP in Dreamweaver, it tends to bloat a script with a lot of useless stuff. Leading to a confusing mess, that is difficult to debug. -
need an example using php_rand on a multidimensional array please
jcbones replied to silverglade's topic in PHP Coding Help
This line gets the random area's $random = array_rand($monsters); Simply change it to: $random = 'Ocean'; -
I would set the timeout to 0. This would wait until you get a response. After you are sure you're getting a response, then adjust the timeout.
-
need an example using php_rand on a multidimensional array please
jcbones replied to silverglade's topic in PHP Coding Help
Multi- dimensional arrays are a little more difficult to work with in this way. Try something like this: <?php $monsters = array ( 'Ocean'=>array ( 'octalisk'=>array ( 'name'=>'octalisk', 'hp'=>100, 'damageLow'=>1, 'damageHigh'=>15, 'exp'=>10, 'ac'=>'HAVE TO LOOK THIS UP', 'monsterInitiativeModifier'=>'HAVE TO LOOK THIS UP'), 'shark', 'eel' ), 'Desert'=>array ( 'sand_snake' ), 'Forest'=>array ( 'frog', 'lizard', 'spider' ) ); $random = array_rand($monsters); $monster = array_rand($monsters[$random]); if(is_array($monsters[$random][$monster])) { $currentMonster = $monsters[$random][$monster]['name']; } else { $currentMonster = $monsters[$random][$monster]; } echo $currentMonster; ?> -
$string is too big? I can not see what my problem is..
jcbones replied to avelonz's topic in PHP Coding Help
IT returns failed, because one of these: if($subject && $activity1 && $activity2 && $activity0) Returns as false. -
Having a litle problem with a membership script here
jcbones replied to sanmagician's topic in PHP Coding Help
Every single one of {'s has to have a matching }, or you will get an un-expected end. AS for your update. //fix this line: echo '<script>alert("The email you have entred is an invalid email address.")';</script>; //To this: echo '<script>alert("The email you have entred is an invalid email address.")</script>'; //And remove else { //From the very bottom. -
Lets get down to everything, so that you can get this running. 3 different ways. 1. Make subfolders for each department, and place an index page inside each folder. http://domain.com/departName/index.php preg_match('~http://domain.com/(.*)/*~',$_SERVER['REQUEST_URI'],$match); $EVENT_TB = $match[1]; $tquery = "select * from ".$EVENTS_TB." where ".$EVENTS_TB.".month='".$smmonth."' and ".$EVENTS_TB.".year='".$smyear."' and ".$EVENTS_TB.".deptid='deptFromQueryString' " ; echo $tquery; 2. Put the department name into the queryString, and point the string to ONE page. index.php <p>Select a department</p> <a href="?dept=deptA">Department A</a><br /> <a href="?dept=deptB">Department B</a><br /> <?php $EVENT_TB = (isset($_GET['dept'])) ? $_GET['dept'] : 'deptA'; $tquery = "select * from ".$EVENTS_TB." where ".$EVENTS_TB.".month='".$smmonth."' and ".$EVENTS_TB.".year='".$smyear."' and ".$EVENTS_TB.".deptid='deptFromQueryString' " ; echo $tquery; ?> 3. Make a .htaccess file that will point to the correct department. .htaccess Options +FollowSymlinks RewriteEngine on RewriteRule ^/Departments/(.*)$ index.php?dept=$1 Then make your page index.php <p>Select a department</p> <a href="http://domain.com/Departments/deptA">Department A</a><br /> <a href="http://domain.com/Departments/deptB">Department B</a><br /> <?php $EVENT_TB = (isset($_GET['dept'])) ? $_GET['dept'] : 'deptA'; $tquery = "select * from ".$EVENTS_TB." where ".$EVENTS_TB.".month='".$smmonth."' and ".$EVENTS_TB.".year='".$smyear."' and ".$EVENTS_TB.".deptid='deptFromQueryString' " ; echo $tquery; ?>
-
Assuming that you are NOT using mod_rewrite. This is put in the simplest of forms. It is basic only, and may need some tweaking for your use. preg_match('~/(.*)/*~',$_SERVER['REQUEST_URI'],$match); $event = $match[1]; echo $event;
-
$str = '/176-0723275-0880505'; $str = preg_replace('~/[0-9]{3}-[0-9]{7}-[0-9]{7}~','',$str);
-
Error_log: Invalid argument supplied for foreach()
jcbones replied to Serellyn's topic in PHP Coding Help
In your original script, I would suggest changing: //This line: $items = array($row['artistname'] => $row['artistID']); //To this: $items[$row['artistname']] = $row['artistID']; Leaving the rest as it is, and see how it works. -
Is there anyway to make an array not start at "0"?
jcbones replied to Lucky2710's topic in PHP Coding Help
<?php for($i = 1; $i < 10; $i++) { $flip[$i] = 'Yes'; } echo '<pre>'; print_r($flip); echo '</pre>'; ?> Outputs Array ( [1] => Yes [2] => Yes [3] => Yes [4] => Yes [5] => Yes [6] => Yes [7] => Yes [8] => Yes [9] => Yes ) -
This should get you started. <?php function uploadFile($name) { foreach($_FILES[$name] as $k => $v) { echo '<br />' . $k . ': ' . $v; } return; } if(isset($_POST['submit'])) { uploadFile('file'); } ?> <form action="" method="post" enctype="multipart/form-data"> <input type="file" name="file"/> <input type="submit" name="submit" value="submit" /> </form>
-
include 'db_connect.php'; //include database connection info. $filename = 'text.txt'; //name of the text file. $db_table = 'my_table'; //name of your database table. $file = file($filename); //get contents of the text file in an array. foreach($file as $line) { //perform the following actions for each line in the text file. $ex = explode('-',$line); //split the line on the dash $id = trim($ex[0]); //trim the value before the dash, this is the id. $name = trim($ex[1]); //trim the value after the dash, this is the name. $sql = "INSERT INTO $db_table VALUES ('$id','$name')"; //put the data into a query. mysql_query($sql); //send it to the database. }
-
//Change $_FILES['uploadedfile']['name'] //To $_FILES['uploaded']['name']
-
include 'db_connect.php'; $filename = 'text.txt'; $db_table = 'my_table'; $file = file($filename); foreach($file as $line) { $ex = explode('-',$line); $id = trim($ex[0]); $name = trim($ex[1]); $sql = "INSERT INTO $db_table VALUES ('$id','$name')"; mysql_query($sql); } Something like that should get it done. There are other ways to do it, that would be faster. This is just a simplistic example.