-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Afraid not. The manual beat you to it. http://www.php.net/manual/en/language.variables.variable.php
-
I managed to get the correct result on the original PNG image by adjusting the image brightness (line 5 in code attached) textarea.php
-
Instead of name = '$result2[id]' have name = 'answers[$result2[id]]'
-
When I've done this I generated all the individual events, say every Monday at 09:00 and gave them a group code. Individual events had no group +---------+---------------------+---------------------+------------------+-------+ | eventid | DateTimeFrom | DateTimeTo | Description | Group | +---------+---------------------+---------------------+------------------+-------+ | 1 | 2014-01-06 09:00:00 | 2014-01-06 10:00:00 | Team meeting | 1 | | 2 | 2014-01-13 09:00:00 | 2014-01-13 10:00:00 | Team meeting | 1 | | 3 | 2014-01-20 09:00:00 | 2014-01-20 10:00:00 | Team meeting | 1 | | 4 | 2014-01-28 16:00:00 | 2014-01-28 17:00:00 | Dentist | NULL | +---------+---------------------+---------------------+------------------+-------+ This allows change or cancellation of individual events in the group plus changes to the group as a whole
-
Single query to read all the answers into an array $res = $db->query("SELECT id,ans FROM questions"); while ($row = $res->fetch_assoc()) { $ans[$row['id']] = $row['ans']; } Gives something like $ans = array ( 1 => 'A', 2 => 'C', 3 => 'D' ); Then you have your POST array like $post = array ( 1 => 'A', 2 => 'B', 3 => 'D' ); Now use array_intersect_assoc() $correct = array_intersect_assoc($ans,$post); /* $correct array ********** Array ( [1] => A [3] => D ) ****************************/
-
GetFreaky See code in #8 above
-
Delete the 2 lines that echo the left-top and right-bottom coordinates then add this code /************************************************ * Create image of the text area * *************************************************/ $im2 = imagecreate($right-$left, $bottom-$top); imagecopy($im2, $im, 0, 0, $left, $top, $right-$left, $bottom-$top); // output image header("Content-type: image/gif"); imagegif($im2); imagedestroy($im); imagedestroy($im2);
-
I am not sure what you mean
-
if you have 1000 records in that table then you run that update 1000 times. All you need is $query2 = "UPDATE merchant SET price= price+$increment WHERE `name`='Harvey Norman' and price = 141.00 "; $result2 = mysql_query($query2);
-
Changing the table cell color depending on input value
Barand replied to sandaru1sx's topic in PHP Coding Help
Set up a CSS style for each cell colour then set the class to be used in the switch statement <?php $cells = ''; for ($i=0; $i<8; $i++) { switch ($val = $i%4) { case 0: $cls = 'c0'; break; case 1: $cls = 'c1'; break; case 2: $cls = 'c2'; break; case 3: $cls = 'c3'; break; } $cells .= "<tr><td class='$cls'>$val</td></tr>\n"; } ?> <html> <head> <title>Cell colours</title> <style type="text/css"> table { border-collapse: collapse; } td { text-align: center; width: 150px; } td.c0 { background-color: red; color: white; } td.c1 { background-color: orange; color: white; } td.c2 { background-color: yellow; color: black; } td.c3 { background-color: green; color: white; } </style> </head> <body> <table border="1" > <?php echo $cells ?> </table> </body> </html> -
try running this code and check "http" is in the list $w = stream_get_wrappers(); echo '<pre>',print_r($w, true),'</pre>';
-
When I ran it it gave http://cdn.putlocker.com/r1KH3Z%2FaMY6kLQ9Y4nVxYpvXrk1%2FQyNvy7xPy8vQTltYliWCdpShxmSPnVzNmP5VlwgLPSYQ%2FddAb5kJ5ZFi3mY0R4gfIY2P69RYRz64ox67Z4LwcyYyZpbQM2FaWb6Or7RgBzqiU1bacFc%2BUyjR95aQgfTpPENEM1NkokFtDaP6oxoBy5mLYlHYbEvIYKwka9qymnoJuwbjKg83fnPX2z7hS6NXWxpudU1NBTWGfSM%3D/aec5ea42616804a307c016b03f6a3e45.flv/aec5ea42616804a307c016b03f6a3e45.flv video/x-flv 5049
-
try using $result2 in conjunction with $sql2 instead of $result
-
try $xml=simplexml_load_file("http://www.putlocker.com/get_file.php?stream=WyJSVEU0TnpGRE9ERXlOemt6UTBRek5Eb3hNemc1TlRJMU16VTRMalk1TnpNNk5EVTBZVFpoWTJaak0yWmxOVEJtTVRjNU5UZGhORGxqTWpKbFl6Z3hZbUZtT0dSaU1qVmpPQT09IiwicmVnIl0"); $xml->registerXPathNamespace("media", current($xml->getNamespaces())); foreach ($xml->xpath('//media:content') as $c) { echo $c['url'] . '<br>'; echo $c['type'] . '<br>'; echo $c['duration'] . '<br>'; }
-
Rounded the results in the query to 2 places <?php $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); // // use attribute table to build the // headings for the report // $sql = "SELECT attrId, description FROM attribute ORDER BY attrId"; $res = $db->query($sql); $attrs = array(); while (list($id, $des) = $res->fetch_row()) { $attrs[$id] = $des; } // // the ratings report // $sql = "SELECT p.persId , p.name , r.attrId , ROUND(AVG(r.rating), 2) as rating , ROUND(av.avrate, 2) as avrate FROM rating r INNER JOIN person p USING (persId) INNER JOIN ( SELECT persid, AVG(rating) as avrate FROM rating GROUP BY persid ) as av USING (persid) GROUP BY r.persid, r.attrid ORDER BY p.name"; $res = $db->query($sql); if ($res->num_rows == 0) { $report = "<h3>No ratings to report</h3>\n"; } else { $report = "<h3>Ratings Report</h3>\n <table id='report' border='1'>\n <tr><th>Name</th><th>" . join('</th><th>', $attrs) . "</th><th>Average</th></tr>\n"; $currpers = 0; $currname = ''; $currav = 0; $newData = array_fill_keys(array_keys($attrs),0); while (list($pid,$name,$aid,$rating,$av) = $res->fetch_row()) { // check if record is for new person if ($pid != $currpers) { if ($currpers) { // only output when we have data $report .= "<tr><td>$currname</td><td>" . join('</td><td>', $rateData) . "</td><td>$currav</td></tr>\n"; } $currname = $name; $currpers = $pid; $currav = $av; // set data to new empty array for next person $rateData = $newData; } // store the attribute rating in the array $rateData[$aid] = $rating; } // output row for the last person $report .= "<tr><td>$currname</td><td>" . join('</td><td>', $rateData) . "</td><td>$currav</td></tr>\n"; $report .= "</table>\n"; } ?> <html> <head> <title>Example ratings</title> <style type='text/css'> table#report { border-collapse: collapse; } td { text-align: center; width: 80px; } </style> </head> <body> <?php echo $report . '<br><hr>'; ?> <a href="exampleForm.php">Back to input form</a> </body> </html>
-
try this version of exampleReport.php <?php $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); // // use attribute table to build the // headings for the report // $sql = "SELECT attrId, description FROM attribute ORDER BY attrId"; $res = $db->query($sql); $attrs = array(); while (list($id, $des) = $res->fetch_row()) { $attrs[$id] = $des; } // // the ratings report // $sql = "SELECT p.persId, p.name, r.attrId, AVG(r.rating) as rating, av.avrate FROM rating r INNER JOIN person p USING (persId) INNER JOIN ( SELECT persid, AVG(rating) as avrate FROM rating GROUP BY persid ) as av USING (persid) GROUP BY r.persid, r.attrid ORDER BY p.name"; $res = $db->query($sql); if ($res->num_rows == 0) { $report = "<h3>No ratings to report</h3>\n"; } else { $report = "<h3>Ratings Report</h3>\n <table id='report' border='1'>\n <tr><th>Name</th><th>" . join('</th><th>', $attrs) . "</th><th>Average</th></tr>\n"; $currpers = 0; $currname = ''; $currav = 0; $newData = array_fill_keys(array_keys($attrs),0); while (list($pid,$name,$aid,$rating,$av) = $res->fetch_row()) { // check if record is for new person if ($pid != $currpers) { if ($currpers) { // only output when we have data $report .= "<tr><td>$currname</td><td>" . join('</td><td>', $rateData) . "</td><td>$currav</td></tr>\n"; } $currname = $name; $currpers = $pid; $currav = $av; // set data to new empty array for next person $rateData = $newData; } // store the attribute rating in the array $rateData[$aid] = $rating; } // output row for the last person $report .= "<tr><td>$currname</td><td>" . join('</td><td>', $rateData) . "</td><td>$currav</td></tr>\n"; $report .= "</table>\n"; } ?> <html> <head> <title>Example ratings</title> <style type='text/css'> table#report { border-collapse: collapse; } td { text-align: center; width: 80px; } </style> </head> <body> <?php echo $report . '<br><hr>'; ?> <a href="exampleForm.php">Back to input form</a> </body> </html>
-
Do the people giving the grades have to Log in, so their userid is available to the script?
-
This worked for me mysql> SELECT m.message, m.user_type -> , CASE m.user_type -> WHEN 0 THEN u.username -> WHEN 1 THEN a.admin_username -> END as Username -> FROM messages m -> LEFT JOIN users u ON m.user_id = u.user_id -> LEFT JOIN administrators a ON m.user_id = a.admin_id; +-----------------+-----------+----------+ | message | user_type | Username | +-----------------+-----------+----------+ | message user 1 | 0 | User 1 | | message admin 1 | 1 | Admin 1 | | message user 2 | 0 | User 2 | | message admin 2 | 1 | Admin 2 | | message user 3 | 0 | User 3 | | message admin 3 | 1 | Admin 3 | +-----------------+-----------+----------+ and so did yours
-
You need to echo the query and see what is being run. I suspect you could be searching for dates where LIKE '2014-1' Instead try ... WHERE YEAR(event_date) = $year AND MONTH(event_date) = $month
-
Have you tried this method http://forums.phpfreaks.com/topic/283707-joiningif-3-tables/?do=findComment&comment=1457559 Which raises the question - why do you insist on storing the same type of data in separate tables instead of a single table with a type column? Could save you from these problems.
-
Check if the $_GET value is set before checking for the $_COOKIE value otherwise the user can't change it once the cookie is set.
-
I've just spotted another post of yours that is already answered. You have just totally wasted my time with this second post of the same question. I'll remember your name and stay clear in future
-
Check for when the name changes and only output totals and name when it does. <html> <head> <style type="text/css"> th { text-align: left; } td { width: 100px; } .ar { text-align: right; } </style> </head> <body> <?php $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); $sql = "SELECT name, contact, code, type, price, quantity FROM selftaught ORDER BY name"; $res = $db->query($sql); $currname = ''; echo "<table border='0' cellpadding='4'> <tr><th>Name</th><th>Contact</th><th>Code</th><th>Type</th><th class='ar'>Price</th><th class='ar'>Quantity</th></tr>"; while (list($name,$con,$code,$type,$pr,$qty) = $res->fetch_row()) { // check if name has changed if ($currname != $name) { // is it not the first name if ($currname) { echo "<tr><td colspan='4' class='ar'>Total price</td><td class='ar'>" . number_format($totprice,2) . "</td><td></td></tr>"; } echo "<tr><td>$name</td><td>$con</td><td>$code</td><td>$type</td><td class='ar'>" . number_format($pr,2) . "</td><td class='ar'>$qty</td></tr>"; $currname = $name; $totprice = 0; } else { echo "<tr><td colspan='2'></td><td>$code</td><td>$type</td><td class='ar'>" . number_format($pr,2) . "</td><td class='ar'>$qty</td></tr>"; } $totprice += $pr; } echo "<tr><td colspan='4' class='ar'>Total price</td><td class='ar'>" . number_format($totprice,2) . "</td><td></td></tr>"; echo "</table>"; ?> </body> </html> And if that really is your table and not the result of a query then you should read up on "data normalization"
-
The usual way to do CONTAINS is WHERE Description LIKE '%dropdownselectvalue%'
-
Select the text then hit the DEL button on keyboard.