jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
No, you must have mis-understood what I said. $query = yasDB_select("SELECT *,DATE_FORMAT(`timestamp`,'%b %e, %y, %r') AS formatted_time FROM newsblog WHERE userid = '$id'");
-
Perhaps Poster is set, but is empty. mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("movies") or die(mysql_error()); $f = mysql_query("SELECT * FROM movies") or die(mysql_error()); while($inf = mysql_fetch_assoc($f)) { $two= $inf['id']; $link = "http://www.imdbapi.com/?i=$two"; $thr = file_get_contents($link); $json = json_decode($thr,true); if(!empty($json['Poster'])) { echo "<img src='".$json['Poster']."' />"; }
-
You will have to post more code. The answers you have been given are correct. If for some reason they are not working for you, then there must be something else in the code causing it to break.
-
You will need to use AJAX for that.
-
Deprecated: Function session_is_registered() is deprecated in
jcbones replied to Function's topic in PHP Coding Help
unset doesn't return a value, so just move it up a line. function tep_session_unregister($variable) { unset($_SESSION[$variable]); return; } -
From when? Within the same year? I would start by determining the amount of weeks that have passed, as there is only 1 Saturday per week. A few simple checks to see if today is a Saturday date, or if the starting day is a Saturday. You would be well on your way.
-
To get the desired format using MySQL's date functions, add this to your select statement. DATE_FORMAT(`timestamp`,'%b %e, %y, %r') AS formatted_time as in: SELECT *,DATE_FORMAT(`timestamp`,'%b %e, %y, %r') AS formatted_time FROM table; Then change your output to: echo '<div class="newsblog_box1"><div class="newsblog_name">' . $row['name'] . ' '.$row['formatted_time'].'</div></div> <div class="newsblog_box2">' . $text . '</div>';
-
I suppose that you could use file_get_contents() (if fopen wrappers are enabled). this will return false if the file can't be accessed. I don't think the external site would like you hitting the image twice though, they may not even like you hitting the image at all.
-
Have you tried putting an A in there, notice the capital. See if that works. I've never had a problem getting am/pm to show.
-
Make a new column, set it to default at the current timestamp.
-
They are indexes in a multidimensional array. PHP arrays-manual
-
Deprecated: Function session_is_registered() is deprecated in
jcbones replied to Function's topic in PHP Coding Help
function tep_session_is_registered($variable) { return isset($_SESSION[$variable]); } function tep_session_unregister($variable) { return unset($_SESSION[$variable]); } -
I'm not sure why you need it to wait 20 seconds before adding slaves. Rather, you should be checking that 20 seconds has passed before adding the slaves to the table. By checking if the date2 that is currently stored is less than the current time, we know that 20 seconds have passed, otherwise it will not update the column. You should also be checking the user, so I threw that in there as well. UPDATE users2 SET slaves=slaves+1, date2=DATE_ADD(NOW(),INTERVAL 20 SECOND) WHERE date2 < NOW() AND user = '$currentUser';
-
My interpretation with the original code that I posted. <?php <?php $field1 = "Farms to " . $_POST['farms_population']; $a = array($field1, $field2, $field3, $field4, $field5, $field6); //no need to quote variables. foreach($a as $k => $v) { //foreach value in an array. if(empty($v)) { //if the value is empty (you will not need it, because it doesn't hold a value). unset($a[$k]); //so get rid of it. } } //if the array still contains more than 2 indexes if(count($a) > 1) { $lastIndex = array_pop($a); //remove the last index and store it in a variable all its own. } $_SESSION['changed'] = "You have changed " . implode(", ",$a); //now implode will work properly. $_SESSION['changed'] .= (isset($lastIndex)) ? ' and ' . $lastIndex : NULL; //if the lastIndex variable exists, then append it, otherwise append nothing. echo $_SESSION['changed']; ?>
-
I would suggest a simpler concept, (unless I mis-understand the problem). <?php <?php $field1 = "Farms to " . $_POST['farms_population']; $a = array($field1, $field2, $field3, $field4, $field5, $field6); //no need to quote variables. foreach($a as $k => $v) { //foreach value in an array. if(empty($v)) { //if the value is empty (you will not need it, because it doesn't hold a value). unset($a[$k]); //so get rid of it. } } $_SESSION['changed'] = "You have changed " . implode(" and ",$a); //now implode will work properly. echo $_SESSION['changed']; ?>
-
So, you need to drop the #1#, and split the string into an array on +447980123456? <?php function parse_csv($line,$delimiter=',',$quote = '"',$newline="\n") { $line = str_replace("\r\n",$newline,$line); //change extended newlines. $line = str_replace("\n",$newline,$line); //this is here in case you pass a different newline to the function. $line = str_replace('"",""','',$line); //remove double quoted commas. $line = str_replace($quote,'',$line); //remove quotes. $line = preg_replace('~,{2,}~',',',$line); //remove double commas. if(strstr($line,$newline)) { $parts = explode($newline,$line); //all new lines should be an array. } if(isset($parts) && is_array($parts)) { //if a newline exists foreach($parts as $value) { //rerun the function on each line. $result = parse_csv($value,$delimiter,$quote,$newline); //only include the results, if there is more than 1 line; if(isset($result[1])) { $arr[] = $result; } } } else { $arr = explode($delimiter,$line); //make an array based on the delimiter. //cleanup = delete lines that has no values. foreach($arr as $k => $v) { if(empty($v)) { unset($arr[$k]); } } } return $arr; } $file ='#1# "4","+447980123456","+447781484145","","2009-06-08","10:38:15","hello "","" world","Orange" "5","+447980123456","+447781484146","","2009-07-08","10:38:55","hello world","Orange"'; $array = parse_csv($file,',','"',"+447980123456"); echo '<pre>' . print_r($array,true) . '</pre>'; //show the array construct. //echoing the values out. foreach($array as $key => $value) { echo '<h4>' . $key . '</h4>'; foreach($value as $v2) { echo $v2 . '<br />'; } echo '<hr />'; } ?> This function would put each line in a separate array. Where as your current function puts it all in one array, which is much harder to separate out. commented up, hope it helps you along the way.
-
Crontab (cron job) is to Linux what Schedule Task is to Windows. Crontab reference What does this all mean? Well, you create a php script that does the desired task, then set the crontab to execute that script at a certain time. To list out your example, it would flow as. Crontab calls a php file. The php file checks to see if someones domain is about to expire, if it is and they are not flagged as email sent, they are sent an email. Then their account is flagged as email sent. Script ends.
-
Have you tried to put the query directly in the console or other database software (phpmyadmin)?
-
<?php // Product data Update $name = mysql_real_escape_string($_POST['product']); $cost = mysql_real_escape_string($_POST['cost']); $details = mysql_real_escape_string($_POST['details']); $sql_title = "INSERT INTO product ( product , cost , details , ) VALUES ( '$name' , '$cost' , '$details')"; $re = mysql_query($sql_title,$con) or trigger_error(mysql_error()); if($re) { echo "records for product added<br />"; $productId = mysql_insert_id(); } $filtername = mysql_real_escape_string($filtername); $filterimgpath = mysql_real_escape_string($filterimg); $combined_array = array_combine($filtername, $filterimgpath); $values = array(); foreach ($combined_array as $filtername => $filterimgpath) { $values[] = "('$filtername', '$filterimgpath')"; } $sql = "INSERT INTO filter (filter , imgpath) VALUES " . implode(',', $values); $values = array(); $rf = mysql_query($sql,$con) or trigger_error(mysql_error()); if($rf) { echo "records added<br />"; $rf_id = mysql_insert_id();//if we inserted 3 rows, we should get the last row's id returned. $count = count($combined_array); //so we build values based on the productId, and then take the last insert id in the filters table, //and decrement it on each loop, based on your combined array. //since the id is auto-incremented, it should be in numerical order. Reversing it is not a problem. for($i = 0,$n = $rf_id; $i < $count; $i++,$n--) { $values[] = '(' . $productId . ',' . $n . ')'; } $sql = 'INSERT INTO product_filter(id_product,id_filter) VALUES ' . implode(',',$values); if(mysql_query($sql)) { echo "records tied together<br />"; } else { trigger_error(mysql_error()); } } else { trigger_error(mysql_error()); echo 'Filters failed to insert, no images tied to the product!'; }
-
two result in two horizontal columns without table
jcbones replied to whynot's topic in PHP Coding Help
The problem is that you are not communicating what you are looking for very well. Can you give us an example of your expected output? -
You are most welcome. Glad it is sorted out.
-
Post EVERYTHING you have related to this topic. It will get sorted quickly. As of now, we can only guess at what you have currently.
-
Table and columns are not wrapped in quotes ('), but can be wrapped in backticks(`). Unless you run into reserved keywords, I would just drop the quotes and add nothing. $query = mysql_query("SELECT id, title, post FROM posts") or die("<b>Your error is:</b><br />\n" . mysql_error());
-
two result in two horizontal columns without table
jcbones replied to whynot's topic in PHP Coding Help
<?php $i = 0; //set variable I as 0 echo '<div style="float:left;">'; //start a division. while($row = mysql_fetch_assoc($result)) { //fetch the data. if(++$i == 5) { //if $i has passed 4 which means 4 lines have been printed, close the division and open another. echo '</div><div>'; } echo implode(',<br />',$row); //echo the data. } echo '</div>'; //close the final division.