jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
Multiple of different ways. <style type="text/css"> .class1 { background: #CC0000; } .class2 { background: #FF0000; } </style> <?php $i = 0; while ($i < 31) : ?> <table> <!-- BEGIN poll_option --> <tr class="<?php echo ((++$i % 2) == 0) ? "class2" : "class1";?>"> <td> .......... </td> </tr> <!-- END poll_option --> </table>
-
You could process your form before page output. Immediately after form processing, refresh the page. Then they can hit f5 all they want, and the form will not process again. Until they submit it, again.
-
$sock = @fsockopen($ip, $port, $num, $error, 5) //<-- Remove last argument, Letting it run the default timeout until you are sure your getting a connection. Then adjust.
-
I did a http://google.com search, and found this page.
-
I would concur with the last posters assessment.
-
Getting script to insert 40,000 rows without stopping
jcbones replied to RAELWEB's topic in PHP Coding Help
He isn't loading a file, he is trying to insert 40K rows into a mail table from an administrative mass message to all current users of a site. -
No what they mean is something on the lines of this: $query = mysql_query("SELECT id, username, lastname FROM users ORDER BY username ASC"); echo '<h1>Add Rota</h1> <table> <tr> <td><b>Presenter 1:</b></td> <td> <select name="presenter1"> <option value="0">Pick presenter</option> '; while ($row = mysql_fetch_array($query, MYSQL_NUM)) { $options[] = "<option value=\"{$row['0']}\">{$row['1']} {$row['2']} </option>\n"; } foreach($options as $v) { echo $v; } echo ' </select> </td> <td></td> <td></td> <td></td> </tr> <tr> <td><b>Presenter 2:</b></td> <td> <select name="presenter2"> <option value="0">Pick presenter</option> '; reset($options); foreach($options as $v) { echo $v; } echo ' </td>
-
UNDEFINED VARIABLES $ZeroHolder INFINTE LOOP while (strcmp(trim($Gate),trim($ZeroHolder)) <> 0) { //run while strcmp() is greater than, or less than 0 <-- INFINATELY.
-
Getting script to insert 40,000 rows without stopping
jcbones replied to RAELWEB's topic in PHP Coding Help
This is only a suggestion. It would need to be tested. Suggestion, let MySQL do all the work. 1. Create a temp table that holds the message. 2. Insert the message to the temp table. 3. Use a INSERT ... SELECT statement to populate the mail table. 4. Temp table destroys itself when the script ends. <?php $tmp = 'CREATE TEMPORARY TABLE message ( subject VARCHAR(50) NOT NULL , content TEXT NOT NULL , from VARCHAR(50) NOT NULL , ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP)'; mysql_query($tmp); $sql = "INSERT INTO message(subject,content,from) VALUES ('New Message','You have a new message.','Administrator')"; mysql_query($sql); $put_to_mail_table = "INSERT mail (subject,content,from,ts,to) SELECT message.subject,message.content,message.from,message.ts,user.id FROM message,user"; mysql_query($put_to_mail_table); ?> -
Sorting database table with links ASC & DESC
jcbones replied to firestarter30's topic in PHP Coding Help
Without code, it is hard to help you with the specifics. <?php if($_GET['order'] == 'd') { $orderBy = 'DESC'; $link = 'a'; } else { $orderBy = 'ASC'; $link = 'd'; } $sql .= ' ORDER BY id ' . $orderBy; echo $sql; ?> <a href="?order=<?php echo $link; ?>">Change Order</a> -
Calculate Distance Between Decimal Co-ordinates
jcbones replied to maxudaskin's topic in PHP Coding Help
I didn't pay attention to the build of your function, thought it was your own. Here is what I used on my test server. Function posted above <?php function distance($lat1, $lon1, $lat2, $lon2, $unit) { $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; $unit = strtoupper($unit); if ($unit == "K") { return ($miles * 1.609344); } else if ($unit == "N") { return ($miles * 0.8684); } else { return $miles; } } //hard coded your lat/lon into the function arguments. echo distance(43.68,-79.63,45.47,-73.74,'M') . ' Miles from Toronto to Montreal, Canada.'; echo distance(43.68,-79.63,45.47,-73.74,'K') . ' Kilometers from Toronto to Montreal, Canada.'; ?> Output 315.055202461 Miles from Toronto to Montreal, Canada. 507.032199749 Kilometers from Toronto to Montreal, Canada. -
Calculate Distance Between Decimal Co-ordinates
jcbones replied to maxudaskin's topic in PHP Coding Help
2 minutes with Google. NOT MY WORK, UN-TESTED, DON"T KNOW IF IT WILL WORK Calculations explained, Apparently -
That query should work, if you only have 3 columns in the table. Does it throw any errors? Have you checked if your variables are set to what you think they are? OR, perhaps You have initialized the variables, AFTER you make the database call, therefore, you are inserting empty values into a database.
-
Fatal error: Cannot use string offset as an array in C:\wamp\www\S
jcbones replied to silverglade's topic in PHP Coding Help
Somewhere above line 202: you have declared one of your variables as a string, therefore you cannot re-declare it as an array, unless done explicitly. -
Try this: <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Pick Your Poison</title> <style type="text/css"> * { margin: 0; padding: 0; } a, a:visited { text-decoration: none; color: #333333; } a:hover, a:active { text-decoration: underline; color: #000099; } h1 { font-family: serif; font-size: 35pt; margin: 10px; } .shot { border: 1px #F00 dashed; color: #00F; height: 250px; width: 200px; margin: 20px; margin-left: 50px; float: left; font-size: 30px; } .red { color: #F00; } .green { color: #0F0; } .grey { color: #CCC; } </style> </head> <?php for($i = 1; $i < 9; $i++) { $shot[$i] = 'available'; } //De-bug uncomment the next line. //echo 'start: <pre>'; print_r($shot); echo '</pre>'; if(isset($_POST['refresh'])) { unset($_SESSION['active']); } //De-bug, uncomment the next line: //echo 'Sesson: <pre>'; print_r($_SESSION); echo '</pre>'; if(isset($_SESSION['active'])) { for($i = 1; $i <9; $i++) { $shot[$i] = $_SESSION["s{$i}"]; } } //De-bug uncomment the next line: //echo 'Shot: <pre>'; print_r($shot); echo '</pre>'; //echo 'POST: <pre>'; print_r($_POST); echo '</pre>'; // To resolve "Notice: Undefined index: shot01-06" for($i = 1; $i < 9; $i++) { $shot[$i] = (!isset($_POST["shot0{$i}"])) ? $shot[$i] : $_POST["shot0{$i}"]; } $random = (!isset($_POST['random'])) ? 'false' : $_POST['random']; //De-bug uncomment the next line: //echo 'Shot: <pre>'; print_r($shot); echo '</pre>'; $_SESSION['active'] = 1; for($i = 1; $i < 9; $i++) { $_SESSION["s{$i}"] = $shot[$i]; } $result_poison = "red"; $result_safe = "green"; $result_out = "grey"; foreach($shot as $k => $v) { if($v == 'available') { $p[$k] = 1; } } if ($random == "true" && in_array('available',$shot)) { $poison = array_rand($p); } else { $poison = NULL; } ////////////// // SHOT 1-8 // ////////////// for ($i = 1; $i < 9; $i++) { if ($shot[$i] == "available") { if ($random == "true" && $poison == $i) { $result0[$i] = $result_poison; } else { $result0[$i] = $result_safe; } } elseif ($shot[$i] == "unavailable") { if ($random == "true" && $poison == $i) { $result0[$i] = $result_out; $poison = mt_rand(1,; } else { $result0[$i] = $result_out; } } else { $result0[$i] = NULL; } ; } ?> <body> <div align="center"> <h1>Pick Your Poison</h1><br /> <?php echo $poison ?><br /> <?php /* <p><a href="?shot01=<? echo $shot01; ?>&shot02=<? echo $shot02; ?>&shot03=<? echo $shot03; ?>&shot04=<? echo $shot04; ?>&shot05=<? echo $shot05 ?>&shot06=<? echo $shot06; ?>&shot07=<? echo $shot07; ?>&shot08=<? echo $shot08; ?>&random=true">Random</a></p> */ ?> <form action="" method="post"> <input type="hidden" name="random" value="true" /> <input type="submit" value="Random" /> </form> <span class="shot"><span class="number <?php echo $result0[1]; ?>">Shot Glass<br />#1</span><br /><br /> <form action="" method="post"> <input type="hidden" name="shot01" value="unavailable" /> <input type="submit" value="Out" /> </form><br /> <form action="" method="post"> <input type="hidden" name="shot01" value="available" /> <input type="submit" value="In" /> </form> </span> <span class="shot"><span class="number <?php echo $result0[2]; ?>">Shot Glass<br />#2</span><br /><br /> <form action="" method="post"> <input type="hidden" name="shot02" value="unavailable" /> <input type="submit" value="Out" /> </form><br /> <form action="" method="post"> <input type="hidden" name="shot02" value="available" /> <input type="submit" value="In" /> </form> </span> <span class="shot"><span class="number <?php echo $result0[3]; ?>">Shot Glass<br />#3</span><br /><br /> <form action="" method="post"> <input type="hidden" name="shot03" value="unavailable" /> <input type="submit" value="Out" /> </form><br /> <form action="" method="post"> <input type="hidden" name="shot03" value="available" /> <input type="submit" value="In" /> </form> </span> <span class="shot"><span class="number <?php echo $result0[4]; ?>">Shot Glass<br />#4</span><br /><br /> <form action="" method="post"> <input type="hidden" name="shot04" value="unavailable" /> <input type="submit" value="Out" /> </form><br /> <form action="" method="post"> <input type="hidden" name="shot04" value="available" /> <input type="submit" value="In" /> </form> </span><br /> <div style="clear:both"></div> <span class="shot"><span class="number <?php echo $result0[5]; ?>">Shot Glass<br />#5</span><br /><br /> <form action="" method="post"> <input type="hidden" name="shot05" value="unavailable" /> <input type="submit" value="Out" /> </form><br /> <form action="" method="post"> <input type="hidden" name="shot05" value="available" /> <input type="submit" value="In" /> </form> </span> <span class="shot"><span class="number <?php echo $result0[6]; ?>">Shot Glass<br />#6</span><br /><br /> <form action="" method="post"> <input type="hidden" name="shot06" value="unavailable" /> <input type="submit" value="Out" /> </form><br /> <form action="" method="post"> <input type="hidden" name="shot06" value="available" /> <input type="submit" value="In" /> </form> </span> <span class="shot"><span class="number <?php echo $result0[7]; ?>">Shot Glass<br />#7</span><br /><br /> <form action="" method="post"> <input type="hidden" name="shot07" value="unavailable" /> <input type="submit" value="Out" /> </form><br /> <form action="" method="post"> <input type="hidden" name="shot07" value="available" /> <input type="submit" value="In" /> </form> </span> <span class="shot"><span class="number <?php echo $result0[8]; ?>">Shot Glass<br />#8</span><br /><br /> <form action="" method="post"> <input type="hidden" name="shot08" value="unavailable" /> <input type="submit" value="Out" /> </form><br /> <form action="" method="post"> <input type="hidden" name="shot08" value="available" /> <input type="submit" value="In" /> </form> </span><br /> <div style="clear:both"></div> <form action="" method="post"> <input type="submit" name="refresh" value="Refresh" /> </form> </div>
-
How to make unselected checkbox destroy previous array on update
jcbones replied to ThunderVike's topic in PHP Coding Help
You could use a function like: function check_box($box) { if(isset($box) && is_array($box)) { return implode(', ',$box); } return NULL; } if (cp_str_starts_with($meta_key, 'cp_checkbox_charley') $meta_value= check_box($_POST['cp_checkbox_charley']); -
Just a note, Being that you are setting the value of a field where theme = 1, then all fields with theme equaling 1 will be updated. Which means, that on your first time through your loop, then all of the rows that have 'theme = 1', will be changed to 'theme = 0'. If you need it run by individual rows, you will need it to check against the PHOTO. Ideally you would want to check against an individual ID field, but it appears you don't have that in your table.
-
Searching an array within an array within an array
jcbones replied to Doublea's topic in PHP Coding Help
$show_id = '107510232628186'; foreach($movies['data'] as $user){ echo($user['name']." is ".($user['rsvp_status'] == "attending" && $user['id'] == $show_id)? "Attending" : "Not Attending"); } -
This may help MySQL Tables Tutorial
-
$allow_tags = '<html><body><b><a><p>'; $sanitize = strip_tags($contents, $allow_tags); echo $sanitize;
-
That is why it isn't working. You must have all of your code in a separate file. If $pic is defined in your main file, then pass it as a get parameter. main.php <?php $pic = 'somepic.jpg'; ?> <img src="pic.php?pic=<?php echo $pic; ?>" alt="<?php echo $pic; ?>"/> pic.php header('content-type: image/jpeg'); $pic = $_GET['pic']; $watermark = imagecreatefrompng('watermark1.png'); $image = imagecreatefromjpeg("/userImages/big/".$pic); imagecopymerge($image, $watermark, 5, 5, 0, 0, 135, 35, 100); imagejpeg($image); imagedestroy($image); imagedestroy($watermark);
-
Sure, pass the deptName in the URL as such. <a hef="http://domain.com/mypage.php?dept=deptName">deptName</a> Then replace this line. $deptName = 'get me a sandwich'; //with this one. $deptName = (isset($_GET['dept'])) ? mysql_real_escape_string($_GET['dept']) : 'defaultName';
-
Notification when a file is download from my site
jcbones replied to big-dog1965's topic in PHP Coding Help
What is the requirements for them to download a file? Nothing? Email address? Name? Do you want an email, or saved to a database? I suggest a database, that way you could echo the amount of downloads below the file, on the downloads page. download.php $file = $_GET['q']; $sql = "INSERT INTO downloads (filename,count,last_time) VALUES ('$file',1,NOW()) ON DUPLICATE KEY UPDATE count=count+1, last_time = NOW()"; mysql_query($sql); //start file download... download table CREATE TABLE `downloads` ( `id` int(11) NOT NULL auto_increment, `filename` varchar(50) NOT NULL, `count` int(11) NOT NULL, `last_time` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `filename` (`filename`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; This is in the simplest form available. -
You have to have the header() function in there for it to work. You are merging the $watermark into the $image, but if $image isn't returning an image, then it will fail. Are you sure that $pic is set, and is a valid image in that directory?
-
Unable to display items located in another TABLE
jcbones replied to crzbadboy's topic in PHP Coding Help
Run this as a test script, and see what you get. test.php <?php if(isset($_POST['submit'])) { $sql = "select l.*,a.* from listings as l, agents as a where l.seller = a.id and (l.`price` = '$_REQUEST[q]' or l.`mls`='$_REQUEST[q]' or l.`seller`='$_REQUEST[q]' or l.`class`='$_REQUEST[q]' or l.`status`='$_REQUEST[q]') order by `price` asc"; $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { while($row = mysql_fetch_assoc($result) { echo $row['agentname'] . ' is selling ' . $row['description'] . ' located at ' . $row['location'] . ' for ' . $row['price'] . '<br />'; $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 '<img src="' . $image['filename'] . '" alt="' . $image['filenamedesc'] . '" /><p>' . $image['imagename'] . '</p>' . "<br />\n"; } } } } } ?> <form action="" method="post"> <input type="text" name="q" value="" /> <input type="submit" name="submit" value=" Search " /> </form>