PHP - Beginning Oo Php..create User Class Query
Hi,
I've always used PHP code in my websites in a procedural manner as I come from a html/css background. Now that I want to do projects with more complexity I'm thinking I need to approach development in a more Object Oriented fashion. My question is more a theoretical one. I'm creating a User class and I'm not sure on what is the best practise for putting my functions etc. and where to call them. My project will have 2 different users (Admin & End User) so is it correct to say that the User class should encapsulate all the functions of both of these users ? By that I mean create/delete/modify user, login & change password/forgotten password functionality rather than having a seperate Login class Should I only call the database functions within these methods of the user class as opposed to calling them on the php page where the form data is posted ? For example, if a user logins in and when the form data is posted I currently open a connection, validate data, run the query. In an OO approach would I have just one User class method thats relevant to a particular page functionality ? Say, in pseudo code, for handling a login request loginRequest.php Code: [Select] include User class try { create new user User(); User::login(); } catch Exception() and should my User class look something like this class.User.php Code: [Select] include DBase class class User { var name, var email, var password, function validateInput (email, password) { if (!valid input) throw Exception else return true } function login (email, password){ try { database connection validateInput(); sql to see if user exists and login } catch Exception } } Apologies for this being a bit long winded! thanks tmfl Similar TutorialsOK, Here is the code $sql = "SELECT TrialListing.listingID AS Trial, TrialClass.classID AS Class, place.place_name AS Place, CONCAT_WS( ' ', pedigree.pretitle, pedigree.`Name`) AS Hound, CONCAT_WS( ' ', ped2.pretitle, ped2. NAME )AS Sire, CONCAT_WS( ' ', ped3.pretitle, ped3. NAME )AS Dam, pedigree.Breeder, pedigree.`Owner`, CASE WHEN placement.place_id < 5 THEN TRUNCATE(TrialClass.number_of_entrants / placement.place_id,2) WHEN placement.place_id = 5 THEN '' ELSE 0 END AS Score FROM TrialListing Left Join TrialClass ON TrialListing.listingID = TrialClass.listingID JOIN placement ON placement.event_id = TrialClass.trialClassID JOIN pedigree ON pedigree.PedigreeId = placement.hound_id LEFT OUTER JOIN pedigree AS ped2 ON pedigree.SireId = ped2.PedigreeId LEFT OUTER JOIN pedigree AS ped3 ON pedigree.DamId = ped3.PedigreeId LEFT JOIN place ON place.place_id = placement.place_id WHERE TrialListing.listingID = 11 ORDER BY Class, FIELD(place.place_id, '1', '2', '3', '4', '0') "; // Database Query $result = mysql_query("$sql"); // Database Query result $num_rows = mysql_num_rows($result); // Starts the table echo "<table class=\"clubList\">\n <tr> <th>trialID</th> <th>ClassID</th> <th>Place</th> <th>Hound</th> <th>Sire</th> <th>Dam</th> <th>Score</th> </tr>"; // Create the contents of the table. for( $i = 0; $i < $row = mysql_fetch_array($result); $i++){ echo "<tr>\n" ."<td>".$row["Trial"]."</td>\n" ."<td>".$row["Class"]."</td>\n" ."<td>".$row["Place"]."</td>\n" ."<td>".$row["Hound"]."</td>\n" ."<td>".$row["Sire"]."</td>\n" ."<td>".$row["Dam"]."</td>\n" ."<td>".$row["Score"]."</td>\n" ."</tr>";} echo "</TABLE>"; Here is the output, I added the TrialID & ClassID for informational purposes, they do not need to be displayed in the live table. trialID ClassID Place Hound Sire Dam Score 11 1 1st Eaton Brook Tug Hill Tatonka Eaton Brook Hickety Hawk Eaton Brook Gunner's Beulah 43.00 11 1 2nd FC North Bend Igloo FC DFJ Murphy White IFC Brad-Ju's Bella Donna 21.50 11 1 3rd FC North Bend Igloo FC DFJ Murphy White IFC Brad-Ju's Bella Donna 14.33 11 1 4th Rail Road Spike VI Elwell's Mike Elwell's Hannah 10.75 11 1 NBQ FC Fish Creek Spike Fish Creek Bull II Fish Creek Susie [H849395] 11 2 1st Enman Hill Sweet Poppy FTCH Straight Arrow Lucky of Coos 32.00 11 2 2nd Fishflakes Penny At Harehaven FTCH Jill's Fair-Isle Spud FTCH Millbridge Brownie 16.00 11 2 3rd Line Elm Flakers IFC Flakers Rex IFC Line Elm Ginger 10.66 11 2 4th FTCH Fareast Mookie FTCH Mellowrun Sly FTCH Cape Breton Maude 8.00 11 2 NBQ FTCH Mellowrun Sly Mellowrun Skylighter FTCH Mellowrun Becka 11 3 1st Bojangle V Lee Otworth Half Acre's Cocoa Candy 23.00 11 3 2nd Gay Doll Gay Roll II Gay Idol 11.50 11 3 3rd Bruce's Blue Lady FC Kilsock's Blue Creek Bart Bishopville's Zippy 7.66 11 3 4th FC Pearson Creek Barbin FC Pearson Creek Barbarian FC B-Line Stubby 5.75 11 3 NBQ Sims Creek Cricket Ronnie Joe Sims Creek Tiny 11 4 1st FTCH Fareast Mookie FTCH Mellowrun Sly FTCH Cape Breton Maude 26.00 11 4 2nd FTCH Mellowrun Sly Mellowrun Skylighter FTCH Mellowrun Becka 13.00 11 4 3rd Fishflakes Penny At Harehaven FTCH Jill's Fair-Isle Spud FTCH Millbridge Brownie 8.66 11 4 4th Enman Hill Sweet Poppy FTCH Straight Arrow Lucky of Coos 6.50 11 4 NBQ Line Elm Flakers IFC Flakers Rex IFC Line Elm Ginger Below is what I would like to generate. How do I word or nest the proper PHP code/loops to accomplish this? ClassID Place Hound Sire Dam Score 1st Eaton Brook Tug Hill Tatonka Eaton Brook Hickety Hawk Eaton Brook Gunner's Beulah 43.00 2nd FC North Bend Igloo FC DFJ Murphy White IFC Brad-Ju's Bella Donna 21.50 3rd FC North Bend Igloo FC DFJ Murphy White IFC Brad-Ju's Bella Donna 14.33 4th Rail Road Spike VI Elwell's Mike Elwell's Hannah 10.75 NBQ FC Fish Creek Spike Fish Creek Bull II Fish Creek Susie [H849395] ClassID Place Hound Sire Dam Score 1st Enman Hill Sweet Poppy FTCH Straight Arrow Lucky of Coos 32.00 2nd Fishflakes Penny At Harehaven FTCH Jill's Fair-Isle Spud FTCH Millbridge Brownie 16.00 3rd Line Elm Flakers IFC Flakers Rex IFC Line Elm Ginger 10.66 4th FTCH Fareast Mookie FTCH Mellowrun Sly FTCH Cape Breton Maude 8.00 NBQ FTCH Mellowrun Sly Mellowrun Skylighter FTCH Mellowrun Becka ClassID Place Hound Sire Dam Score 1st Bojangle V Lee Otworth Half Acre's Cocoa Candy 23.00 2nd Gay Doll Gay Roll II Gay Idol 11.50 3rd Bruce's Blue Lady FC Kilsock's Blue Creek Bart Bishopville's Zippy 7.66 4th FC Pearson Creek Barbin FC Pearson Creek Barbarian FC B-Line Stubby 5.75 NBQ Sims Creek Cricket Ronnie Joe Sims Creek Tiny ClassID Place Hound Sire Dam Score 1st FTCH Fareast Mookie FTCH Mellowrun Sly FTCH Cape Breton Maude 26.00 2nd FTCH Mellowrun Sly Mellowrun Skylighter FTCH Mellowrun Becka 13.00 3rd Fishflakes Penny At Harehaven FTCH Jill's Fair-Isle Spud FTCH Millbridge Brownie 8.66 4th Enman Hill Sweet Poppy FTCH Straight Arrow Lucky of Coos 6.50 NBQ Line Elm Flakers IFC Flakers Rex IFC Line Elm Ginger I have a some value that are being generated from a database then thrown into <li><href> to create a list that user can click and fetch data through ajax right now its in a form select/menu and works fine however I need to convert to a list and use and onKeyDown event Code: [Select] <form> <select name="users" size="<?php echo $num_rows;?>" onchange="showUser(this.value)" > <?php do { ?> <option value="<?php echo $row_Recordset1['item_id']?>"><?php echo $row_Recordset1['item_id'].' '. $row_Recordset1['item_name']?></option> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); $rows = mysql_num_rows($Recordset1); if($rows > 0) { mysql_data_seek($Recordset1, 0); $row_Recordset1 = mysql_fetch_assoc($Recordset1); } ?> </select> </form> I need to correct this Code: [Select] <ol> <?php do { ?> <li onKeyDown="showUser(this.value)"><a href="getmenu.php?item_id="<?php echo $row_Recordset1['item_id']?>"> <?php echo $row_Recordset1['item_name']?></a></li> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); $rows = mysql_num_rows($Recordset1); if($rows > 0) { mysql_data_seek($Recordset1, 0); $row_Recordset1 = mysql_fetch_assoc($Recordset1); } ?> </ol> Hello all
i have this code
<?php $sql = "SELECT DISTINCT phonemodel FROM iphone ORDER BY phonemodel DESC LIMIT 4"; $rows = $conn->sqlExec($sql); $nr_row = $conn->num_rows; if($nr_row>=0) { $div_cls = (($nr_row % 2) == 0) ? 'linksmen' : 'linksmen_s'; foreach($rows as $row) { echo '<div class="'.$div_cls.'" title="'.$row['phonemodel'].'"><a href="iphone.php?phonemodel='.$row['phonemodel'].'"><img src="images/mark.png" alt="" /> '.$row['phonemodel'].'</a></div>'; } } ?>And looks like,the code take only firs class (linksmen) ,the condition else not working.did someone what is wrong. Thx What do you think of my user class so far? Room to improve, things to change etc. I'm still getting the hang of this oop thing. Code: [Select] http://pastebin.com/fPFk21k4 Can someone give me a hand on getting this working :p maybe how to use it and what not.. I'm trying but not very successful lol. I want to call the loaduser on the profile page.. <?php include "Database.php"; class User{ //Constructor - Create a new user function User(){ } //Constructor - Load an existing user function LoaddUser($userID){ $this->LoadUser($UserID); } function LoadUser($userID){ //$db = new Database(); $results = mysql_fetch_array(mysql_query("SELECT * FROM userInfo WHERE User_ID = '$userID'")); $UserID = $results[UserID]; $Email_Address = $results[Email_Address]; $Password = $results[Password]; $Name = $results[Name]; $Screen_Name = $results[Screen_Name]; return $results; } } ?> Thanks, Sean I'm new to OOP and straight out the gate Dreamweaver keeps giving me an error which I do not understand. I get that $_POST creates an array, however, in the procedural world I have always been able to assign a $variable to a $_POST. In fact if I remove the Class declaration the error goes away. What am am I missing ? - Many Thanks VJ : Code: [Select] <?php class LookUp { $first_name = $_POST["f_name"]; $last_name = $_POST ["l_name"]; $company = $_POST["company"]; } ?> I can't find out whats the problem here, would appreciate some input in how to think building my "if".
The problem is that I don't seem to catch if an email exists, nor if user exists and neither can I create a new user :/.
Appreciate your help alot!
<?php // Start the session in case of errors to display within the page of user creation session_start(); $err_msg = array(); $errflag = false; // Check if the submit button was pressed if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_POST['submit'] === 'Skapa') { // Crypt password $options = ['cost' => 10]; $username = strip_tags($_POST['uname']); $password = strip_tags(password_hash($_POST['pword'], PASSWORD_DEFAULT, $options)); $email = strip_tags($_POST['uname'], '@'); // Check so all the fields are filled if ($_POST['uname'] == '' || $_POST['pword'] == '' || $_POST['pwordcheck'] == '') { $err_msg[] = 'Please enter all fields<br>'; $errflag = true; } // See if passwords and confirm matches if ($_POST['pword'] !== $_POST['pwordcheck']) { $err_msg[] = 'Passwords doesn\'t match!<br>'; $errflag = true; } // Check password length, atleast 8 characters if (strlen($_POST['pword']) < 7) { $err_msg[] = 'Password must be atleast 8 characters long'; $errflag = true; } // Check if email exists include_once('../includes/db.inc.php'); $db = new PDO(DB_INFO, DB_USER, DB_PASS); $sql = "SELECT COUNT(*) AS count FROM movies WHERE email = :emailadress"; $stmt = $db->prepare($sql); $stmt->bindParam(':emailadress', $email); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); if ($row > 0) { $err_msg[] = 'Email already taken!'; $errflag = true; $db = NULL; } // Check if user exists include_once('../includes/db.inc.php'); $db = new PDO(DB_INFO, DB_USER, DB_PASS); $sql = "SELECT uname FROM users WHERE uname = :username"; $stmt = $db->prepare($sql); $stmt->bindParam(':username', $username); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); if ($row > 0) { $err_msg[] = 'User already exists'; $errflag = true; $db = NULL; } if ($errflag = false) { // Everything passed, create the user! include_once('../includes/db.inc.php'); $db = new PDO(DB_INFO, DB_USER, DB_PASS); $sql = "INSERT INTO users (uname, pword, email) VALUES (:username, :password, :emailadress)"; $stmt = $db->prepare($sql); $stmt->bindParam(':username', $username); $stmt->bindParam(':password', $password); $stmt->bindParam(':emailadress'); $stmt->execute(); $_SESSION['uname'] = $username; header('Location: ../template/header.php'); exit; } // If any error, send the user back and display messages if ($errflag == true) { $_SESSION['err_msg'] = $err_msg; session_write_close(); header('Location: ../user/create.php'); exit; } } else { $_SESSION['err_msg'] = $err_msg; session_write_close(); header('Location: ../user/create.php'); exit; } ?> Well I have a user profile page with codes written like this: Code: [Select] <?php $filename = "profile"; include("functions/functions.php"); include("functions/functions_users.php"); include("functions/functions_adopts.php"); include("functions/functions_friends.php"); include("inc/lang.php"); include("inc/bbcode.php"); //***************// // START SCRIPT // //***************// // This page handles user profiles and shows the site members... $user = $_GET["user"]; $page = $_GET["page"]; if($user != ""){ // We have specified a specific user who we are showing a profile for... // See if the user exists... $article_title = "{$user}'s Profile"; $query = "SELECT * FROM {$prefix}users, {$prefix}users_contacts, {$prefix}users_options, {$prefix}users_profile, {$prefix}users_status WHERE {$prefix}users.username = '{$user}' AND {$prefix}users_contacts.uid = {$prefix}users.uid AND {$prefix}users_options.uid = {$prefix}users.uid AND {$prefix}users_profile.uid = {$prefix}users.uid AND {$prefix}users_status.uid = {$prefix}users.uid AND {$prefix}users_contacts.username = {$prefix}users.username AND {$prefix}users_options.username = {$prefix}users.username AND {$prefix}users_profile.username = {$prefix}users.username AND {$prefix}users_status.username = {$prefix}users.username"; $result = runquery($query); $row = mysql_fetch_array($result); if($row['username'] == $user){ // First let's initiate tab system! include("inc/tabs.php"); include("css/tabs.css"); $article_content = "<div id='page-wrap'><div id='profile'> <ul class='nav'> <li class='nav0'><a href='#visitormessage'>Visitor Message</a></li> <li class='nav1'><a href='#aboutme' class='current'>About Me</a></li> <li class='nav2'><a href='#adopts'>Adoptables</a></li> <li class='nav3'><a href='#friends'>Friends</a></li> <li class='nav4 last'><a href='#contactinfo' class='last'>Contact Info</a></li> </ul><div class='list-wrap'>"; // Format user profile information... $id = $row['uid']; $ccstat = cancp($row['usergroup']); $website = (empty($row['website']))?"No Website Information Given":"<a href='{$row['website']}' target='_blank'>{$row['website']}</a>"; $facebook = (empty($row['facebook']))?"No Facebook Information Given":"<a href='{$row['facebook']}' target='_blank'>{$row['facebook']}</a>"; $twitter = (empty($row['twitter']))?"No Twitter Information Given":"<a href='{$row['twitter']}' target='_blank'>{$row['twitter']}</a>"; $msn = (empty($row['msn']))?"No MSN Information Given":$row['msn']; $aim = (empty($row['aim']))?"No AIM Information Given":$row['aim']; $yahoo = (empty($row['yahoo']))?"No YIM Information Given":$row['yahoo']; $skype = (empty($row['skype']))?"No YIM Information Given":$row['skype']; $row['username'] = ($ccstat == "yes")?"<img src='templates/icons/star.gif' /> {$row['username']}":$row['username']; $row['favpet'] = ($row['favpet'] == 0)?"None Selected":"<a href='http://www.{$domain}{$scriptpath}/levelup.php?id={$row['favpet']}' target='_blank'><img src='http://www.{$domain}{$scriptpath}/siggy.php?id={$row['favpet']}' border=0></a>"; // Here we go with the first tab content: Visitor Message $article_content .= "<ul id='visitormessage' class='hide'><strong><u>{$user}'s Profile Comments:</u></strong><br /><br /><table>"; $result = runquery("SELECT * FROM {$prefix}visitor_messages WHERE touser = '{$user}' ORDER BY vid DESC LIMIT 0, 10"); while($vmessage = mysql_fetch_array($result)){ $date = substr_replace($vmessage['datesent']," at ",10,1); $query2 = "SELECT * FROM {$prefix}users, {$prefix}users_profile WHERE {$prefix}users.username = '{$vmessage['fromuser']}' AND {$prefix}users_profile.uid = {$prefix}users.uid AND {$prefix}users_profile.username = {$prefix}users.username"; $result2 = runquery($query2); $sender = mysql_fetch_array($result2); $article_content .= "<tr> <td><img src='{$sender['avatar']}' width='40' height='40'></br></td> <td><a href='profile.php?user={$sender['username']}'>{$vmessage['fromuser']}</a> ({$date}) <a href='vmessage.php?act=view&user1={$user}&user2={$vmessage['fromuser']}'> <img src='templates/icons/status.gif'> </a> </br>{$vmessage['vmtext']} </br></td> <td><a href='vmessage.php?act=edit&vid={$vmessage['vid']}'> <img src='templates/icons/cog.gif'> </a> <a href='vmessage.php?act=delete&vid={$vmessage['vid']}'> <img src='templates/icons/delete.gif'> </a></br></td></tr>"; } if($isloggedin == "yes"){ if(isbanned($loggedinname) == 1){ $article_content .= "</table>It seems that you have been banned from this site and thus cannot send profile comment."; } else{ $article_content .= "</table> To Post a profile comment, please write your message in the text area below: <form action='profile.php?user={$user}' method='post'> <textarea rows='10' cols='50' name='vmtext' wrap='physical' ></textarea><br> <input type='submit' name='Submit' value='Submit'></form>"; $vmcontent = $_POST["vmtext"]; // Now check if the two users are friends... if($vmcontent != ""){ $datesent = date("Y-m-d H:i:s"); // $date = "2010-23-03 21:02:35"; $fromuser = $loggedinname; $touser = $user; runquery("INSERT INTO {$prefix}visitor_messages (vid, fromuser, touser, datesent, vmtext) VALUES ('', '$fromuser', '$touser' , '$datesent', '$vmcontent')"); $article_content .= "<p>Your comment for user has been posted. You may now view your conversation with {$user} from <a href='vmessage.php?act=view&user1={$fromuser}&user2={$touser}'>here</a>.</p>"; } } } else{ $article_content .= "</table>Guests cannot post profile comment, sorry..."; } // Now the second tab: About me... $article_content .= "</ul><ul id='aboutme'><li><strong><u>{$lang_basic_info} {$user}</u></strong><br /><br /> <img src='{$row['avatar']}' border=0 width='100' height=100 /><br /> <strong>Member Since:</strong> {$row['membersince']}<br /><br /> Gender: {$row['gender']}<br /> Favorite Color: {$row['color']}<br /> Nickname: {$row['nickname']}<br /> Bio: <br /> {$row['bio']}<br /></li>"; // The third tab: Adopts... $article_content .= "</ul><ul id='adopts' class='hide'><h2>.:AdoptSpotlight:.</h2><br /> {$row['favpet']}<br />{$row['about']}<br /><br /> <strong><u>{$user}'s Pets:</u></strong><br /><br />"; $query = "SELECT COUNT(*) AS pets FROM {$prefix}owned_adoptables WHERE owner = '{$user}'"; $result = runquery($query); $total = mysql_fetch_array($result); if($total['pets'] > 0){ $rowsperpage = 15; $totalpages = ceil($total['pets'] / $rowsperpage); if(is_numeric($page)) $currentpage = $page; else $currentpage = 1; if($currentpage > $totalpages) $currentpage = $totalpages; if($currentpage < 1) $currentpage = 1; $offset = ($currentpage - 1) * $rowsperpage; $query = "SELECT * FROM {$prefix}owned_adoptables WHERE owner = '{$user}' LIMIT {$offset}, {$rowsperpage}"; $result = runquery($query); while($row = mysql_fetch_array($result)){ $image = getcurrentimage($row['aid']); $article_content .= "<a href='levelup.php?id={$row['aid']}'><img src='{$image}' border='0' /></a>"; } $article_content .= "<br />"; if($currentpage > 1){ $newpage = $currentpage - 1; $article_content .= "<strong><a href='profile.php?user={$user}&page={$newpage}'><img src='templates/icons/prev.gif' border=0> Previous Page</a></strong> "; } else $article_content .= "<strong><img src='templates/icons/prev.gif' border=0> Previous Page</strong> "; if($currentpage < $totalpages){ $newpage = $currentpage + 1; $article_content .= " :: <strong><a href='profile.php?user={$user}&page={$newpage}'>Next Page <img src='templates/icons/next.gif' border=0></a></strong> "; } else $article_content .= " :: <strong>Next Page <img src='templates/icons/next.gif' border=0></strong>"; } else{ $article_content .= "This user currently does not have any pets."; } // The fourth tab: Friends... $friendlist = getfriendid($user); $friendnum = getfriendnum($user); $article_content .= "</ul><ul id='friends' class='hide'>{$user} currently have {$friendnum} friends.<br /><table>"; if($friendnum != 0){ foreach($friendlist as $friendid){ $query = "SELECT * FROM {$prefix}users, {$prefix}users_profile WHERE {$prefix}users.uid = '{$friendid}' AND {$prefix}users_profile.uid = {$prefix}users.uid AND {$prefix}users_profile.username = {$prefix}users.username"; $result = runquery($query) ; $friendinfo = mysql_fetch_array($result); $uid = $friendinfo['uid']; $username = $friendinfo['username']; $friendgender = getfriendgender($username); $onlinestatus = getonlinestatus($username); $article_content .= "<tr><td style='text-align: left'><img src='{$friendinfo['avatar']}' border=0 width='60' height =60></td> <td><strong><a href='profile.php?user={$username}'>{$username}</a></strong> {$friendgender}<br />{$friendinfo['nickname']}<br />{$onlinestatus} <a href='{$friendinfo['website']}' target='_blank'><img src='templates/icons/web.gif'></a> <a href='messages.php?act=newpm&user={$username}'><img src='templates/icons/title.gif'></a></td>"; $article_content .= ($user == $loggedinname)?"<td style='text-align: right'><br /><br /><br /><a href='friends.php?act=delete&uid={$uid}'>Break Friendship </td></tr>":"</tr>"; } } $article_content .= "</table>"; // The last tab: Contact Info! $article_content .= "</ul><ul id='contactinfo' class='hide'><img src='templates/icons/web.gif' /> {$website}<br /> <img src='templates/icons/facebook.gif' /> {$facebook}<br /> <img src='templates/icons/twitter.gif' /> {$twitter}<br /> <img src='templates/icons/aim.gif' /> {$aim}<br /> <img src='templates/icons/msn.gif' /> {$msn}<br /> <img src='templates/icons/yahoo.gif' /> {$yahoo}<br /> <img src='templates/icons/skype.gif' /> {$skype}<br /> <img src='templates/icons/title.gif' /> <a href='messages.php?act=newpm&user={$user}'>Send {$user} a Private Message</a><br /> <img src='templates/icons/fr.gif' /><a href='friends.php?act=request&uid={$id}'>Send {$user} a Friend Request</a><br /> <br /></div></div>"; } else{ $article_content .= "Sorry, but we could not find a user in the system with the name {$user}. Please make sure you have the username right. The user's account may also have been deleted by the system admin."; } } else{ // We did not specify a user, so show the memberlist $article_title = "Memberlist"; $article_content = "Here are all of the members of this site, sorted by registration date.<br /><br />"; include("classes/class_pagination.php"); include("css/pagination.css"); $query = "SELECT * FROM {$prefix}users ORDER BY uid ASC"; $result = runquery($query); $rowsperpage = 15; $pagination = new Pagination($query, $rowsperpage, "http://www.{$domain}{$scriptpath}/profile.php"); $pagination->setPage($_GET[page]); $query = "SELECT * FROM {$prefix}users ORDER BY uid ASC LIMIT {$pagination->getLimit()},{$rowsperpage}"; $result = runquery($query); while ($row = mysql_fetch_array($result)){ $status = cancp($row['usergroup']); $star = ($status == "yes")?"<img src='templates/icons/star.gif' border=0' /> ":""; $article_content .= "<strong><a href='profile.php?user={$row['username']}'>{$star}{$row['username']}</a></strong><br />"; } $article_content .= "<br />{$pagination->showPage()}"; } //***************// // OUTPUT PAGE // //***************// echo showpage($article_title, $article_content, $date); ?> In order to improve re-usability of the tabs, I attempted to create a file called class_tabs.php to make it object oriented. It did not work however, as the css is seriously messed up, and I have absolutely no idea why it did not. Here is the class file: Code: [Select] <?php class Tab{ private $t_num; private $t_name = array(); private $t_alias = array(); private $t_content; private $t_default; private $t_hide; private $t_index = array(); private $t_last = array(); public function __construct($num, $tabs, $default=1){ $this->t_num = $num; $this->t_default = $default; $i = 0; foreach ($tabs as $key => $val){ $this->t_name[$i] = $key; $this->t_alias[$i] = $val; $this->t_index[$i] = ($i == $default-1)?" class='current":""; $this->t_index[$i] = ($i == $num-1)?" class='last":$this->t_index[$i]; $this->t_last[$i] = ($i == $num-1)?" last":""; $i++; } } public function createtab(){ if($this->t_num < 2 or $this->t_num > 5) throw new Exception("The number of tabs must be restricted between 2 to 5!",272); $this->t_content = "<div id='page-wrap'><div id='tab'><ul class='nav'>"; for($i=0; $i<$this->t_num; $i++){ $this->t_content .= " <li class='nav{$i}{$this->t_last[$i]}'><a href='#{$this->t_alias[$i]}{$this->t_index[$i]}'>{$this->t_name[$i]}</a></li>"; } $this->t_content .= "</ul><div class='list-wrap'>"; return $this->t_content; } public function starttab($index){ $this->t_hide = ($index == $this->t_default)?"":" class='hide'"; $this->t_content .= "<ul id='{$this->t_alias}'{$this->t_hide}>"; return $this->t_content; } public function endtab($index){ $this->t_content .= "</ul>"; if($index == $this->t_num) $this->t_content .= "</div></div>"; return $this->t_content; } } ?> And this is the modified profile codes with OOP: Code: [Select] <?php $filename = "profile"; include("functions/functions.php"); include("functions/functions_users.php"); include("functions/functions_adopts.php"); include("functions/functions_friends.php"); include("inc/lang.php"); include("inc/bbcode.php"); //***************// // START SCRIPT // //***************// // This page handles user profiles and shows the site members... $user = $_GET["user"]; $page = $_GET["page"]; if($user != ""){ // We have specified a specific user who we are showing a profile for... // See if the user exists... $article_title = "{$user}'s Profile"; $query = "SELECT * FROM {$prefix}users, {$prefix}users_contacts, {$prefix}users_options, {$prefix}users_profile, {$prefix}users_status WHERE {$prefix}users.username = '{$user}' AND {$prefix}users_contacts.uid = {$prefix}users.uid AND {$prefix}users_options.uid = {$prefix}users.uid AND {$prefix}users_profile.uid = {$prefix}users.uid AND {$prefix}users_status.uid = {$prefix}users.uid AND {$prefix}users_contacts.username = {$prefix}users.username AND {$prefix}users_options.username = {$prefix}users.username AND {$prefix}users_profile.username = {$prefix}users.username AND {$prefix}users_status.username = {$prefix}users.username"; $result = runquery($query); $row = mysql_fetch_array($result); if($row['username'] == $user){ // First let's initiate tab system! include("inc/tabs.php"); include("css/tabs.css"); include("classes/class_tabs.css"); $profile_tabs = new Tabs(5, array("Visitor Message" => "visitormessage", "About Me" => "aboutme", "Adoptables" => "adopts", "Friends" => "friends", "Contact Info" => "contactinfo"), 2); $article_content = $profile_tabs -> createtab(); // Format user profile information... $id = $row['uid']; $ccstat = cancp($row['usergroup']); $website = (empty($row['website']))?"No Website Information Given":"<a href='{$row['website']}' target='_blank'>{$row['website']}</a>"; $facebook = (empty($row['facebook']))?"No Facebook Information Given":"<a href='{$row['facebook']}' target='_blank'>{$row['facebook']}</a>"; $twitter = (empty($row['twitter']))?"No Twitter Information Given":"<a href='{$row['twitter']}' target='_blank'>{$row['twitter']}</a>"; $msn = (empty($row['msn']))?"No MSN Information Given":$row['msn']; $aim = (empty($row['aim']))?"No AIM Information Given":$row['aim']; $yahoo = (empty($row['yahoo']))?"No YIM Information Given":$row['yahoo']; $skype = (empty($row['skype']))?"No YIM Information Given":$row['skype']; $row['username'] = ($ccstat == "yes")?"<img src='templates/icons/star.gif' /> {$row['username']}":$row['username']; $row['favpet'] = ($row['favpet'] == 0)?"None Selected":"<a href='http://www.{$domain}{$scriptpath}/levelup.php?id={$row['favpet']}' target='_blank'><img src='http://www.{$domain}{$scriptpath}/siggy.php?id={$row['favpet']}' border=0></a>"; // Here we go with the first tab content: Visitor Message $article_content .= "{$profile_tabs -> starttab(0)}<strong><u>{$user}'s Profile Comments:</u></strong><br /><br /><table>"; $result = runquery("SELECT * FROM {$prefix}visitor_messages WHERE touser = '{$user}' ORDER BY vid DESC LIMIT 0, 10"); while($vmessage = mysql_fetch_array($result)){ $date = substr_replace($vmessage['datesent']," at ",10,1); $query2 = "SELECT * FROM {$prefix}users, {$prefix}users_profile WHERE {$prefix}users.username = '{$vmessage['fromuser']}' AND {$prefix}users_profile.uid = {$prefix}users.uid AND {$prefix}users_profile.username = {$prefix}users.username"; $result2 = runquery($query2); $sender = mysql_fetch_array($result2); $article_content .= "<tr> <td><img src='{$sender['avatar']}' width='40' height='40'></br></td> <td><a href='profile.php?user={$sender['username']}'>{$vmessage['fromuser']}</a> ({$date}) <a href='vmessage.php?act=view&user1={$user}&user2={$vmessage['fromuser']}'> <img src='templates/icons/status.gif'> </a> </br>{$vmessage['vmtext']} </br></td> <td><a href='vmessage.php?act=edit&vid={$vmessage['vid']}'> <img src='templates/icons/cog.gif'> </a> <a href='vmessage.php?act=delete&vid={$vmessage['vid']}'> <img src='templates/icons/delete.gif'> </a></br></td></tr>"; } if($isloggedin == "yes"){ if(isbanned($loggedinname) == 1){ $article_content .= "</table>It seems that you have been banned from this site and thus cannot send profile comment."; } else{ $article_content .= "</table> To Post a profile comment, please write your message in the text area below: <form action='profile.php?user={$user}' method='post'> <textarea rows='10' cols='50' name='vmtext' wrap='physical' ></textarea><br> <input type='submit' name='Submit' value='Submit'></form>"; $vmcontent = $_POST["vmtext"]; // Now check if the two users are friends... if($vmcontent != ""){ $datesent = date("Y-m-d H:i:s"); // $date = "2010-23-03 21:02:35"; $fromuser = $loggedinname; $touser = $user; runquery("INSERT INTO {$prefix}visitor_messages (vid, fromuser, touser, datesent, vmtext) VALUES ('', '$fromuser', '$touser' , '$datesent', '$vmcontent')"); $article_content .= "<p>Your comment for user has been posted. You may now view your conversation with {$user} from <a href='vmessage.php?act=view&user1={$fromuser}&user2={$touser}'>here</a>.</p>"; } } } else{ $article_content .= "</table>Guests cannot post profile comment, sorry..."; } // Now the second tab: About me... $article_content .= "{$profile_tabs -> endtab(0)}{$profile_tabs -> starttab(1)} <li><strong><u>{$lang_basic_info} {$user}</u></strong><br /><br /> <img src='{$row['avatar']}' border=0 width='100' height=100 /><br /> <strong>Member Since:</strong> {$row['membersince']}<br /><br /> Gender: {$row['gender']}<br /> Favorite Color: {$row['color']}<br /> Nickname: {$row['nickname']}<br /> Bio: <br /> {$row['bio']}<br /></li>"; // The third tab: Adopts... $article_content .= {$profile_tabs -> endtab(1)}{$profile_tabs -> starttab(2)}<h2>.:AdoptSpotlight:.</h2><br /> {$row['favpet']}<br />{$row['about']}<br /><br /> <strong><u>{$user}'s Pets:</u></strong><br /><br />"; $query = "SELECT COUNT(*) AS pets FROM {$prefix}owned_adoptables WHERE owner = '{$user}'"; $result = runquery($query); $total = mysql_fetch_array($result); if($total['pets'] > 0){ $rowsperpage = 15; $totalpages = ceil($total['pets'] / $rowsperpage); if(is_numeric($page)) $currentpage = $page; else $currentpage = 1; if($currentpage > $totalpages) $currentpage = $totalpages; if($currentpage < 1) $currentpage = 1; $offset = ($currentpage - 1) * $rowsperpage; $query = "SELECT * FROM {$prefix}owned_adoptables WHERE owner = '{$user}' LIMIT {$offset}, {$rowsperpage}"; $result = runquery($query); while($row = mysql_fetch_array($result)){ $image = getcurrentimage($row['aid']); $article_content .= "<a href='levelup.php?id={$row['aid']}'><img src='{$image}' border='0' /></a>"; } $article_content .= "<br />"; if($currentpage > 1){ $newpage = $currentpage - 1; $article_content .= "<strong><a href='profile.php?user={$user}&page={$newpage}'><img src='templates/icons/prev.gif' border=0> Previous Page</a></strong> "; } else $article_content .= "<strong><img src='templates/icons/prev.gif' border=0> Previous Page</strong> "; if($currentpage < $totalpages){ $newpage = $currentpage + 1; $article_content .= " :: <strong><a href='profile.php?user={$user}&page={$newpage}'>Next Page <img src='templates/icons/next.gif' border=0></a></strong> "; } else $article_content .= " :: <strong>Next Page <img src='templates/icons/next.gif' border=0></strong>"; } else{ $article_content .= "This user currently does not have any pets."; } // The fourth tab: Friends... $friendlist = getfriendid($user); $friendnum = getfriendnum($user); $article_content .= "{$profile_tabs -> endtab(2)}{$profile_tabs -> starttab(3)}{$user} currently have {$friendnum} friends.<br /><table>"; if($friendnum != 0){ foreach($friendlist as $friendid){ $query = "SELECT * FROM {$prefix}users, {$prefix}users_profile WHERE {$prefix}users.uid = '{$friendid}' AND {$prefix}users_profile.uid = {$prefix}users.uid AND {$prefix}users_profile.username = {$prefix}users.username"; $result = runquery($query) ; $friendinfo = mysql_fetch_array($result); $uid = $friendinfo['uid']; $username = $friendinfo['username']; $friendgender = getfriendgender($username); $onlinestatus = getonlinestatus($username); $article_content .= "<tr><td style='text-align: left'><img src='{$friendinfo['avatar']}' border=0 width='60' height =60></td> <td><strong><a href='profile.php?user={$username}'>{$username}</a></strong> {$friendgender}<br />{$friendinfo['nickname']}<br />{$onlinestatus} <a href='{$friendinfo['website']}' target='_blank'><img src='templates/icons/web.gif'></a> <a href='messages.php?act=newpm&user={$username}'><img src='templates/icons/title.gif'></a></td>"; $article_content .= ($user == $loggedinname)?"<td style='text-align: right'><br /><br /><br /><a href='friends.php?act=delete&uid={$uid}'>Break Friendship </td></tr>":"</tr>"; } } $article_content .= "</table>"; // The last tab: Contact Info! $article_content .= "{$profile_tabs -> endtab(3)}{$profile_tabs -> starttab(4)}<img src='templates/icons/web.gif' /> {$website}<br /> <img src='templates/icons/facebook.gif' /> {$facebook}<br /> <img src='templates/icons/twitter.gif' /> {$twitter}<br /> <img src='templates/icons/aim.gif' /> {$aim}<br /> <img src='templates/icons/msn.gif' /> {$msn}<br /> <img src='templates/icons/yahoo.gif' /> {$yahoo}<br /> <img src='templates/icons/skype.gif' /> {$skype}<br /> <img src='templates/icons/title.gif' /> <a href='messages.php?act=newpm&user={$user}'>Send {$user} a Private Message</a><br /> <img src='templates/icons/fr.gif' /><a href='friends.php?act=request&uid={$id}'>Send {$user} a Friend Request</a><br /> <br />{$profile_tabs -> endtab(4)}"; } else{ $article_content .= "Sorry, but we could not find a user in the system with the name {$user}. Please make sure you have the username right. The user's account may also have been deleted by the system admin."; } } else{ // We did not specify a user, so show the memberlist $article_title = "Memberlist"; $article_content = "Here are all of the members of this site, sorted by registration date.<br /><br />"; include("classes/class_pagination.php"); include("css/pagination.css"); $query = "SELECT * FROM {$prefix}users ORDER BY uid ASC"; $result = runquery($query); $rowsperpage = 15; $pagination = new Pagination($query, $rowsperpage, "http://www.{$domain}{$scriptpath}/profile.php"); $pagination->setPage($_GET[page]); $query = "SELECT * FROM {$prefix}users ORDER BY uid ASC LIMIT {$pagination->getLimit()},{$rowsperpage}"; $result = runquery($query); while ($row = mysql_fetch_array($result)){ $status = cancp($row['usergroup']); $star = ($status == "yes")?"<img src='templates/icons/star.gif' border=0' /> ":""; $article_content .= "<strong><a href='profile.php?user={$row['username']}'>{$star}{$row['username']}</a></strong><br />"; } $article_content .= "<br />{$pagination->showPage()}"; } //***************// // OUTPUT PAGE // //***************// echo showpage($article_title, $article_content, $date); ?> Incase you find it necessary, the css/tabs.css and inc/tabs.php files are provided below. They should be irrelevant to this problem though, but just incase.. css/tabs.css Code: [Select] <style type="text/css"> * body { font: 12px Georgia, serif; } html { overflow-y: scroll; } a { text-decoration: none; } a:focus { outline: 0; } p { font-size: 15px; margin: 0 0 20px 0; } #page-wrap { width: 640px; margin: 30px;} h1 { font: bold 40px Sans-Serif; margin: 0 0 20px 0; } /* Generic Utility */ .hide { position: absolute; top: -9999px; left: -9999px; } /* Specific to example one */ #profile { background: #eee; padding: 10px; margin: 0 0 20px 0; -moz-box-shadow: 0 0 5px #666; -webkit-box-shadow: 0 0 5px #666; } #profile .nav { overflow: hidden; margin: 0 0 10px 0; } #profile .nav li { width: 97px; float: left; margin: 0 10px 0 0; } #profile .nav li.last { margin-right: 0; } #profile .nav li a { display: block; padding: 5px; background: #959290; color: white; font-size: 10px; text-align: center; border: 0; } #profile .nav li a:hover { background-color: #111; } #profile ul { list-style: none; } #profile ul li a { display: block; border-bottom: 1px solid #666; padding: 4px; color: #666; } #profile ul li a:hover { background: #fe4902; color: white; } #profile ul li:last-child a { border: none; } #profile ul li.nav0 a.current, #profile ul.visitormessage li a:hover { background-color: #0575f4; color: white; } #profile ul li.nav1 a.current, #profile ul.aboutme li a:hover { background-color: #d30000; color: white; } #profile ul li.nav2 a.current, #profile ul.adopts li a:hover { background-color: #8d01b0; color: white; } #profile ul li.nav3 a.current, #profile ul.friends li a:hover { background-color: #FE4902; color: white; } #profile ul li.nav4 a.current, #profile ul.contactinfo li a:hover { background-color: #Eac117; color: white; } </style> Code: [Select] <?php if($filename == "profile"){ ?> <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'></script> <script src="js/tabs.js"></script> <script> $(function() { $("#profile").organicTabs(); }); </script> <? } ?> Please help... Hello everybody, This is my first post here and I am beginner in PHP world in terms of writing the code to serve my own purposes. Well I am building a web app and basically it's a calendar which pulls information from .js file. Now I have thinking for the past couple of days how can I accomplish that each user that registers on the site manipulates its own .js file because information from .js file will be shown on calendar. Let me tell you how it's currently set up: 1. JavaScript file with particular static name is called under the script that is placed on index.php and the data is displayed on the page itself. So I would love to have is set it up like this: 1. Index page contains login form - Each registered/logged in user will have its own session 2. User registers and based on username/email new .js file is created out of a blank template and it is named based on user's username 3. user is then redirected to the calendar index which contains javascript that cals out that appropriate .js file based on the what user is logged in and displays data to the calendar I am not sure if that is doable with PHP or not but that's my thinking how it can be done if it's doable. I am open for any kind of suggestions how all this can be put together and if you do have better ideas I would love to hear from you. Hi, i coded a very simple forum "website" with registration, login, and a place where everyone posts comments. I wanted to make some sort of profile page for each user so they would each have their own URL too (e.i. test/barney or test/simpsons). each of these pages would have different content, depending on what barney or simpsons puts on that page. i've been looking everywhere trying to find documentation but i don't think i know how to search it correctly. I checked a lot of mod_rewrite documentation but i don't understand if i'm suppose to call a php function to create a profile page or something. Any guidance would be greatly appreciated Thanks! Whats going on PHPfreaks? So this is what I've been trying to do for the whole weekend and just can't figure it out. I want to let users create new pages on my site like wiki style but dont want a wiki or drupal or joomla or any of that. I know its possible with: $text = $_POST['text']; $file = fopen($text . ".php","x"); fwrite($file,"Welcome to your new page!"); but I'm not sure how to integrate it. For further clarification here's an example: You come to the site and there is a list of previously made user pages all with their own user generated name. What I want to have is a create new page button that opens a new page allows the user to upload images then submit it to the database and upon refresh of the page their page is now in the list. The create new page resets and is available for another user and on and on. Any help will be appreciated. I need to get this done it's driving me crazy. Hi Guys, have you got an idea how I can create a user management system with login and pw, please? I tried the below, but when I click on the "ADD NEW USER" button nothing happens <div> <fieldset> <legend>USER DETAILS</legend> <table> <tr> <td align="right"><a title='NAME' href='user_edit.php?id=1'>NAME</a></td> <td> <input class="norm" type="text" name="name" id="name" /></div> </td> <td align="right"><a title='SURNAME' href='user_edit.php?id=2'>SURNAME</a></td> <td> <input class="norm" type="text" name="surname" id="surname" /></div> </td> </tr> <tr> <td align="right"><a title='E-MAIL ADDRESS' href='user_edit.php?id=3'>E-MAIL ADDRESS</a></td> <td colspan="4"> <input class="norm" type="text" size="57" name="e-mail" id="e-mail" /></div> </td> </tr> <tr> <td align="right"><a title='LOGIN' href='user_edit.php?id=4'>LOGIN</a></td> <td> <input type="text" name="login" id="login" /></div> </td> <td align="right"><a title='PASSWORD' href='user_edit.php?id=5'>PASSWORD</a></td> <td> <input class="norm" type="text" name="password" id="password" /></div> </td> </tr> </table> </fieldset> </div> <br /> <div> <fieldset> <input type='submit' name='delete' value='DELETE USER' onclick='confirm("ARE YOU SURE?");'/> <input type='submit' name='add' value='ADD NEW USER'/> </fieldset> </div> cheers, ozzo How would I go about creating a new user email account that can be accessed via my cpanel mail scripts (RoundCube, SquirrelMail, etc.), in PHP. All my code is returning is the username... Please help.
index.php
<?php include('user.class'); $user = new user("Jbonnett", "0", "Admin", "Jamie", "Bonnett", "jbonnett@site.co.uk", "01/09/1992"); echo "username: " . $user->getUsername() . "<br/>"; echo "id: " . $user->getId() . "<br/>"; echo "level: " . $user->getLevel() . "<br/>"; echo "Forename: " . $user->getForename() . "<br/>"; echo "Surname: " . $user->getSurname() . "<br/>"; echo "Email: " . $user->getEmail() . "<br/>"; echo "Dob: " . $user->getDob() . "<br/>"; ?>user.class <?php class user { private $username; private $id; private $level; private $forename; private $surname; private $email; private $dob; public function user($username, $id, $level, $forname, $surname, $email, $dob) { $this->setUsername($username); $this->setId($id); $this->setLevel($level); $this->setForename($forename); $this->setSurname($surname); $this->setEmail($email); $this->setDob($dob); } public function destroy() { unset($this->username); unset($this->id); unset($this->level); unset($this->forename); unset($this->surname); unset($this->uemail); unset($this->dob); } public function setUsername($username) { $this->username = $username; } public function getUsername() { return $this->username; } public function setId($id) { $this->id = $id; } public function getId() { return $this->$id; } public function setLevel($level) { $this->level = $level; } public function getLevel() { return $this->level; } public function setForename($forename) { $this->foreName = $forename; } public function getForename() { return $this->forename; } public function setSurname($surname) { $this->surName = $surname; } public function getSurname() { return $this->surname; } public function setEmail($email) { $this->email = $email; } public function getEmail() { return $this->email; } public function setDob($dob) { $this->dob = $dob; } public function getDob() { return $this->dob; } }; ?> Hello,
I'm embarking on a pretty ambitious task and I need some bits of information here and there.
One of the functions I need to achieve is to build a query or array of photos based on a background image and user input.
So imagine that I have a box and within that box is a column of three rows.
I need to have three different bits of data be placed into each of the subsequent rows and then an image is taken of these three pieces of data overlaying the background photo.
Then stored somewhere with an incremented identifier to be pulled later.
I think I can already begin to imagine how it would work but what eludes me is a "screenshot" function to generate the images. I'm looking for .png or .jpg end result files with fixed width/height and item placement.
Thank you for any help
i have a simple class which sees if there are any members in the database with the supplied details, then returns a simple number to show how many results there are, but it isnt working and throwing the error: Code: [Select] Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\classTest\classes\user_process.php on line 52 here is the class: require_once("db_mysql.php"); require_once("./init.php"); class emptyArgs extends Exception { function __toString() { return "<strong>Empty Arguments</strong>"; } } class user_process { public $user_name; public $password; public function login($user_name, $password) { try { if (empty($user_name) || empty($password)) { throw new emptyArgs(); } if ($user_name == "") { throw new emptyArgs(); } } catch (emptyArgs $e) { echo $e; echo "<p>Please Supply All Details Marked *</p>"; } echo $user_name; echo $password; $query = <<<QUERY SELECT COUNT(*) FROM ".TBL_PREFIX."members WHERE user_username = '$user_name' AND user_password = '$password' QUERY; $process = mysql_query($query); $result = mysql_num_rows($process); // Line 52 where the error originates return $result; } } and here is the call: $user = new user_process(); $user->login("username", "password"); All of the database details are correct and the values do match in the database. Where am i going wrong? Note that this class is just for testing and not actually used. I have a function that performs a SELECT query on a MySQL database and populates the results in an array of Class. At the moment it is using PDO. Trouble is that PDO is not supported by the server the code will run on. Changing server is not an option, nor is installing PDO.
I have tried splitting the function to use the PDO method if installed or MySQLi if not. I am struggling to get the MySQLi part working though. Can anyone help me with this?
Here is the function I have so far which basically returns nothing from the MySQLi part:
public function mysqlSelectToClass($query, $className, $args = NULL) { include (dirname(__FILE__) . "/../config.php"); if (class_exists('PDO')) { $db = new PDO('mysql:host=' . $db_host . ';dbname=' . $db_name . ';charset=utf8', $db_user, $db_pass); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbQuery = $db->prepare($query); if (isset($args)) { foreach ($args as $arg) { $dbQuery->bindParam(array_values($arg)[0], array_values($arg)[0], PDO::PARAM_STR); } } $dbQuery->execute(); return $dbQuery->fetchAll(PDO::FETCH_CLASS, $className); } else { $db = mysqli_connect($db_host, $db_user, $db_pass, $db_name); $dbQuery = $db->prepare($query); if (isset($args)) { // Type is a string of parameter types e.g. "is" $type = array_values($args)[0]; // Params is an array of parameters e.g. array(1, 'value') $params = array_values($args)[1]; call_user_func_array('mysqli_stmt_bind_param', array_merge(array($dbQuery, $type), $this->byrefValues($params))); $result = mysqli_stmt_execute($dbQuery); mysqli_close($db); } elseif ($dbResult = mysqli_query($db, $query)) { $result = mysqli_fetch_object($dbResult, $className); mysqli_close($db); } return $result; } }the byrefValues function is simply swapping a value array to a reference array and seems to be working fine. I can paste that too if required. Thanks Jay Edited by jay20aiii, 24 September 2014 - 12:41 PM. I'm not exactly sure how to go about this, but I have an IM & online friends script that shows the online friends both in a module position as well as in a jquery box. Currently it's set to link the results to the IM function for both positions, however I want the module position to link to their profile and the jquery box to link to the IM function. Here is the bit of code where this is done: <!-- I added this as the second option to link to the profile... $text2.="<div onmousedown=\"createChatBoxmesg('".$res[$show_name]."','".$res['id']."')\"><a class=\"texts\" href='index.php?option=com_comprofiler'><img style='padding:0px 5px 0px 0px;' src='".$res['avatar']."' height='25' width='25' />".$res[$show_name]."</a></div><hr/>"; --> $text.="<div onmousedown=\"createChatBoxmesg('".$res[$show_name]."','".$res['id']."')\"><a class=\"texts\" href='javascript:void(0)'><img style='padding:0px 5px 0px 0px;' src='".$res['avatar']."' height='25' width='25' />".$res[$show_name]."</a></div><hr/>"; } } $query="SELECT * FROM frei_chat WHERE frei_chat.to=$usr_id AND recd=0 ORDER BY sent"; $db->setQuery($query); $jon->messages=$db->loadAssocList(); <!-- I need to add this here but obviously so far u can just have one or the other.. $jon->userdata=$text2; --> $jon->userdata=$text; $jon->result=$exec; $jon->count=$onlcnt; It would be simple if I could do an if else depending on the div id or class it sits in but as far as I know there is no real way to do that. Anyone have any ideas on how to do this? Dear All, I would like to create a json a below format { "data": [ { "datetime": "2021-05-12", "history": [ { "name": "ABC", "feel": 1, "cough": 0, "fever": 1, "headache": 1, "tired": 0, "appetite": 0, }, { "name": "DEF", "feel": 1, "cough": 0, "fever": 1, "headache": 1, "tired": 0, "appetite": 0, } ] }, { "datetime": "2021-05-13", "history": [ { "name": "ABC", "feel": 1, "cough": 0, "fever": 1, "headache": 1, "tired": 0, "appetite": 0, }, { "name": "DEF", "feel": 1, "cough": 0, "fever": 1, "headache": 1, "tired": 0, "appetite": 0, } ] }, { "datetime": "2021-05-14", "history": [ { "name": "ABC", "feel": 1, "cough": 0, "fever": 1, "headache": 1, "tired": 0, "appetite": 0, }, { "name": "DEF", "feel": 1, "cough": 0, "fever": 1, "headache": 1, "tired": 0, "appetite": 0, } ] } ] } But I need to select database 2 time because information need to group by date so my PHP like below $myArray = array(); $stmt = $conn->prepare("SELECT survay_date FROM tb_feedback WHERE app_ID = ? GROUP BY CAST(survay_date AS DATE) ORDER BY survay_date DESC"); $stmt->bind_param("s", $data->{'app_id'}); $stmt->execute(); $res = $stmt->get_result(); if($res->num_rows==0){ header('Content-Type: application/json'); $json = array(); $myArray['data'] = $json; echo json_encode($myArray);die(); } while($row = $res->fetch_array(MYSQLI_ASSOC)) { $myArray['data'][] = array_push($row,array("A","B")); $statement = $conn->prepare("SELECT tb_register.firstname,tb_feedback.feel,tb_feedback.cough,tb_feedback.fever,tb_feedback.headache,tb_feedback.tired,tb_feedback.appetite,tb_feedback.swelling FROM tb_feedback INNER JOIN tb_register ON tb_register.id = tb_feedback.user_id WHERE tb_feedback.app_ID = ? AND tb_feedback.survay_date = ?"); $statement->bind_param("s", $data->{'app_id'}); $statement->bind_param("s", $row['survay_date']); $statement->execute(); $result = $statement->get_result(); while($infor = $result->fetch_array(MYSQLI_ASSOC)) { $myArray['data'][] = $infor; } } header('Content-Type: application/json'); echo json_encode($myArray); So, How can I create the json format like that? Hi, I have attached sql script for table structure and sample data. When I run following sql query ,I get result set. Code: [Select] select * from tablename order by col10 desc I want to create array using result set. Following is the require structure of array. Code: [Select] <?php $resultSet[]=array ( ('0') =>array ( ('col10value1') => array ( ('0') => array ( ('col1') => 'col1', ('col2') => 'col2', ('col3') => 'col3', ('col4') => 'col4', ('col5') => 'col5', ('col6') => 'col6', ('col7') => 'col7', ('col8') => 'col8', ), ('1') => array ( ('col1') => 'col1', ('col2') => 'col2', ('col3') => 'col3', ('col4') => 'col4', ('col5') => 'col5', ('col6') => 'col6', ('col7') => 'col7', ('col8') => 'col8', ), ), ), ('1') => array ( ('col10value2') => array ( ('0') => array ( ('col1') => 'col1', ('col2') => 'col2', ('col3') => 'col3', ('col4') => 'col4', ('col5') => 'col5', ('col6') => 'col6', ('col7') => 'col7', ('col8') => 'col8', ), ), ), ); ?> |