premiso
Members-
Posts
6,951 -
Joined
-
Last visited
-
Days Won
2
Everything posted by premiso
-
If you are simplying parsing a url, use the parse_url function. $path = parse_url($url, PHP_URL_PATH); echo $path; And a correction to AyKay's code, the $matches[0] does not return the first match, it returns the fully matched string. $matches[1] returns the first match as identified by the parenthesis.
-
Have you tried echoing out all the variables and attempting to run that command in a command line environment, to make sure that it is not producing any errors? If not do that, but this is really not a PHP issue, unless the paths are messed up. You will probably do better to take it to the ffmpeg people.
-
Arrays are not a MySQL thing. They are done on the PHP side of things. You will want to use UNION. $query = 'SELECT count(*) FROM table_a UNION SELECT count(*) FROM table_b;' $query = mysql_query($query) or trigger_error('SQL Failed: ' . mysql_error()); if (is_resource($query)) $rows = array(); while ($row = mysql_fetch_row($query)) { $rows[] = $row[0]; } // index 0 will be table a index 1 will be table b: echo 'Table A count is: ' . $rows[0] . ' and Table b's count is: ' . $rows[1]; }
-
file_get_contents was not built for handling cookies etc. You should really look into curl as that is it's sole intention is fetching websites. It can handle cookies just fine and you will find plenty of examples of that at the manual and on google. Not to mention it will be at least 3x faster in retrieving the content over file_get_contents.
-
So whats the problem then? If it is not writing well, either A: permissions issue, B: Something else in the code is screwing it up and you need to post the full code for further help.
-
Nope, and I don't plan on looking it up for you. Some one else may know, but your better bet is to use your Google-Fu.
-
It is not possible without a 3rd party software that can interpret it. If you have that third party software and you can access via a command line interface, sure. I would imagine it would work just fine.
-
Is there any way too pass variables through include files.
premiso replied to Orionsbelter's topic in PHP Coding Help
To add the btherl's answer. If you have the included file using $_GET already, you can do this: $_GET['var1'] = 'one'; include('file.php'); And not have to change the file.php code. -
Drummin, you do realize that 1 query, vs several is always preferred and way more efficient. Why waste calls when you can do it one go? Second, doing a select * with num_rows is just so.... inefficient and just wrong... it really saddens me that this advice was ever given. That would have to select all the rows, and they would be stored as a resource. He just wants the number of rows, which is easily obtained with a count(*) and done so way more efficiently without wasting resources. So yea, just bad advice all around.
-
I said remove the top level select: SELECT COUNT(*) as forums FROM ".TBL_PREFIX."forums AS f UNION SELECT COUNT(*) as topics FROM ".TBL_PREFIX."topics AS t UNION SELECT COUNT(*) as posts FROM ".TBL_PREFIX."posts AS p Is all you should use. Details make or break ya.
-
Why are you summing it? A union statement alone should work just fine. The count gives you the total on a single line, so the SUM part is just not needed. I would remove that top level select and just use the UNION.
-
Is there a more efficient way to handle this?
premiso replied to thebusiness's topic in PHP Coding Help
if ($row['rating'] >= 0.1 && $row['rating'] < .5) { $rate = '05'; } // .. the rest of the ifstatements, setting the rate to be the 2 digit number $random_game_mini['rate'] = '<img src="'.$setting['site_url'].'/'.$setting['template_url'].'/images/minirating' . $rate . '.png" height="12" width="61">'; You can probably stream line it bit better if you wanted, I am just too distracted to really to want to try right now -
It seems that the blog.COUNT function does not exist. Looking at the query, either you didn't paste the whole thing, something is overwriting your query or something in your database has gone funky. If you can I would run a few simple count queries, like SELECT COUNT(*) FROM comments; And see if that works. If it does, well make sure that the $sql is what it should be: $posts = mysql_query($sql) or trigger_error('SQL Failed: ' . $sql . '<br>Error: ' . mysql_error());
-
Change this line: $posts = mysql_query($sql); To be: $posts = mysql_query($sql) or trigger_error('SQL Failed: ' . mysql_error()); And see what SQL error is being thrown.
-
ereg_replace is also depreciated. Stick to using preg_replace for that reason alone
-
PHP is server side. Either way, AJAX or JS or HTML you still need to code that anchor link to work and get the extra data you need. You could perhaps pass a parameter called "extra" inside the link so on the Reviews.php, you see if $_GET['extra'] has been set, if it has then you just display the extra data. So yea, it shouldn't be too complicated, you just have to code it. If you want it to be fancy and styled and flow better, well AJAX / JS would be the way to go. If you just want to open a new window, the link you have is fine, you just have to code the Reviews to display what you want displayed.
-
IrOnMaSk, there really is no effectiveness or efficiency. Ideally you should separate the business logic from view logic. On the view side is where the html etc would be placed, without requiring to echo out any html code. This would keep your business logic clean and make it a ton easier for changes in the future, IE you just have to change the HTML side of things instead of tinkering with the actual code. That is just my 2cents however. But yes, you can echo any html tag from within PHP.
-
$fh=fopen('sitemap.html', 'w'); fwrite($fh, $html2write); fclose($fh); Pretty simple.
-
PHP Date Difference in Hours with a working twist!
premiso replied to vapourmike's topic in PHP Coding Help
Even though I didn't see any real effort you put into it, I was intrigued. I wrote it up, this does not take into account weekends or holidays. You will have to figure that part out. But for the most part should give you an accurate account of the number of working hours. <?php function workingHours($stDate, $enDate) { $busHours = 8.5; $interval = $stDate->diff($enDate); $totalHours = ($interval->d * 24) + $interval->h; $days = $interval->d; // If the total hours is exactly 24, we do not want to add 1. if (($totalHours % 24) != 0 && $interval->format('%R') == "+") $days += 1; return $totalHours - ($days * (24 - $busHours)); } // Time stamps can be used instead - // $start = new datetime('@'. time()); // where time() is the timestamp $start = new datetime('2011-07-12 10:00:00'); $end = new datetime('2011-07-13 10:00:00'); echo workingHours($start, $end); Not perfect, but at least you have something to work off of. This will only work on PHP 5.3, given I like the DateTime function. If you need it without that, well you will just have to work that out, but at least you have the logic more or less. -
zander1983 has it right, use arrays. They will be much easier to understand and perform better. If you want to just know how to get your code to work: $i=0; $temp = 'mycode' . $i; $$temp = "stuff"; echo $mycode0; Should do it, this technique is called, variables variable.
-
Which is better to use echo 'Hello world' or echo "Hello world" ?
premiso replied to colap's topic in PHP Coding Help
For the sake of argument, echo is faster than print, by a margin. Single quotes, will of course be faster than double quotes. Why? Because single quotes do not have to parse string data inside of them. That being said, the difference is marginal that you would not know the difference in the end. So it really comes down to preference. I prefer to use the single quotes for echo'ing, as when I echo it is generally with HTML and I prefer not to mess with escaping quotes if at all possible. -
Remove the while loop. Then replace this: if (empty($error)){ mysql_query("UPDATE table1 SET field1='$value1' WHERE field2 IN ('" . implode("','", $_POST['checkbox_value']) . "')"); } For security reasons, you may want to run mysql_real_escape_string on the $_POST['checkbox_value'] through an array_map to help prevent SQL injection, but that should get you to where you want to be. IE: $_POST['checkbox_values'] = array_map('mysql_real_escape_string', $_POST['checkbox_values']); if (empty($error)){ mysql_query("UPDATE table1 SET field1='$value1' WHERE field2 IN ('" . implode("','", $_POST['checkbox_value']) . "')"); } Pending any errors I may have.
-
Or his local server has output buffering enabled.
-
/* Side Note */ ereg_replace is depreciated. You can easily migrate it to preg_replace, here is an example: preg_replace("#[^A-Za-z0-9]#", "", $_POST['name']); /* End Side Note */
-
htmlentities strip_tags preg_replace are all viable solutions to your problem. And next time, choose a better, more descriptive subject title. Help is just so fuckin annoying.