jazzman1
Staff Alumni-
Posts
2,713 -
Joined
-
Last visited
-
Days Won
12
Everything posted by jazzman1
-
Start from here: if (validadres($email) == false ) { $errors[] = "The given e-mail address is not valid."; } You can not assign boolean or some values like this to the function. This is wrong! Start to re-design the script, I found deprecated php functions too.
-
I really appreciate your responses guys
-
No, forget it to change "double" to "decimal", it works just fine. I've made exactly same table structure like yours, and this works fine. $query = "SELECT SUM(amount - Newamount) AS TOTALSMALL FROM mytable WHERE Newamount != '0.00'";
-
Change "double" to "decimal". I think that type of table is not correct in this particular case, but I'm not sure 100%.
-
Take a look at here -> http://stackoverflow.com/questions/6761118/change-css-property-dynamically-in-php
-
Explain the table structure, please. $query = "EXPLAIN `mytable`"
-
Warning: oci_free_statement(): 3 is not a valid oci8 statement resource
jazzman1 replied to benphp's topic in PHP Coding Help
What is your database ? -
She want's to be maybe: <?php function myFunc($arg1, $arg2=NULL){ if($arg2 == NULL){ $arg2 = array('Some other data', $arg1, 'more data'); } return $arg2; } echo '<pre>'.print_r(myFunc(1)).'</pre>';
-
With CASE operator, the sql is a little more complex, but it is possible to achieve the same result using only one query. Check this out -> http://www.karlrixon.co.uk/writing/update-multiple-rows-with-different-values-and-a-single-sql-query/
-
@ zetcoby, NEVER EVER do this! Queries in loops make me start to sweat nervously. I wrote a simple script for you, just to make a note, how to avoid the queries in loops. As you mentioned above you have a 2 tables and 4 columns - `id`,`var`,`val`and `page` ! Take a look at an example: // An array containing navigation list $nav_list = array('nav_home','nav_project','nav_forum','nav_db','nav_contact','nav_faq'); // start array with index 1 $iOne = array_combine(range(1, count($nav_list)), array_values($nav_list)); // implode keys of $iOne... $ids= implode(", ", array_keys($iOne)); // build query..... // using CASE SQL operator updating `val` column $sql = "UPDATE `tbl_name` SET `tbl_name`.`val` = CASE `tbl_name`.`id` "; // looping result array foreach ($iOne as $key => $val) { $sql .= sprintf("WHEN %d THEN '%s' ", $key, $val); } $sql .= "END WHERE `tbl_name`.`id` IN ($ids)"; echo '<pre>'.print_r($sql, true).'</pre>'; // proper output //UPDATE `tbl_name` SET `tbl_name`.`val` = CASE `tbl_name`.`id`WHEN 1 THEN 'nav_home' WHEN 2 THEN 'nav_project' WHEN 3 THEN 'nav_forum' //WHEN 4 THEN 'nav_db' WHEN 5 THEN 'nav_contact' WHEN 6 THEN 'nav_faq' END WHERE `tbl_name`.`id` IN (1, 2, 3, 4, 5, 6) // execute query........ $result = mysql_query($sql) or die(mysql_error()); PS.Now in this particular example, only 6 rows are being updated, but 5 queries have been trimed.... If you need to update multiple fields, this is easily done just by adding another CASE block. Take a look at here -> http://www.delphipraxis.net/161775-%5Bmysql%5D-multiple-row-update.html#post1112695 UPDATE `mytable` SET `color` = CASE id WHEN 2 THEN 255 END, `position` = CASE id WHEN 1 THEN 5 END
-
B/s empty and isset function doesn't work with constants. Simple test: define("CONSTANT", "Hello world."); if(empty (CONSTANT)){ echo CONSTANT; } else if(isset(CONSTANT)){ echo '....'; } else { echo CONSTANT; } You have to use defined() if (defined('CONSTANT')) { echo CONSTANT; }
-
You need learn more of OOP and PDO. In this case use: if (self::SLAVE1_HOST))
-
Yes, but everything is there You have to post the class, b/s I don't know the structure. Try if (!self::SLAVE1_HOST))
-
Yes, you can! Don't repeat the same thing multiple times. Use arrays and loops.
-
No, start from here -> http://php.net/manual/en/language.oop5.php
-
If you replaced self::SLAVE1_HOST with $var, what happened? if(!empty ($var)){ }
-
If you try to change the $id with some correct integer, what happened ? @off forget it, I saw the result - cat = 1. PS, start with fetch_array(MYSQLI_ASSOC)
-
Yes, you can, but does not make sense b/s it will show you only one error -> mysql_error(). You have to use functions to show you multiple errors, for example mysqli_connect error number or something else.. mysql_query($sql) or showError(mysqli_connect_errno()); function showError($error = null) { trigger_error($error); exit; }
-
Start to debug the content of $row. In the while loop copy/paste this piece of code - echo '<pre>'.print_r($row, true).'</pre>'; exit; Post the result and compare it with the result of phpMyAdmin $result = yasDB_select("SELECT `t`.`id` , `t`.`subject` , DATE_FORMAT( `p`.`timestamp` , '%b %e, %y, %r' ) AS `formatted_time` , `p`.`name` , `t`.`cat` FROM `forumtopics` AS `t` , `forumposts` AS `p` WHERE `t`.`cat` =$id ORDER BY `t`.`id` DESC LIMIT 1"); while($row = $result->fetch_array(MYSQLI_ASSOC)) { echo '<pre>'.print_r($row, true).'</pre>'; exit; etc....................
-
@Davie33, copy/paste my query string in your phpMyAdmin's SQL tab, just to check the result of it. If everything is good, that's mean you have a problem in your php script. P.S Instead $id replaced with some integer
-
You probably have others errors somewhere in your code. With the same table structure I've got a correct result from my DB: SELECT `t`.`id` , `t`.`subject` , DATE_FORMAT( `p`.`timestamp` , '%b %e, %y, %r' ) AS `formatted_time` , `p`.`name` , `t`.`cat` FROM `forumtopics` AS `t` , `forumposts` AS `p` WHERE `t`.`cat` =2 ORDER BY `t`.`id` DESC LIMIT 1 // output Array ( [0] => 1 [id] => 1 [1] => test [subject] => test [2] => Aug 13, 12, 09:04:20 PM [formatted_time] => Aug 13, 12, 09:04:20 PM [3] => forum of post [name] => forum of post [4] => 2 [cat] => 2 ) PS. Maybe forumposts` .``timestamp` and `forumposts` .`name` has the same values with `forumtopics`.`timestamp` and `forumtopics`.`name` , I don't know just check the columns.
-
Little mistake : WHERE `t`.`cat` =2 to be WHERE `t`.`cat` =$id
-
Okay, I've re-written the query string that you gave us above, it could be like this: SELECT `t`.`id` , `t`.`subject` , DATE_FORMAT( `p`.`timestamp` , '%b %e, %y, %r' ) AS `formatted_time` , `p`.`name` , `t`.`cat` FROM `forumtopics` AS `t` , `forumposts` AS `p` WHERE `t`.`cat` =2 ORDER BY `t`.`id` DESC LIMIT 1
-
Have you tried dumping the querie's strings ? I've got one, but I'm sure you have more than one errors. Wrong: $result = yasDB_select("SELECT id, subject, cat FROM forumtopics WHERE cat = '$id' AND (SELECT id, name, DATE_FORMAT(`timestamp`,'%b %e, %y, %r') AS formatted_time FROM forumposts WHERE topicid = '$id')");