-
Posts
1,807 -
Joined
-
Last visited
Posts posted by hitman6003
-
-
Why are you executing the same query twice?
The second time you are querying (for the exact same data) you are using "mysql_query", not "mysqli_query".
-
$result = "mysql_query($query)";
...should not be in quotes.
-
$times isn't defined and $n will always equal 10 (100 / 10 = 10), so the line that reads "$values[] = rand(1, $n)" may as well read "$values[] = rand(1, 10)". Also the second for loop will execute 6 times, not 5.
-
Warning ahead of time...I haven't tested any code........
$pet_names = array('bob', 'sue', 'larry', 'bill'); // find pets who are in the database as adopted and in your array of names $result = mysql_query('SELECT * FROM pets WHERE name IN("' . implode("\",", $pet_names) . '")'); // put the adopted pets into their own array while ($row = mysql_fetch_assoc($result)) { $adopted[] = $row['name']; } // determine the unadopted pets from the full list using array_diff $not_adopted = array_diff($pet_names, $adopted);
-
arguably the simplest way....
$total = 100; $values = array(); for ($i = 1; $i <= 4; $i++) { $values[] = rand(1, 20); } $values[] = $total - array_sum($values); echo "<pre>Values are:\n" . print_r($values, true) . "</pre>";
No excessive amount of looping involving a where loop or anything which could iterate thousands of times before it hits the correct numbers. Only caveat being the last number will be very different....ranging from 20 to 96 versus 1 to 20 for the others. A little more logic could solve that though....
-
Are you sure that a file is being uploaded? Check the contents of the $_POST super global...
echo "<pre>" . print_r($_POST, true) . "</pre>";
-
The only way to chain method invocations is to return the object from the previous call.
-
JOIN the tables and use a "GROUP BY" statement...
SELECT fid, forum, desc, COUNT(fid) FROM forum_titles ft LEFT JOIN forum_questions fq ON fq.fid = ft.fid GROUP BY fid
-
Use MySQL's "GROUP BY" clause:
http://dev.mysql.com/doc/refman/5.1/en/group-by-functions.html
Or, depending on what you are wanting, "DISTINCT".
SELECT DISTINCT(referrer) FROM tablename
-
-
The manual states that the stat functions are not supported for http/https locations. This means that file_exists will not function.
http://www.php.net/file_exists (see the "Notes" section)
http://www.php.net/wrappers.http (see the "Wrapper Summary" section)
-
Use the modulus operator: http://php.net/language.operators.arithmetic
if ($i % 10 == 0) { echo "true"; }
-
So escape them...or use a single quote...
echo '<input type="text" name="ausername" maxlength="12" size=30 style="background-color: #FA1B00;" value="' . $_POST['ausername'] . '">';
Rocket surgery...
-
You're missing basic html...
This
echo "<input type="text" name="ausername" maxlength="12" size=30 background-color=#FA1B00 value="<?=$_POST['ausername']?>";
should be
echo "<input type="text" name="ausername" maxlength="12" size=30 style="background-color: #FA1B00;" value="<?=$_POST['ausername']?>";
-
Or use a combo of substr and strpos...
echo substr($string, 0, strpos("-", $string));
-
what is the header you are sending to the browser? Is it hard coded to gif?
-
Is there some advanced php template producer?
You could use any one of the many frameworks. I'm most familiar with Zend (http://framework.zend.com) and I know that their form class(es) can do what you want.
They use an especially nice decorator format that makes things easy to change. Padriac Brady wrote a nice tutorial about ZF a while back: http://blog.astrumfutura.com/archives/367-Example-Zend-Framework-Blog-Application-Tutorial-Parts-1-8-Revisited.html
-
time returns the unix timestamp, which is an integer.
I think you want to pass something like this...
date = date("d-m-Y", time());
-
Not without getting eccentric...you could use array_walk or something of that sort, but at that point it becomes more difficult to read to get the same result an you only save 2 lines of code...
-
Yes, you can remove the close/open php tag pair without it affecting anything.
-
Using Zend's PDF class you can open and manipulate PDF files...
http://framework.zend.com/manual/en/zend.pdf.html
-
There are two reference points that you can use...
The first is the "document root". This is the directory that is the base for all the webpages on the server. For example, if you install the apache RPM on RHEL/CentOS it defaults to /var/www/html. When you have a link in your html and you put "/" in the link, for example:
<a href="/some/random/page.php">test</a>
The browser will look to the document root.
The other reference point is the file system. When you include a file, using php's include or require functions, it references the file system. So the path you use references the "root" of the file system.
This means that doing
include("/web/includes/somefile.php");
will look for a file outside of the tree of documents that the web server references. In the above example for a link, the actual referenced file would be at a location similar to "/var/www/html/some/random/page.php".
This is important when you are including documents in your php scripts because sometimes you want to put a file to be included outside of the document tree that the webserver can access. For example, if you have a php file that contains your MySQL credentials, you don't want just anyone to be able to use their browser and point to "/some/random/mysql_credentials.php" to get the connection information.
For the majority of files though, they are simply code that contains nothing sensitive. Using the $_SERVER['DOCUMENT_ROOT'] variable is a simple way of providing the absolute path for including a file, while that path still remaining flexible (because not everyone has the same document root).
-
Cookies store data only on the client side, every page visit the data is sent to the server.
Sessions store data on the server. A client cookie is used to identify which user is accessing the page in order to determine which session data file to read. The actual session data is not stored in a cookie, only the session identifier.
However, with sessions the cookie is optional. When the cookie behavior is turned off the session identifier will be passed to the server in the url (you most often see this in search engine results, when the url has something like "sessionid=......" in it)
-
Use a for loop...
<?php for ($i = 0; $i < 10; $i ++) { $entry = $sxml_twitter->channel->item[$i]; $news_title = $entry->description; $date = $entry->pubDate; echo " <ul> <li class='tweet'>$news_title</li> <li class='date_twitter'>$date</li> </ul>"; } ?>
unexpected T_EXIT
in PHP Coding Help
Posted
Which line is 44?