-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Which line is it ? (In MySQL error message number 1064)
Barand replied to roparzhhemon237's topic in PHP Coding Help
Syntax error...at line 1 refers to line 1 of your SQL query code. If you are one of those people who always stretch out there SQL code on a single line then the error will always be on line 1. OTOH, if you structure you queries to make them more readable eg SELECT col1 , col2 , CONCAT(col3, col4) AS something FROM tablea JOIN tableb USING (somekey) ORDERBY col1 then it would report the syntax error in line 7 in the example able The 35 refers to the line in the php file where the error occurred. -
There are two ways of doing this. 1. Given that you have the domain table and the word tables then you you would have a "normalized" table (keyword) to link the two. You would then search the keyword table for those domain_ids that had links to both "rugby" and "league" (ie word_ids 3 and 5 in the example below) Domain Word +----+---------------------+ +----+-----------------+ | id | Domain | | id | Word | +----+---------------------+ +----+-----------------+ | 1 | londonharriers.org | | 1 | Sport | | 2 | leedsrhinos.com | | 2 | Athletics | | 3 | manchesterrufc.org | | 3 | Rugby | | 4 | wiganwarriors.net | | 4 | Union | +----+---------------------+ | 5 | League | | +----+-----------------+ | | +-------------------------+ | Keyword | | +----+-----------+---------+ | id | domain_id | word_id | +----+-----------+---------+ | 1 | 1 | 1 | | 2 | 1 | 2 | | 3 | 2 | 1 | | 4 | 2 | 3 | | 5 | 2 | 5 | | 5 | 3 | 1 | | 5 | 3 | 3 | | 5 | 3 | 4 | | 6 | 4 | 1 | | 7 | 4 | 3 | | 8 | 4 | 5 | +----+-----------+---------+ 2. The other way is to use FULLTEXT searches on text field/s Domain +----+---------------------+--------------------------------------------------+ | id | Domain | Description | +----+---------------------+--------------------------------------------------+ | 1 | londonharriers.org | Athletics club in London promoting sport for all | | 2 | leedsrhinos.com | Yorkshire based rugby league club | | 3 | manchesterrufc.org | Rugby union sports club in South Manchester | | 4 | wiganwarriors.net | Lancashire based rugby league sports club | +----+---------------------+--------------------------------------------------+ By setting up a fulltext index you could then search the text for, say Rugby but not Union Rugby Rugby and must contain league also etc
-
There seems to a basic flaw in that subquery you use everywhere. It assumes that the usage is the max reading - min reading. In another post of yours you have problem where the readings trip over back to zero, so if you have readings like this for a quarter 2013-12-31 99999800 2014-02-28 00000010 2014-03-31 00000250 then if you use the max and min only you get usage of 210 when it should be 450
-
$ag_forums_to_kunena_categories = array(); $cat_id = $ag_forums_to_kunena_categories[$row->messages_catid]; $ag_forums_to_kunena_categories is an empty array. I don't see you put anything into it in that code.
-
Does $_FILES['picture']['error'] give any clues?
-
However, if you do need to loop and process all the values in the array then you can check this way <?php $id1 = '5' ; $id = array(1,2,3,4,5,6,7); $found = 0; // set a flag variable to FALSE foreach($id as $value){ if($id1==$value){ echo 'One of them matches, ' ; echo 'Do not execute command <BR>' ; $found = 1; // set the flag to TRUE if found } } if (!$found) { // use flag to see if it was found // do 'not found' action } ?>
-
Had you considered reading the manual? http://uk1.php.net/manual/en/function.mysql-fetch-row.php
-
That var_dump of $_REQUEST should tell you all you need to access the value that you want from the posted data. And as for $Events = new GalaxyEvents(); That should create an object of class GalaxyEvents.
-
Another thing that you might want to consider (and which would probably be appreciated by team member) is to keep the task time random but make the following break proportional to the task time so they they get a longer break after a long task. $eTime = mt_rand(7, 38); // mins $bTime = calcBreak(30,300,7,38,$eTime); function calcBreak($min,$max,$minet,$maxet,$et) { return floor(($max-$min) * ($et-$minet) / ($maxet-$minet)) + $min; }
-
I would generate random times for the events and breaks and maintain a running total of the time until 24 hours were filled $events = array(); $cumval = 0; $finished = 0; $k = 0; // // GENERATE RANDOM EVENT AND BREAK TIMES // UNTIL THE 24HRS HAVE BEEN FILLED // while (!$finished) { $remain = 24*60*60 - $cumval; if ($remain < 7*60 + 30) break; // cannot fit another event/break if ($remain < 39*60) { $eTime = floor($remain/60) - 1; $bTime = $remain - $eTime*60; $finished = 1; } else { $eTime = mt_rand(7, 38); // mins $bTime = mt_rand(3, 30) * 10; // 10 sec increments } $events[++$k] = array ( 'event' => $eTime, //mins 'break' => $bTime //secs ); $cumval += $eTime*60 + $bTime; } // // GET THE SCHEDULE FOR EACH OF THE 3 TEAMS // $schedule = array(); $keys = array_keys($events); $k = count($keys); for ($team = 1; $team <= 3; $team++) { shuffle($keys); $schedule[$team] = $keys; } Once you have the event and break durations in the $events array you can generate a timetable for each time using their schedule of events
-
OK, so if the max id for a player is, say, 12345, and his weight in that record is 180lbs, that only tells you his weight changed by 180lb since he was an egg.
-
That's a lot clearer. From the times produced by your code you will have around 57 events $e = eventRange(7,38,32); $b = breakRange(.5,5,32); $ae = array_sum ($e) / count($e); $ab = array_sum($b) / count($b); $k = floor((24*60)/($ae+$ab)); echo"<pre>"; print_r($e); print_r($b ); printf ("Ave event: %5.2f\nAve break: %5.2f\nNum events in 24hrs: %d", $ae, $ab, $k); echo"</pre>"; Giving: Ave event: 22.50 Ave break: 2.76 Num events in 24hrs: 57
-
How to print a string that also contains an array?
Barand replied to E_Leeder's topic in PHP Coding Help
IMHO print_r() is a debugging function and not suitable for output to a web page for user consumption. You might find it useful to have a couple of functions in your arsenal, such as function bulletList($arr) { return "<ul><li>" . join('</li><li>', $arr) . "</li></ul>\n"; } function commaList($arr) { $last = array_pop($arr); return join(', ', $arr) . " and $last"; } Then can $books = array ( 'Treasure Island', 'Harry Potter and the Philosopher\'s Stone', 'A Tale of Two Cities' ); $pages = array(23,45,135,247,248); $sentence = "These are the books " . bulletList($books) . "and these are the pages " . commaList($pages); and echoing $sentence gives -
When you talk about change in height or weight then a time period usually involved - ie the difference between weight now compared with the known weight at a previous point in time. I see no mention of dates in your queries
-
Try $data = array ( 'firstname' => 'JOHN', 'lastname' => 'SMIth', 'address' => '2 EFFIN ClOse' ); foreach ($data as $key => &$value) { $value = ucwords(strtolower($value)); } View results echo '<pre>',print_r($data, true),'</pre>'; Array ( [firstname] => John [lastname] => Smith [address] => 2 Effin Close )
-
... and %6 will yield results between 0 and 5 only. You need %12
-
As a prerequisite to learning PHP you need to learn to read. I said you have defined the host etc but you have not connected to the server. http://uk3.php.net/manual/en/function.mysqli-connect.php
-
You have defined the host, user etc but you still need to connect to the database before you can execute any queries. And you should not be creating new code using the mysql_xxxx functions, use mysqli_xxxx or PDO functions. @KillerOz, the {} are advisable but not essential for a single statement
-
so $start_reading = 99999945; $end_reading = 10; $usage = $end_reading - $start_reading; if ($usage < 0) { $usage += 100000000; } echo $usage;
-
Looping value increase resulting in odd and even numbers
Barand replied to engy123's topic in PHP Coding Help
or just do $intermediate[$key][] = $y; Then for each key you have an array where the index (+1) is the x value and the value is y -
- 9 replies
-
- search code
- string
-
(and 1 more)
Tagged with:
-
Try if(isset($_GET["id"])){ $query = sprintf("SELECT * FROM `DATABASE`.`TABLE` WHERE idquack='%s'", mysql_real_escape_string($part));