-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
If the user chooses the "All" option then you can leave that column and the condition value out of the query
-
You can't bind column names, only values $pp1 = 'Beginner'; $pp2 = 'Intermediate'; $ll = 7; $room_no = 4; $query = "SELECT md.Member_reg_id, md.fname, md.lname, md.email, md.cell, ms.level, ms.diff, ms.score, r.ID_Status FROM register as r JOIN member_detail as md ON r.ID = md.Member_reg_id JOIN memstatus as ms On r.ID = ms.ID WHERE r.CENTERCODE = ? AND r.ID_Status ='A' AND ms.level IN (?,?) AND ms.diff <= ? ORDER by level, diff, score DESC"; $stmt=$fcon->prepare($query); $stmt->bind_param('issi',$room_no,$pp1,$pp2,$ll);
-
The string that you are echoing finishes at the ' after location.href= You need to escape the single quotes within the string echo'<input name="Enabled" type="button" value="Enabled" onclick="location.href=\'../edit.php\'"/>';
-
One connection will suffice, and when you decide on MySQLi or PDO, use a prepared query. And you do not specify which column the value $killforumid should be written to
-
Of the two I think confusion is the more likely option. You brilliant coding merely takes an array that looks like this $row = array( array('CID'=>100,'Country'=>'France'), array('CID'=>200,'Country'=>'Germany'), array('CID'=>300,'Country'=>'Holland') ); and converts it to an array that looks like this $countries = array( array('0'=>100,'1'=>'France'), array('0'=>200,'1'=>'Germany'), array('0'=>300,'1'=>'Holland') ); when what is really required is an array that looks like this $countries = array( '100'=>'France', '200'=>'Germany', '300'=>'Holland' ); CroNiX already gave the solution in #17, so why are you muddying the water?
-
Running script depending on client Public IP
Barand replied to angelcause's topic in PHP Coding Help
I'd test for localhost otherwise remote. -
You need to to connect to the server before you can select a database. You also need to send the POST data from the form. Check that data has been posted before trying to use the posted data ( isset() )
-
All you are doing in the code in insert.php is defining a string. You have to execute the query defined in that string.
-
echo
-
Those COUNTs need to be SUMs SELECT SUM(IF(level='P1',1, NULL)) 'P1', SUM(IF(level='P2',1, NULL)) 'P2', SUM(IF(level='P3',1, NULL)) 'P3' FROM faults
-
pdo runs twice when everything else is commented out
Barand replied to Q695's topic in PHP Coding Help
Strange, then, that the examples in the manual have the colons http://php.net/manual/en/pdostatement.execute.php (examples #1, #2) -
So. There a 3 level 2 users (Tom, Tommy, Kim) so they each receive £4.50/3 (ie £1.50 each) There is 1 level 3 user (Henry) so he receives £13.50.
-
So given this situation frank --- tommy --- tom jimmy --- kim --- --- henry Frank (2 refers) gets 1.05 Jimmy (1 refer) gets 1.00 Kim (1 refer) gets 1.00 Is that right?
-
We live and learn. I haven't used that one before.
-
$a[2014][123456]['EMPS']=114350; $b[2014][60]['EMPS']=1470; $c = $a; foreach ($b as $y => $ydata) { foreach ($ydata as $k => $v) { $c[$y][$k] = $v; } } echo '<pre>',print_r($c, true),'</pre>'; /* RESULT Array ( [2014] => Array ( [123456] => Array ( [EMPS] => 114350 ) [60] => Array ( [EMPS] => 1470 ) ) ) */
-
Are you sure those are the correct columns for your join?
-
Yes, I know. But there is no way that I can I help with that one line of code quoted out of context. The code was tested before posting. BTW, the recursive code I just posted is not the same as that posted earlier in this thread.
-
It's just the same problem in reverse. If you use the query method, reverse the fields in the joins $sql = "SELECT r.id , r.acct_name , r.ref_id , r1.acct_name as first , r2.acct_name as second , r3.acct_name as third , r4.acct_name as fourth FROM test_referral r LEFT JOIN test_referral r1 ON r1.refer_id = r.ref_id LEFT JOIN test_referral r2 ON r2.refer_id = r1.ref_id LEFT JOIN test_referral r3 ON r3.refer_id = r2.ref_id LEFT JOIN test_referral r4 ON r4.refer_id = r3.ref_id WHERE r.acct_name = 'john' ORDER by id"; +----+-----------+--------+-------+---------+-------+--------+ | id | acct_name | ref_id | first | second | third | fourth | +----+-----------+--------+-------+---------+-------+--------+ | 1 | john | J1234 | frank | tommy | NULL | NULL | | 1 | john | J1234 | doe | girly | NULL | NULL | | 1 | john | J1234 | bull | ronaldo | NULL | NULL | | 1 | john | J1234 | jimmy | kim | henry | fred | | 1 | john | J1234 | frank | tom | NULL | NULL | +----+-----------+--------+-------+---------+-------+--------+ Or if you want to go to any depth, use the recursion method $sql = "SELECT id , acct_name , ref_id , refer_id FROM test_referral"; $data = array(); $res = $mysqli->query($sql); while ($row = $res->fetch_assoc()) { $names[$row['ref_id']] = $row['acct_name']; $data[$row['refer_id']][] = $row['ref_id']; } $id = 'J1234'; getRefs($data, $names, $id); // // recursive function to get list of referrees // function getRefs(&$data, &$names, $id, $level=0) { $indent = str_repeat('--- ', $level); echo "$indent {$names[$id]}<br>"; if (isset($data[$id])) { foreach ($data[$id] as $refid) { getRefs($data, $names, $refid, $level+1); } } } /// OUTPUTS ////////////////////// john --- bull --- --- ronaldo --- doe --- --- girly --- frank --- --- tommy --- --- tom --- jimmy --- --- kim --- --- --- henry --- --- --- --- fred
-
use exit instead of break
-
These are my results mysql> select * from test_referral; +----+-----------+--------+----------+ | id | acct_name | ref_id | refer_id | +----+-----------+--------+----------+ | 1 | john | J1234 | 0 | | 2 | bull | B3456 | J1234 | | 3 | doe | D5567 | J1234 | | 4 | frank | F7788 | J1234 | | 5 | jimmy | J9990 | J1234 | | 6 | tommy | T6784 | F7788 | | 7 | tom | T9988 | F7788 | | 8 | girly | G8866 | D5567 | | 9 | fred | F0099 | H7654 | | 10 | ronaldo | R7722 | B3456 | | 11 | henry | H7654 | K1234 | | 12 | kim | K1234 | J9990 | +----+-----------+--------+----------+ SELECT r.id , r.acct_name , r.ref_id , r1.acct_name as first , r2.acct_name as second , r3.acct_name as third , r4.acct_name as fourth FROM test_referral r LEFT JOIN test_referral r1 ON r.refer_id = r1.ref_id LEFT JOIN test_referral r2 ON r1.refer_id = r2.ref_id LEFT JOIN test_referral r3 ON r2.refer_id = r3.ref_id LEFT JOIN test_referral r4 ON r3.refer_id = r4.ref_id WHERE r.acct_name = 'fred' ORDER by id; +----+-----------+--------+-------+--------+-------+--------+ | id | acct_name | ref_id | first | second | third | fourth | +----+-----------+--------+-------+--------+-------+--------+ | 9 | fred | F0099 | henry | kim | jimmy | john | +----+-----------+--------+-------+--------+-------+--------+
-
Add a TIMESTAMP type column and ORDER BY that.
-
I have run your query against the test_referral table that you provided (after adding adding a couple of extra referrals to give a chain of 4 names) and it works fine. I can only assume the problem is when you run it against your ca_categories table, which I cannot help with.
-
If you are after the id of the record just inserted into movimiento, use mysql_insert_id() http://php.net/manual/en/function.mysql-insert-id.php
-
To get the values automatically you close your eyes and make a wish. However, as this seldom works, you have to write the code. Why are you looping 3 times through the same array? $maxshipping1=$maxshipping2=$maxqty=0; foreach ($_SESSION['products'] as $prod) { $maxshipping1 = max($maxshipping1, $prod['shipping1']); $maxshipping2 = max($maxshipping2, $prod['shipping2']); $maxqty = max($maxqty, $prod['qty']); if ($prod['qty'] >= 2) { echo $prod['product'] . '<br>'; echo "Ship1: " . $prod["shipping1"] . '<br>'; echo "Ship2: " . $prod["shipping2"] . '<br><br>'; } }
-
With a left join, cust_fname and cust_number will be NULL where there is no customer record matching the site record