Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. No you haven't. They should be name = "state[]" Then foreach ($_POST['state'] as $state) { $statearray[] = $mysql_real_escape_string($state); } $states = implode ("','", $statearray); $sql = "SELECT * FROM channel WHERE state IN ('$states')";
  2. for example mysql> SELECT CONCAT(batch, id) as id -> , name -> FROM person -> ORDER BY batch; +-------+--------+ | id | name | +-------+--------+ | 36001 | Brock | | 36002 | Barand | | 53001 | Cary | | 53002 | Josh | +-------+--------+ and your client doesn't have to care what's going on behind the scenes.
  3. It's use isn't that uncommon, for example while ($row = $result->fetch_row()) { or if (($pos = strpos($x, $y, 0)) !== false) {
  4. Firstly, don't store multiple fields in a single field, separate the batch and the id into separate columns. Use a MyISAM table and you can make the second part of a compound key auto increment. Here's an example $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); $sql = "DROP TABLE IF EXISTS `person`"; $db->query($sql); $sql = "CREATE TABLE `person` ( `batch` int(11) NOT NULL, `id` int(3) ZEROFILL NOT NULL AUTO_INCREMENT, `name` varchar(45) DEFAULT NULL, PRIMARY KEY (`batch`,`id`) ) ENGINE=MyISAM"; $db->query($sql) or die ($db->error); $sql = "INSERT INTO person (batch, name) VALUES (53, 'Cary'), (53, 'Josh'), (36, 'Brock'), (36, 'Barand') "; $db->query($sql); mysql> SELECT * FROM person; +-------+-----+--------+ | batch | id | name | +-------+-----+--------+ | 53 | 001 | Cary | | 53 | 002 | Josh | | 36 | 001 | Brock | | 36 | 002 | Barand | +-------+-----+--------+
  5. Check for a change in colA and only output when it changes pseudocode: currentCampaign = '' while fetch next row if campaign != currentCampaign print campaign currentCampaign = campaign endif print asset endwhile
  6. NULLIF() is not a PHP function, it's a SQL function You will notice I used it as a function inside the MySQL query
  7. Your column name "Update" is a MySQL reserved word. Change the name or put it in backticks ie `update` http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
  8. I'd take a different approach from Ch0cu3r, normalizing the ratings so there was a separate table with a rating on each row. This makes it easier to add new new attributes to be rated The tables +----------------------+ +----------------------+ | person | | attribute | +-----+----------------+ +-----+----------------+ | id | name | | id | description | +-----+----------------+ +-----+----------------+ | 1 | John Doe | | 1 | Hair | | 2 | Jane Brown | | 2 | Clothing | +-----+----------------+ | 3 | Education | | | 4 | etc | | +-----+----------------+ +--------------------------+ | | +--------------------+ | | +----------------------+ | rating | +------+------+--------+ |persId|attrId| rating | +------+------+--------+ | 1 | 1 | 2 | | 1 | 2 | 4 | | 1 | 3 | 4 | | 1 | 4 | 3 | | 2 | 1 | 5 | | 2 | 2 | 4 | | 2 | 3 | 4 | | 2 | 4 | 5 | +------+------+--------+ $sql = "CREATE TABLE person ( persId INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50) )"; $db->query($sql); $sql = "INSERT INTO person (name) VALUES ('John Doe'), ('Jane Brown'), ('Harry Potter')"; $db->query($sql); $sql = "CREATE TABLE attribute ( attrId INT NOT NULL AUTO_INCREMENT PRIMARY KEY, description VARCHAR(50) )"; $db->query($sql); $sql = "INSERT INTO attribute (description) VALUES ('Hair'), ('Clothes'), ('Education'), ('Other'), ('Etc')"; $db->query($sql); $sql = "CREATE TABLE rating ( ratingId INT NOT NULL AUTO_INCREMENT PRIMARY KEY, persId INT, attrId INT, rating TINYINT )"; $db->query($sql); For the rating dropdowns I'd give them names like "rating[attributeId]" so it's simple to loop through the post data to add the ratings for each attribute // // define the options for the rating dropdowns // $ratings = "<option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option>"; // // use attribute table to build the rating selections // and alsoto store the headings for the report // $sql = "SELECT attrId, description FROM attribute ORDER BY attrId"; $res = $db->query($sql); $ratingSelections = ''; $attrs = array(); while (list($id, $des) = $res->fetch_row()) { $ratingSelections .= "<div class='descrip'>$des</div> <div class='rating'><select name='rating[$id]'>$ratings</select></div> <div style='clear:both'></div>"; $attrs[$id] = $des; // store heads for table } and to process them if (isset($_POST['persid'])) { // id of person being rated $persid = intval($_POST['persid']); // insert a row for each attribute into rating table $data = array(); foreach ($_POST['rating'] as $attrid => $rating) { $data[] = sprintf("(%d, %d, %d)", $persid, intval($attrid), intval($rating)); } $sql = "INSERT INTO rating (persId, attrId, rating) VALUES " . join(',', $data); $db->query($sql); } which give an insert query like INSERT INTO rating (persId, attrId, rating) VALUES (1, 1, 4),(1, 2, 2),(1, 3, 2),(1, 4, 4),(1, 5, 5) Complete example attached example.php
  9. When you display the form the $_POST data does not yet exist so the code is not executed. When you submit the form the post data is sent to images.php (because that is the specified form action). So the code still isn't executed because it isn't in that file.
  10. Start at the top left and look for an occurrence of many contiguous horizontal white pixels. Then work back from bottom right looking for same.
  11. do you mean SELECT users_username , users_battle_w , users_battle_l , users_battle_w + users_battle_l as fights , users_battle_w * 100 / (users_battle_w + users_battle_l) as winpcent FROM stats ORDER BY fights DESC, winpcent DESC
  12. SELECT users_username , users_battle_w , users_battle_l , users_battle_w * 100 / (users_battle_w + users_battle_l) as winpcent FROM stats ORDER BY winpcent DESC
  13. If the query fails, check out why! if (!mysql_query($sql)) die (mysql_error() . "<pre>$sql</pre>");
  14. $result->num_rows will always be 1 with that query! try $result = mysqli_query($con,"SELECT COUNT(*) FROM Draws"); list($num_rows) = $result->fetch_row(); echo "There are $num_rows results from your query.";
  15. You could try NULLIF() $db->query("DROP TABLE IF EXISTS bravo14"); $db->query("CREATE TABLE bravo14 ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY , name VARCHAR(20), points INT)"); $a = ''; $b = 0; $c = 1; $sql = "INSERT INTO bravo14 (name, points) VALUES ('aaaaaa', NULLIF('$a', '')), ('bbbbbb', NULLIF('$b', '')), ('cccccc', NULLIF('$c', '')) "; $db->query($sql) mysql> SELECT * FROM bravo14; +----+--------+--------+ | id | name | points | +----+--------+--------+ | 1 | aaaaaa | NULL | | 2 | bbbbbb | 0 | | 3 | cccccc | 1 | +----+--------+--------+
  16. Have you tried echoing the output from mysql_error() to find the reason? And do you really have a column named "FEATUES"?
  17. Dates should be stored in Y-m-d format in databases, column type DATE. $dbdate = date ('Y-m-d', mktime(0,0,0,$month,$day,$year)); Use the MySQL function CONCAT() for the names, or concatenate using PHP prior to the insert $name = "$firstname $lastname"; Or consider storing lastname and firstname in separate columns.
  18. If you are working with week numbers it makes sense to have the correct year to which the week number belongs. Consider Date ISO Wk d M Y o-W 25 Dec 2010 2010-51 26 Dec 2010 2010-51 27 Dec 2010 2010-52 28 Dec 2010 2010-52 29 Dec 2010 2010-52 30 Dec 2010 2010-52 31 Dec 2010 2010-52 01 Jan 2011 2010-52 02 Jan 2011 2010-52 03 Jan 2011 2011-01 04 Jan 2011 2011-01 05 Jan 2011 2011-01 06 Jan 2011 2011-01 For the date 01-Jan-2011 it would be wrong to have 2011-52 as the week
  19. Also bear in mind that the user may submit the form data by pressing the Enter key. In this case it depends on which browser is being used whether the value of the Submit button is posted or not.
  20. /********************************** * Output the array ***********************************/ foreach ($acopy as $sportname => $sportarray) { echo "$sportname<br><br>"; foreach ($sportarray as $tournament => $tournarray) { foreach ($tournarray as $match => $matcharray) { $dt = date('jS F Y, H:i', strtotime($matcharray['time'])); // added echo "$tournament - $match - $dt<br>"; // changed foreach ($matcharray['links'] as $linkarray) { echo join(' : ', $linkarray) . '<br>'; } echo '<br>'; } } }
  21. The code I posted almost worked for the extract you provided (with the addition of </browse> at the end. I have since added {...} to fix the bug when printing the <key> values $xml = simplexml_load_string($str); #echo '<pre>',print_r($xml, true),'</pre>'; foreach ($xml->tr as $tr) { echo "<h4>td</h4>"; foreach ($tr->td as $td) { echo "{$td['field']} : $td<br>"; } echo "<h4>key</h4>"; echo "office: {$tr->key->office}<br>"; echo "code: {$tr->key->code}<br>"; echo "number: {$tr->key->number}<br>"; echo "line: {$tr->key->line}<br>"; } /*** RESULTS *********************************************** td fin.trs.line.dim2 : 2001 fin.trs.line.openbasevaluesigned : -629.93 fin.trs.line.basevaluesigned : -629.93 fin.trs.line.invnumber : fin.trs.head.code : BEGINBALANS fin.trs.line.matchdate : fin.trs.line.datedue : 20111031 fin.trs.head.date : 20111001 fin.trs.head.status : final fin.trs.line.availableforpayruns : true key office: NLA003802 code: BEGINBALANS number: 201100001 line: 16 td fin.trs.line.dim2 : 2000 fin.trs.line.openbasevaluesigned : -3570.00 fin.trs.line.basevaluesigned : -3570.00 fin.trs.line.invnumber : fin.trs.head.code : BEGINBALANS fin.trs.line.matchdate : fin.trs.line.datedue : 20111031 fin.trs.head.date : 20111001 fin.trs.head.status : final fin.trs.line.availableforpayruns : true key office: NLA003802 code: BEGINBALANS number: 201100001 line: 17 ****************************************************************/ It depends on how much pruning you did before posting. If the <browse> tag is embedded inside other tags you need to adjust to take the parent(s) into account, but I cannot to more without the full xml structure.
  22. I'm pretty sure I posted a solution to a similar question posted by Jessica some time ago. I'll see if search turns it up. edit: success http://forums.phpfreaks.com/topic/266415-permutations-of-setscombinations/?do=findComment&comment=1365289
  23. try $xml = simplexml_load_string($str); #echo '<pre>',print_r($xml, true),'</pre>'; foreach ($xml->tr as $tr) { echo "<h4>td</h4>"; foreach ($tr->td as $td) { echo "{$td['field']} : $td<br>"; } echo "<h4>key</h4>"; echo "office: $tr->key->office<br>"; echo "code: $tr->key->code<br>"; echo "number: $tr->key->number<br>"; echo "line: $tr->key->line<br>"; }
  24. I get the impression you are storing attributes like this "size=large,colour=red,fabric=cotton" Don't. Normalize your data and store one attribute per row eg +-------+--------------+----------+ | item | attribute | value | +-------+--------------+----------+ | 1 | size | large | | 1 | colour | red | | 1 | fabric | cotton | +-------+--------------+----------+ Ensure the columns used in the joins are indexed plus those in the WHERE clause
  25. SELECT n.id, n.process, n.action FROM n1concepts n LEFT JOIN ( SELECT process FROM n1concepts WHERE `action` <> 'idle' ) as notidle USING (process) WHERE n.action = 'idle' AND notidle.process IS NULL
×
×
  • 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.