mikosiko
Members-
Posts
1,327 -
Joined
-
Last visited
-
Days Won
1
Everything posted by mikosiko
-
the fact that you are using , instead of a dot to separate table name from column names is what is causing that error... and you have the same mistake in all others fields in your select
-
and when everything fail then is time to go back to the basic source of information http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_max
-
select multiple values from mysql between intervals
mikosiko replied to charles07's topic in PHP Coding Help
yes it is http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_timediff -
syntax error with updating one table into another table
mikosiko replied to Shadowing's topic in MySQL Help
http://dev.mysql.com/doc/refman/5.0/en/update.html -
NO, it is not... seems that you don't even know what are you posting.... your last post with your code was post #27, and later you posted that you were getting this error: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, string given in /home/pawz/public_html/kaboomlabs.com/testbed/edit.php on line 104 which is totally coincident with the missing "$data" , and my reply was related to that post.. so go back and read what you posted there and check for yourself.
-
I didn't read all your code... post it enclosed in tags in the future (using the # symbol in the editor) for clarity for the rest of us. what have you done to debug your code? a basic step to debug is at least echo your queries and or variables and see if they contain what they are supposed to... per example your code: mysql_query ("INSERT INTO users VALUES ('','$fullname','$username','$password','$date')"); will be much better for debugging purposes to write it in this way: $query = "INSERT INTO users VALUES ('','$fullname','$username','$password','$date')"; // and then echo your raw query and look for errors echo "Query is : " . $query . "<br />"; // and at least use a basic mechanism to trap possibles errors mysql_query( $query) or die('Query Error : ' . mysql_error()); and also will help your debugging if, while in development you enable the error reporting and display; either globally (in php.ini) or locally in each script using this 2 lines at the beginning of your scripts. error_reporting(E_ALL); ini_set("display_errors", 1);
-
don't just copy/paste without try to understand what you are doing... that will minimize your staring time .... look this is a portion of the code that you have in your very first post: // Grab the profile data from the database if (!isset($_GET['id'])) { $query = "SELECT * FROM ncmr WHERE id = '$id'"; } else { $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'"; } $data = mysqli_query($dbc, $query); and this is what you have now: // Grab the profile data from the database if (!isset($_GET['id'])) { $query = "SELECT * FROM ncmr WHERE id = '$id'"; } else { $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'"; } // echo your raw query and look for obvious errors echo "Query is : " . $query . "<br />"; // and at least use a basic mechanism to trap possibles errors mysqli_query($dbc, $query) or die('Query Error : ' . mysqli_error($dbc)); can you spot the difference?... $data is defined in your first one... the last one is not
-
Query matching multiple columns in multiple rows??? (serialized data?)
mikosiko replied to Jim R's topic in MySQL Help
use one of the options in my previous answers (the one that apply to what you want).. or test both and pick -
Query matching multiple columns in multiple rows??? (serialized data?)
mikosiko replied to Jim R's topic in MySQL Help
SELECT * FROM wp_usermeta WHERE meta_key = "wp_s2member_custom_fields" AND user_id IN (SELECT user_id FROM wp_usermeta WHERE meta_value LIKE "%s2member_level%") umeta_id,user_id,meta_key,meta_value 16484,1117,wp_capabilities,a:1:{s:15:"s2member_level2";s:1:"1";} 16491,1117,wp_s2member_custom_fields,a:1:{s:6:"county";s:1:"2";} please explain again in plain English what exactly do you have and what exactly do you need. to me looks like that you are asking for record that have meta_key = "wp_s2member_custom_fields" OR meta_value LIKE "%s2member_level%", but I'm just guessing... because could also be that you need meta_key = "wp_s2member_custom_fields" AND meta_value LIKE "%s2member_level%" -
well... yes... you are missing your $_GET['id'] lets do a little cleaning here: // Grab the profile data from the database if (!isset($_GET['id'])) { // Where are you defining your $id variable?.. this line doesn't make sense considering how your code works // if $_GET['id'] is not set then this script has been called incorrectly... trigger an error. $query = "SELECT * FROM ncmr WHERE id = '$id'"; } else { $query = "SELECT * FROM ncmr WHERE id = '" . $_GET['id'] . "'"; // You are wide open to sql injections here... take the $_GET[] out of here, sanitize it (CASTing it if numeric) // and assign it to a variable using that variable in this query } now... for the UPDATE $query = "UPDATE ncmr SET ab = '$ab', date = '$date', part = '$part', rev = '$rev' , partdesc = '$partdesc' , ncmrqty = '$ncmrqty' , comp = '$comp' , ncmrid = '$ncmrid' , rma = '$rma' , jno = '$jno' , fdt = '$fdt' , cof = '$cof' , fab1 = '$fab1' , fab2 = '$fab2' , fab3 = fab3' , non = '$non' , dis = '$dis' , comm = '$comm' , caad = '$caad' , po = '$po' , pod = '$pod' , dri = '$dri' WHERE id = '" . $_GET['id'] . "'"; again using the $_GET[] directly you are calling for trouble... take that out of there IMMEDIATELY if you care for the data that you have. most likely what do you want here in replacement for the $_GET['id'] is a sanitized variable as you did with the rest of the ones that you are using... just add a hidden input field in your form using $row['id'] as the value before this line, and use that in your update. echo '<div id="button2"><input type="submit" value="Submit Edits" name="submit" /></div>'; work on that and ask if you have further problems.
-
echo your raw query and look for errors $query = "UPDATE ncmr SET ab = '$ab', date = '$date', part = '$part', rev = '$rev' , partdesc = '$partdesc' , ncmrqty = '$ncmrqty' , comp = '$comp' , ncmrid = '$ncmrid' , rma = '$rma' , jno = '$jno' , fdt = '$fdt' , cof = '$cof' , fab1 = '$fab1' , fab2 = '$fab2' , fab3 = fab3' , non = '$non' , dis = '$dis' , comm = '$comm' , caad = '$caad' , po = '$po' , pod = '$pod' , dri = '$dri' WHERE id = '" . $_GET['id'] . "'"; // echo your raw query and look for obvious errors echo "Query is : " . $query . "<br />"; // and at least use a basic mechanism to trap possibles errors mysqli_query($dbc, $query) or die('Query Error : ' . mysqli_error($dbc)); while in development you should at least enable error reporting and display either globally (in php.ini) or locally in each script using this 2 lines by the beginning of your scripts. error_reporting(E_ALL); ini_set("display_errors", 1); in an additional note, I see that you are connecting/querying/looping 3 times over the table users (once for each "fab?") why?... you can do that only one time, store the values and use them as you need.
-
try this: SELECT j.id, j.date, j.cost, (SELECT i.rate FROM exchange i WHERE i.date <= j.date ORDER BY i.date DESC LIMIT 1) AS therate FROM jobs j;
-
mysql_query($query) or die ('Error registering'); echo " Successful!" something is missing in the last line
-
People You May Know Feature - Need Only Friends Friends
mikosiko replied to unemployment's topic in MySQL Help
with different aliases x.uname, y.uname, z.uname; matching the aliases used for JOINing the table users... in your case you should have x.firstname, x.lastname, y.firstname, y.lastname, z.firstname, z.lastname -
People You May Know Feature - Need Only Friends Friends
mikosiko replied to unemployment's topic in MySQL Help
here is the mock-up of a possible solution (tested)... replace/add your table field names and aliases SELECT a.uid, x.uname, a.fid, y.uname, b.fid, z.uname FROM partners a JOIN partners b ON a.fid = b.uid AND b.fid NOT IN ( SELECT m.fid FROM partners m JOIN partners n ON m.fid = n.uid WHERE m.uid =1) JOIN users x ON a.uid = x.uid JOIN users y ON a.fid = y.uid JOIN users z ON b.fid = z.uid WHERE a.uid =1; Note: uid = user_id uname = users.firstname or users.lastname // add fields as you need fid = friend_id The output of that query (using your data as example) is this 1, 'Jason', 2, 'Chelsea', 6, 'Jim' 1, 'Jason', 2, 'Chelsea', 12, 'Peter' 1, 'Jason', 2, 'Chelsea', 12, 'Cameron' 1, 'Jason', 2, 'Chelsea', 38, 'Felicia' 1, 'Jason', 4, 'Davey', 14, 'Jeffrey' 1, 'Jason', 5, 'Adam', 6, 'Jim' 1, 'Jason', 5, 'Adam', 14, 'Jeffrey' 1, 'Jason', 5, 'Adam', 17, 'Dan' 1, 'Jason', 20, 'Victor', 1, 'Jason' the last record (yourself) could be eliminated easily adding the condition to the last where -
+1 with Pikachu2000 suggestions... and to answer your last question... one way to do it is using the Modulus operator (%) http://php.net/manual/en/language.operators.arithmetic.php
-
I don't follow... your SUM(IF(migrate='YES',1,0)) is doing exactly that... is not clear from the select that you shown how you produce the output... - effdate is not shown in you final output and anyway it will not have any meaning at all because your GROUP BY. - carrier ... OK... it is shown. - COUNT(carrier)... is this the column 'Case' ?? - SUM(employees) ... is this your column 'Employees'?... what are you summing ?... the employees Id's? - COUNT(employees)... what column is this in your output?... seems logical to me that it should be your column 'employees' in your output. - SUM(IF...)) this is the column 'Migrated'?... should be.. an it represent the number of migrated employees for a carrier (the ones that have a 'YES' in the column Migrated in your table your last column '# of migrated employees' doesn't make sense to me... I do not understand from your explanations what that could be... maybe it make sense for someone else.
-
I understood that.... you didn't answer my question nor provided the required information ... asking again:
-
and what represent your column "Migrated" actually? or that is the column that you want to obtain? and post the exact SELECT that you have today to produce the result that you shown
-
The explanation of your apparent objectives (in bold) is really not clear to me, could you explain it better?.. an example showing part of your real data and the expected result will help to offer you an answer
-
this is one of those very common cases here where the signature of our good friend mjdamato apply perfectly: the solution offered to you apply and solve perfectly the example and objectives that you addressed in your first post, obviously if you changed the conditions the solution may or may not be correct. MORAL: post your real tables, describe your real problem and objectives and we could help you better.
-
this will do it: SELECT table_1.product_name, GROUP_CONCAT(IF(table_2.attribute_code = 'brand',table_2.value,NULL)) AS 'Brand', GROUP_CONCAT(IF(table_2.attribute_code = 'price',table_2.value,NULL)) AS 'Price' FROM table_1 JOIN table_2 ON table_1.id = table_2.product_id GROUP by table_1.id;
-
some comment added if (isset($_POST['close'])){ $idList = array_keys($_POST['close']); $idList = array_map('intval', $idList); $implValue = implode(',', $idList); $closequery = "UPDATE sellerinfo SET Closed='y' WHERE Index IN ($implValue)"; // Here you echo your raw query to validate if it is well formed and syntactically correct echo "The query is : " . $closequery . "<br/>". // Here you add a basic error control to trap any error during the query execution // die should be replaced for something better while code is in production.. like trigger_error per example mysql_query($closequery) or die("Query Error : " . mysql_error()); }
-
Referencing a table twice in a row with 2 different ID numbers
mikosiko replied to VoodooJai's topic in MySQL Help
seems that you are looking for something like this (replace table and columns name for the real ones) SELECT tbl1.horse1, tbl1.horse1_odds, b.fav AS Horse1_fav, tbl1.horse2, tbl1.horse2_odds, c.fav AS Horse2_fav, tbl1.horse3, tbl1.horse3_odds, d.fav AS Horse3_fav FROM tbl1 LEFT JOIN table2 AS b ON tbl1.horse1_fav = b.id LEFT JOIN table2 AS c ON tbl1.horse2_fav = c.id LEFT JOIN table2 AS d ON tbl1.horse3_fav = d.id in a side note; you should normalize your tabla 1 to eliminate the repeating groups (like horse*_odds and horse*_fav) (1NF violation)... examples & some further simple explanation here: http://www.troubleshooters.com/littstip/ltnorm.html