Jump to content

Makke_

Members
  • Posts

    18
  • Joined

  • Last visited

Makke_'s Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. That solved it, thanks! I used this '{$date->format('Y-m-d')}' with the quotes in the query.
  2. If I hardwrite the date like this '2013-05-29' in the query that works. If I echo the $date->format('Y-m-d') I get the date in correct format.
  3. I have a SQL query where I am retrieving information to a table. I would like to only retrieve data from yesterday. I found some PHP code which I´ve formated to look exactly as the Date does in the database (2013-05-30) YYYY-mm-dd but I can´t get it to work. Does someone see what the error might be? <?php $date = new DateTime(); $date->add(DateInterval::createFromDateString('yesterday')); $conn = mysql_connect($dbhost, $dbuser, $dbpassword); if(! $conn ) { die('Could not connect: ' . mysql_error()); } mysql_select_db($dbname, $conn); echo '<STYLE TYPE="text/css">'; echo 'TD{font-family: Arial; font-size: 9pt;}'; echo '</STYLE>'; echo '<table border=1><thead><tr><th>Namn</th><th>Datum</th><th>SE Mail</th><th>SE Backoffice</th><th>DK Mail</th><th>DK Backoffice</th><th>NO Mail</th><th>NO Backoffice</th><th>FI Mail</th><th>FI Backoffice</th></tr></thead><tbody>'; $q = mysql_query("SELECT id, name, Date, SEMail, SEBackoffice, DKMail, DKBackoffice, NOMail, NOBackoffice, FIMail, FIBackoffice FROM maildata WHERE Date = $date->format('Y-m-d')"); while($f = mysql_fetch_array($q)) { echo '<tr><td>'.$f['name'].'</td><td>'.$f['Date'].'</td><td>'.$f['SEMail'].'</td><td>'.$f['SEBackoffice'].'</td><td>'.$f['DKMail'].'</td><td>'.$f['DKBackoffice'].'</td><td>'.$f['NOMail'].'</td><td>'.$f['NOBackoffice'].'</td><td>'.$f['FIMail'].'</td><td>'.$f['FIBackoffice'].'</td></tr>'; } echo '</tbody></table>'; mysql_close($conn); ?>
  4. I know noticed I did some mistake. I use following to trim the string. trim($f['rc_comment'], "/* ") I would like to also remove the words Created page with from the same string.
  5. I use following code to retrieve data from a database and trim it in different ways to make it look better. and remove unwanted characters and also to be able to use some characters. Allthough in rc_comment string I would also like to remove if possible a specific sentence Created page with or in worst case the three words. I have tried to add $newString = str_replace("Created", " ", $newString); to remove the word Created but this doesnt work. Any idea how to solve this? echo '<table border=0><thead><tr><th></th></tr></thead><tbody>'; $q = mysql_query("SELECT rc_id, rc_title, rc_comment, rc_minor FROM recentchanges WHERE rc_minor = '0' ORDER BY rc_id desc limit 20"); while($f = mysql_fetch_array($q)) { $string = $f['rc_comment']; $newString = $string; $newString = str_replace("/* ", "", $newString); $newString = str_replace(" ", "_", $newString); $newString = str_replace("(", ".28", $newString); $newString = str_replace(")", ".29", $newString); $newString = str_replace(",", ".2C", $newString); $newString = str_replace("&", ".26", $newString); $newString = str_replace("å", ".C3.A5", $newString); $newString = str_replace("ä", ".C3.A4", $newString); $newString = str_replace("ö", ".C3.B6", $newString); echo '<tr><td><span style="color:grey">■&nbsp&nbsp&nbsp&nbsp</span><a href="index.php/'.$f['rc_title'].'#'.substr_replace($newString ,"",-4).'" target="_parent">'.$f['rc_title'].' - '.trim($f['rc_comment'], "/* ").'</a></td></tr>'; } echo '</tbody></table>';
  6. Seems like following part of the code isn´t working. 'user_name = ".$wgUser."', If a write a specific user like 'user_name = "admin". It will fetch the information for Admin user. How should above code be written? i now $wgUser conatines value. I managed to print that information before. $wgOut->addHTML(''.$wgUser.'.'); I can then write it by using below code : <?php /** * Prevent a user from accessing this file directly and provide a helpful * message explaining how to install this extension. */ if ( !defined( 'MEDIAWIKI' ) ) { echo <<<EOT To install the Test extension, put the following line in your LocalSettings.php file: require_once( "\$IP/extensions/Test.php" ); EOT; exit( 1 ); } // Extension credits that will show up on Special:Version $wgExtensionCredits[ 'other' ][] = array( 'path' => __FILE__, 'name' => 'Test', 'author' =>'Your Name Here', 'url' => 'https://www.mediawiki.org/wiki/Extension:Test', 'description' => 'This extension is an Test extension', 'version' => 1.0, ); // Find the full directory path of this extension $current_dir = dirname( __FILE__ ) . DIRECTORY_SEPARATOR; // Tell MediaWiki about the special page $wgSpecialPages[ 'Test' ] = 'SpecialTest'; global $wgRequest; class SpecialTest extends SpecialPage { function __construct() { parent::__construct( 'Test' ); } /** * Make your magic happen! */ function execute( $par ) { global $wgOut, $wgUser; $wgUser->getName(); $dbr = wfGetDB( DB_SLAVE ); $res = $dbr->select( 'user', // $table array( 'user_name', 'approved_account' ), // $vars (columns of the table) 'user_name = ".$wgUser."', // $conds __METHOD__, // $fname = 'Database::select', array( 'ORDER BY' => 'user_name ASC' ) // $options = array() ); $output = ''; foreach( $res as $row ) { $output .= 'Catgeory ' . $row->user_name . ' contains ' . $row->approved_account . " entries.\n"; } $wgOut->addHTML(''.$output.'.'); } }
  7. I did like this and then i seems to work! Thanks for your help! SELECT DISTINCT WEEK(Date, 1) AS WeekNo FROM maildata ORDER BY 1 ASC
  8. Thanks for a quick reply. It did work but it starts to count from 0.
  9. Hi, I am trying to display week number in a drop down menu. I managed to display the numbers but not distinct. I´ve tried using array_unique but i´m not sure how to implement it. (below code shows how I tried to use array_unique. $sql="SELECT Date FROM maildata ORDER BY Date ASC"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($result)){ $date_string = date($row['Date']); $week = array_unique($date_string); $options .="<option>". date("W", strtotime($week))."</option>"; ?> <SELECT name="week"> <OPTION VALUE="">Choose week <?=$options?> </SELECT>
  10. How should I write to be able to write user_name & approved_account? I´m not sure how to fomulate that sentence/code string?
  11. I´m currently working on below code. Would appreciate feedback and help. I don´t know if it fetches the values from the database. I am not able to print it. <?php /** * Prevent a user from accessing this file directly and provide a helpful * message explaining how to install this extension. */ if ( !defined( 'MEDIAWIKI' ) ) { echo <<<EOT To install the Test extension, put the following line in your LocalSettings.php file: require_once( "\$IP/extensions/Test.php" ); EOT; exit( 1 ); } // Extension credits that will show up on Special:Version $wgExtensionCredits[ 'other' ][] = array( 'path' => __FILE__, 'name' => 'Test', 'author' =>'Your Name Here', 'url' => 'https://www.mediawiki.org/wiki/Extension:Test', 'description' => 'This extension is an Test extension', 'version' => 1.0, ); // Find the full directory path of this extension $current_dir = dirname( __FILE__ ) . DIRECTORY_SEPARATOR; // Tell MediaWiki about the special page $wgSpecialPages[ 'Test' ] = 'SpecialTest'; global $wgRequest; class SpecialTest extends SpecialPage { function __construct() { parent::__construct( 'Test' ); } /** * Make your magic happen! */ function execute( $par ) { global $wgOut, $wgUser; $wgUser->getName(); $dbr = wfGetDB( DB_SLAVE ); $res = $dbr->select( 'user', // $table array( 'user_name', 'approved_account' ), // $vars (columns of the table) 'user_name = ".$wgUser."', // $conds __METHOD__, // $fname = 'Database::select', array( 'ORDER BY' => 'user_name ASC' ) // $options = array() ); $output = ''; foreach( $res as $row ) { $output .= 'Catgeory ' . $row->user_name . ' contains ' . $row->approved_account . " entries.\n"; } $wgOut->addHTML('Hej '.$wgUser.'.'); } }
  12. I have tried to read about extensions and hooks. I´ve created below (as an extension I think). Allthough it´s not working, giving me a blank page when implementing it to my MediaWiki. Anyone famillier with MediaWiki Extension coding? <?php $wgExtensionCredits['validextensionclass'][] = array( 'path' => __FILE__, 'name' => 'Approve Account', 'author' =>'Markus', 'url' => 'https://www.mediawiki.org/wiki/Extension:Approve_Account', 'description' => 'This extension require admin to allow recently registered users to login', 'version' => 0.1, ); $wgHooks['AddNewAccount'][] = 'approve_accountHooks::onAddNewAccount'; $user = User::loadFromSession(); $dbr = wfGetDB( DB_SLAVE ); $res = $dbr->select(user_name, approved_account FROM user WHERE user_name = $user); if( approved_account == '0' { } }
  13. It is MediaWiki´s original. I suspect is is withing this file: https://doc.wikimedia.org/mediawiki-core/master/php/html/User_8php_source.html Alltough I´ve heared they don´t recommend changing in MediaWiki's files but creating extensions instead (even though I don´t know how to do it).
×
×
  • 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.