Jump to content

doddsey_65

Members
  • Posts

    902
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by doddsey_65

  1. what im trying to do is echo all of the results from the database query but add bold to results with a pid of 0. here is my code: $list = ''; $query = $link->query("SELECT * FROM ".TBL_PREFIX."forums ORDER BY f_lid ASC"); $result = $query->fetchAll(); foreach($result as $key => $val) { if($result[$key]['f_pid'] == 0) { $list .= '<b>'.$result[$key]['f_name'].'</b><br />'; } $list .= $result[$key]['f_name'].'<br />'; } echo $list; this works fine but the ones with a pid of 0 are displayed twice. once as bold and then once normal like so: General General New Features Testing Testing Sandbox Bugs my question is how to prevent this.
  2. in my attempts at PDO i seem to have gone wrong here. perhaps someone can help: $query = "SELECT * FROM ".TBL_PREFIX."users WHERE u_uid=$uid"; $stmt = $link->query($query); $result = $stmt->fetch(PDO::FETCH_ASSOC); foreach($result as $key => $val) { echo $key.' - '.$val.'<br />'; } this is the error: Fatal error: Call to a member function fetch() on a non-objec $link = new PDO("mysql:host={$settings['hostname']}; dbname={$settings['database']}", $config['database']['username'], $config['database']['password'] );
  3. cheers mate, youre a star. works perfectly
  4. that doesnt seem to work since the html file isnt included anywhere. ive tried again, thinking it was a loop i needed but now {BOARD_NAME} isnt even replaced: function replace($array, $file) { if(!is_array($array)) { die('template->replace: No Array Specified'); } $file = 'html/'.$file.'.html'; $replace = ''; foreach ($array as $key => $val) { while($element = each($array)) { $replace .= str_replace($element['key'], $element['val'], file_get_contents('./'.$this->template.$file)); } } echo $replace; }
  5. no since the only thing that gets looped is what is in the while loop. in this case your echo. your connection is outside of the while loop therefore doesnt get looped.
  6. ive gotten one step closer but its only replacing the first part of the array. function replace($array, $file) { $file = 'html/'.$file.'.html'; foreach ($array as $key => $val) { echo str_replace($key, $val, file_get_contents('./'.$this->template.$file)); } return; } $template->replace(array( '{BOARD_NAME}' => $settings['board_short_name'], '{PAGE_TITLE}' => $lang->index ), 'header'); {PAGE_TITLE} does not get replaced.
  7. hi, im trying to replace an arrays key with its value. this is so i can display the html on the pages. eg: index.html <title>{BOARD_TITLE}</title> index.php $template->replace(array( '{BOARD_TITLE}' => $settings['board_name'] )); template.php(template class) function replace($array) { foreach ($array as $key => $val) { echo $key = $val; } return; } however {BOARD_TITLE} does not get replaced with the value. where am i going wrong? Thanks
  8. varchar(10)
  9. im trying to generate a birthday list for people who have birthdays today. Unfortunatly it keeps coming up 0 when there are birthdays today. here is the query: $birthday_query = $link->query("SELECT u.u_username, u.u_birthday FROM ".TBL_PREFIX."users u WHERE u.u_banned = '0' AND u_confirmed = '1' AND u_birthday LIKE '" . $link->asf_escape(sprintf('%2d-%2d-', $now['mday'], $now['mon'])) . "%' ORDER BY u_username ASC"); the query string is: SELECT u.u_username, u.u_birthday FROM asf_users u WHERE u.u_banned = '0' AND u_confirmed = '1' AND u_birthday LIKE '25- 1-%' ORDER BY u_username ASC there is a birthday in the database which appears like: 25-1-1986 but it still says no birthdays. any ideas? and yes the user is confirmed and not banned.
  10. mark as *solved*
  11. no probs. please dont just copy the code. learn what i did. then you will be able to expand on it.
  12. solved - misplaced quote: case '0': $direction = 'ASC'";
  13. echoing the query string returns 1(or true since its a bool)
  14. <?PHP session_start(); //Database Information $dbhost = "localhost"; $dbname = "test"; $dbuser = "test"; $dbpass = "test"; //Connect to database $conn = mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname, $conn) or die(mysql_error()); //Clean data $_POST = array_map('strip_tags', $_POST); $_POST = array_map('mysql_real_escape_string', $_POST); $currentpassword = md5($_POST['currentpassword']); $newpassword = $_POST['newpassword']; $cnewpassword = $_POST['cnewpassword']; if($newpassword == $cnewpassword) { // get the current password $sql = mysql_query("SELECT password FROM users WHERE username='".$_SESSION['username']."'")or die(mysql_error()); $result = mysql_fetch_array($sql); // check if the entered currentpassword is the same as password in database if ($currentpassword != $result['password']) { echo 'Entered Password Does Not Match Current Password'; } else { $query = "UPDATE `users` SET `password` = '".md5($newpassword)."' WHERE `username` = '".$_SESSION['username']."' LIMIT 1"; $run = mysql_query($query); if($run) { echo "Congratulations You have successfully changed your password"; include 'success.php'; exit(); } else { include 'password.php'; exit; } } } else { echo "The new password and confirm new password fields must be the same"; include 'password.php'; exit(); } ?> took the liberty of adding an md5 hash there for you aswell. I would also advise against using array map on $_POST. reason is twofold: 1. strip_tags and escape_string are applied to the submit button and any hidden fields aswell. not really a problem but it's unneeded. 2. any multi dimensional $_POST arrays will be lost. not a problem now since you dont have any but something to be aware of.
  15. mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean i get that error with this code: $online_query = $link->simple_query('u_username', 'users', 'u_online=1 AND u_hidden != 1', '0u_username'); while($online_info = $link->fetch_array($online_query)) //THIS LINE THROWS THE ERROR the simple_query function is: function simple_query($fields, $table, $clause, $order) { global $link, $config; if(!empty($clause)) { $clause = "WHERE $clause"; } else { $clause = ''; } if(!empty($order)) { $direction = $order[0]; switch($direction) { case '0': $direction = 'ASC"'; break; case '1': $direction = 'DESC'; break; } $order = substr($order, 1, strlen($order)); $order = "ORDER BY $order $direction"; } $query = mysqli_query($this->link, "SELECT $fields FROM ".TBL_PREFIX."$table $clause $order"); return $query; } when i use a normal query instead of my simple_query function it works fine. it also worked fine before i made the database class. Where am i going wrong?
  16. can anyone help with this function. i keep getting undefined variable: link error. function simple_query($fields, $table, $clause, $order) { if (empty($config)) { require("./config/config.php"); } if(!empty($clause)) { $clause = "WHERE $clause"; } if(!class_exists('db_mysqli')) { include('./includes/db_mysqli.php'); $link = new db_mysqli; $link->connect($config['database']); } if(!empty($order)) { $direction = $order[0]; switch($direction) { case "0": $direction = "ASC"; break; case "1": $direction = "DESC"; break; } $order = substr($order, 1, strlen($order)); $order = "ORDER BY $order $direction"; } $query = $link->query("SELECT $fields //THIS LINE THROWS THE ERROR FROM ".TBL_PREFIX."$table $clause $order")or die(mysqli_error($link)); return $query; } database class: class db_mysqli { public $link; function connect($settings) { require_once(dirname(dirname(__FILE__)).'/config/config.php'); $link = new mysqli($settings['hostname'], $settings['username'], $settings['password'], $settings['database']); $this->link = $link; } } thanks.
  17. thanks for the replies. how would i go about not including anything from forums table where the pid != 0? i tried adding a where clause but it didnt show any categories. also is this the best way to do this? at the minute for tests im only pulling f_name but i will be wanting to pull alot more from the forum table later. heres my revised code: $forum_query = mysqli_query($link, "SELECT cid, c_name, group_concat(f_name separator '<br />') forums FROM ".TBL_PREFIX."categories LEFT JOIN ".TBL_PREFIX."forums USING (cid) GROUP BY ".TBL_PREFIX."categories.cid") or die(mysqli_error($link));
  18. error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'seperator ', ') forums FROM asf_categories LEFT JOIN asf_forums ' at line 2
  19. im trying to group all forums into their respective categories like so: category 1 forum 1 forum 2 category 2 forum 3 forum 4 but im having problems with the query: $forum_query = mysqli_query($link, "SELECT cid, c_name, group_concat(f_name seperator ', ') forums FROM ".TBL_PREFIX."categories LEFT JOIN ".TBL_PREFIX."forums using (cid) group by ".TBL_PREFIX."categories") or die(mysqli_error($link)); while($forum_info = mysqli_fetch_array($forum_query, MYSQLI_ASSOC)) { echo $forum_info['cat_name']."<br>"; echo $forum_info['forums']."<br>"; } i get an sql error before seperator. the database tables are as follows(btw TBL_PREFIX is "asf_") asf_categories cid c_name asf_forums fid cid f_name so to summarise im trying to group all foums with cid of 1 into cateogry with cid of 1 and so on. Any pointers?
  20. in the essence of trying to code my forum better i have started again(again). i havent just ditched the old files however. what i am doing is starting with one file and getting it right until i move to the next. then i will pull some old code(css and html mainly) from the old files. with that in mind i would like someone to have a look over what i have so far on the index.php page. it doesn't display anything, just sets up variables and such. I would like to know how it can be improved before i move on to more. <?php /* ASF A Simple Forum * Version 0.1.0 * Page Created 21/01/2011 */ // can page be accessed directly? define("ACCESS", 1); // start sessions session_start(); // get the functions file require_once("./functions/functions.php"); // get whos online list $online_list = array(); $online_query = simple_query("user_username", "members", "user_online=1 AND user_hidden != 1", "0user_username", "array"); while($online_info = mysqli_fetch_array($online_query, MYSQLI_ASSOC)) { // add online users into array for later callback $online_list[] .= profile_link("", $online_info['user_username'], ""); } $online_num = mysqli_num_rows($online_query); // find hidden users $hidden_query = simple_query("user_username", "members", "user_online=1 AND user_hidden = 1", "0user_username", "array"); $hidden_num = mysqli_num_rows($hidden_query); // if logged in as admin if(@$_SESSION['permissions'] == 1) { $hidden_list = array(); // show hidden list while($hidden_info = mysqli_fetch_array($hidden_query, MYSQLI_ASSOC)) { // add hidden users to array and append with * to denote hidden $hidden_list[] .= "*".profile_link("", $hidden_info['user_username'], ""); } } // get birthday list $this_day = date("d", time()); $this_month = date("m", time()); $birthday_list = array(); $birthday_query = simple_query("user_username", "members", "user_dob_day=$this_day AND user_dob_month=$this_month", "0user_username", "array"); while($birthday_info = mysqli_fetch_array($birthday_query, MYSQLI_ASSOC)) { $birthday_list[] .= profile_link("", $birthday_info['user_username'], ""); } // get current user info if(@$_SESSION['logged_in'] == 1) { $uid = $_SESSION['user_id']; $user_query = simple_query("*", "members", "user_id=$uid", "", "array"); $user_info = mysqli_fetch_array($user_query, MYSQLI_ASSOC); // is the user a mod or admin? switch($user_info['user_group']) { case "1": $_SESSION['permissions'] = 1; // admin permissions break; case "2": $_SESSION['permissions'] = 2; // mod permissions break; case "3": $_SESSION['permissions'] = 3; // standard permissions break; default; $_SESSION['permissions'] = 3; // standard permissions break; } $u_name = profile_link("", $user_info['user_username'], ""); // is the user banned? if($user_info['user_banned'] == 1) { $_SESSION['permissions'] = 0; // no permissions // get ban length $ban_query = simple_query("*", "bans", "user_id=$uid", "", "array"); $ban_info = mysqli_fetch_array($ban_query, MYSQLI_ASSOC); $ban_start = asf_date($ban_info['ban_start'],1); $ban_end = asf_date($ban_info['ban_end'],1); echo ban_notice($ban_start, $ban_end, ""); } } // get forum statistics $forum_stats = get_forum_stats(); ?> [attachment deleted by admin]
  21. the planning part is my problem. the first draft was a complete failure with no planning. so i started again thinking of all the planning i was going to do. but i did none and now im in the same mess. I think a fresh start is what i need. and plenty of planning.
  22. well when you view the site everything looks fine, and for the most part the basic features all work. but looking over the code for mybb and phpbb im stumped. they do things alot better than me but i dont understand half of it. mainly because they all use oop and i dont. i just need to know how to do things better. i have no problems with you making modifications to it but as it stands i think i am going to have to start again and plan better(2nd time i will have to start again) or just abandon it and call it a day. its been going on since august last year now and i dont seem to be getting any better at it.
  23. is this the full script? because $sql is just a string. it isnt doing anything to the database. it should be a mysql_query
  24. for those of you who don't know i am creating a piece of forum software called ASF. Ive done it by myself so far but as it grows i find it harder to write the code and keep organised. my code is a mess and things arent done the way they should be. So if anyone can give me advice or wants to help i could post some of the files for download. Even if you just want to have a look and let me know waht you think. Thanks Carl http://www.thevault.cz.cc
  25. That's alright. Honestly though, your markup has plenty of room for improvement and would make this, and allot of other things in the future much easier to implement I'm sure. Not to mention making your code easier to maintain and more efficient. could you give me a hint on where i could improve. I know you have done alot so far but this is the second time i have started the whole thing again in order to improve my coding and such thanks
×
×
  • 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.