Jump to content

celsoendo

Members
  • Posts

    41
  • Joined

  • Last visited

About celsoendo

  • Birthday 04/06/1984

Profile Information

  • Gender
    Male

celsoendo's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. If you see the error message you'll see that variable $shoename is empty. By the way, if the column is a char/varchar column you must enclose the variable with quotes. $query ="SELECT rating , COUNT(*) AS rating_counts FROM rating WHERE item_name = '$shoename' GROUP BY rating"; With this, even if the variable is empty the query will not generate an error.
  2. DATEDIFF(date1, date2); http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html It returns on days, but you can apply some divisions to get all the info you want.
  3. Can you print the $sql variable just after all the ifs and elses?
  4. Try utf8_encode() or utf8_decode() on php after retrieving the data from mysql.
  5. <?php $myFile = file("file.txt"); ?> You can't do this never for one simple reason: memory. The function file reads the entire file an put it on an array. Arrays are stored on memory, memory is not unlimited, so memory blows up! The best to do is reading the file with a handle.... something like this: <?php $myFile = "file.txt"; // Open the file for read only from starting $myHandle = fopen($myFile, "r"); while (!feof($myHandle)) { // Read the line $myLine = fgets($myHandle, 8024); print $myLine ."\n"; } fclose($myHandle); ?> With this you are reading line by line... not the entire file all at once. The only limitation for this technique is the max_execution_time variable on your php.ini. Default is 30 seconds. If you need, you can put set_time_limit(0) on the top of your code and then no time limit will be imposed, then you can read any file of any size.
  6. Where is the php error generated when the dir exists?
  7. Do you want the php code to do this or sql queries?
  8. Maybe the directory you are trying to write doesn't have permissions to write.
  9. From PHP manual (http://www.php.net/manual/en/function.header.php): <?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past ?> After that you must print your javascript/css, but I think you don't need PHP to do this.... you can also do something like this: <script src="myscript.js?rnd=<?=time()?>"></script> It will print the current timestamp as a querystring for your js file, so the browser will always get the server version of the file and not from the local temporary dir.
  10. The $cfg array with connection settings is not global.... This array is outside the scope of function connect_db(). connect_db() can't "see" this array... when you try to run this function, it tries to connect with the web user (in your case, vhostswww) without password. The only way for your code to work is declaring $cfg as global inside the function connect_db (a bad practice anyway...): function connect_db() { global $cfg; $conn = mysql_connect($cfg["db"]["host"], $cfg["db"]["username"], $cfg["db"]["password"]) or die (mysql_error()); if ($conn) echo "Connection successful!"; mysql_select_db($cfg["db"]["name"]); }
  11. hmmm... I think this is not possible with pure mysql. But there is a workaround to do this... See: http://www.php-trivandrum.org/code-snippets/invoke-shell-from-mysql-trigger.html
  12. It depends on what type of reports do you want. If you want some OLAP tools, I think the best software to work with OLAP and MySQL is Pentaho (www.pentaho.com). It is open-source and free. But maybe this is too much for your needs... Depending on what do you want, maybe the best is to design the reports using php and some graphical component to generate graphics. But your database must be well designed so that you can retrieve data fast and with high performance.
  13. If you want to store a "log" per user, yes, you must have another table. I suggest that maint_msgs_user_link table has these columns: msg_id, user_id, date You can make msg_id and user_id a composite primary key. When you store action logs is always a good practice to store the date and time that the event occurred. This is why I added the column date on your table. Then you can retrieve the messages with this query: SELECT m.msg_id, m.msg, m.author, m.date_added FROM maint_msgs m WHERE NOT EXISTS (SELECT 1 FROM maint_msgs_user_link WHERE msg_id = m.msg_id AND user_id = $userId) AND CURDATE() BETWEEN m.date_start AND m.date_end;
  14. Why you repeat the column attribute_name on tbl_pd_options_link ? And why you have the column attribute_checked? It makes no sense. I think this table (tbl_pd_options_links) must have only 2 columns with primary key on these 2 columns: product_id and attribute_id. Then you store on this table ONLY the attributes that is checked for that product (n-n relationship). Then you can use a sql statement like this to select the attributes of a product that were not checked (availabe attributes): SELECT pda.* FROM tbl_pd_attribute pda WHERE NOT EXISTS (SELECT 1 FROM tbl_pd_options_link WHERE product_id = $productId AND attribute_id = pda.attribute_id); The query above will return all attributes available for the product $productId. Or you can return all attributes and an extra column saying if the attribute is checked or not: SELECT opt.*, pda.*, IF(pda.attribute_id IS NULL, 'no', 'yes') attribute_checked FROM tbl_pd_options_link opt LEFT JOIN tbl_pd_attribute pda ON (pda.attribute_id = opt.attribute_id) WHERE opt.product_id = $productId; Got it?
  15. Remember: php is a SERVER-SIDE language, NOT client-side, like javascript. It means that PHP scripts GENERATES html/xml/js/etc outputs. You can't embed PHP code directly on your html code to run it on client-side (browser). It means that if you make something like this: <p><?php echo "Hello World!"; ?></p> the server will interpret and process your php code BEFORE send data back to the client (browser). The visitor will see on source code: <p>Hello World!</p> He can't see php codes on source code because the server does not send it to the client. You can make things like this: <?php echo '<p>A simple counter:</p>'; for ($i = 0; $i < 10; $i++) { echo 'Number '. $i .'<br />'; } echo '<p>End counter!</p>'; ?> Got it?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.