Jump to content

PdVortex

Members
  • Posts

    29
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

PdVortex's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thats wicked and perfectly explained thanks very much appreciate it a lot. One last question for you, is this part necessary? $cols = implode( ', ', array( FORUM_TOPIC, TID ) ); could i not just add the constants directly into the sql line or just the table colum names i need? something like this $sql = " SELECT id, topic FROM forum_topic WHERE forum_topic.user_id='{$this->userId}' ORDER BY datetime DESC LIMIT 5 "; Thanks again.
  2. function connectToDb () { // Make connection to MySQL server if (!$this->dbConn = @mysql_connect($this->host, $this->dbUser, $this->dbPass)) { trigger_error('Could not connect to server'); $this->connectError=true; // Select database } else if ( !@mysql_select_db($this->dbName,$this->dbConn) ) { trigger_error('Could not select database'); $this->connectError=true; } } Is the code im using to connect function & query($sql) { if (!$queryResource=mysql_query($sql,$this->dbConn)) trigger_error ('Query failed: '.mysql_error($this->dbConn). ' SQL: '.$sql); return new MySQLResult($this,$queryResource); } } is the code i use to query the db function fetch () { if ( $row=mysql_fetch_array($this->query,MYSQL_ASSOC) ) { return $row; } else if ( $this->size() > 0 ) { mysql_data_seek($this->query,0); return false; } else { return false; } } is the code i use to fetch the info.
  3. Yes that way would be more clearer how would i implement that? Like your above code? In which case would i still put the cho like this? foreach($user->forumPosts() as $index => $record) { echo '<a href="../forum/view_topic.php?id='. $record[id] .'">' . $record[topic] . '</a><br />'; } With out sounding like an idiot... what's an api can you give me an example of one.
  4. @ roopurt18 Your method can you explain it a bit more.... If the numerical indexes were the same i wouldn't be able to display the correct data? How would i display TOPIC_ID and TOPIC_TITLE ?
  5. Hey thanks for your responses, to be brutally honest i had no idea where you were going mrMarcus lol However Koobi your method works perfectly. function forumTopics() { $sql = "SELECT * FROM forum_topic WHERE forum_topic.user_id='".$this->userId."' ORDER BY datetime DESC LIMIT 5"; $result=$this->db->query($sql); $FTopics = array(); //initialize as an array while ($row = $result->fetch()){ //it makes no sense to use $this here $FTopics[] = array($row[FORUM_TOPIC], $row[TID]); } return $FTopics; } And the echoing code : echo ' Here are your 5 latest forum topics : <br />'; foreach($user->forumTopics() as $index => $record) { echo '<a href="../forum/view_topic.php?id='. $record[1] .'">' . $record[0] . '</a><br />'; } I don't like to put output in a class anyway cheers for the advice and help guys you been great!
  6. Hey thanks for both of your responses, just wondering if i pull 2 bits of information from the function and display them. i.e. $row[FORUM_TOPIC] and $row[FORUM_ID] I cant figure it out $FReplys[] = $row[FORUM_R_ID][FORUM_REPLYS] .'<br />'; That dont work but then to be honest i didnt think it would $FRId[] = $row[FORUM_R_ID]; $FReplys[] = $row[FORUM_REPLYS]; return $FRId; return $FReplys; That doesn't work ah why is the little bit of code irritating me sooo much
  7. @roopurt18 If i wanted to put the contents of the sql into an array how would i go about that?
  8. return causes a function to end, optionally returning one value to the calling code. That one value returned can be any PHP data type, including but not limited to: + ints + strings + floats + objects + arrays + arrays of objects + arrays of arrays of arrays of objects etc. Basically, if you want to return a list or collection of items, then you must build them up as an array inside the function and then return the entire array. Thanks for the info roopurt18 although mrMarcus solution also works fine. Definitely not I'm new OOP but not that new Thank you MadTechie you add-on to mrMarcus's code worked perfectly I give you the final working code below for anyone else who may need help with a problem like this. function forumTopics() { $sql = "SELECT * FROM forum_topic WHERE forum_topic.user_id='".$this->userId."' ORDER BY datetime DESC LIMIT 5"; $result=$this->db->query($sql); $this->FTopics = ""; while ($row = $result->fetch()){ $this->FTopics .= $row[FORUM_TOPIC] .'<br />'; } return $this->FTopics; } Thank you all so much for your help, I try to solve things on my own before running and asking for help, I normally solve the problems on my own but this one got the better of me. Really appreciate you taking the time to help me out. --Topic marked solved-- Oh and ***Hits myself with the yellow pages***
  9. Thanks mrMarcus, your solution worked fine apart from its duplicating the output twice so now im getting "test1 test2 test3 test4" "test1 test2 test3 test4" any ideas on that one? Ah yes thank you for pointing that out roopurt18 I was wondering if return was only capable of output one row. I believe the -> just points to an object inside a class an object is a function. $var->functionGetTime Someone correct me if im wrong please don't want to confuse anyone
  10. Hello i need some help with a tiny bit of code which i've been trying to solve on my own for well over 7 hours and to be honest i've exhausted all my ideas... and i bet the solution is so simple when someone helps me i will slap myself in the face with a yellow pages book! So here goes : This is my output code : echo ' Here are your latest forum topics : <br />'; $Topics = $user->forumTopics(); echo $Topics; Which should output the latest topic from a forum that a user has made! This is the code from the class into which the above code is refereing too : function forumTopics() { $sql = "SELECT * FROM forum_topic WHERE forum_topic.user_id='".$this->userId."' ORDER BY datetime ASC LIMIT 5"; $result=$this->db->query($sql); while ($row = $result->fetch()){ return $this->Topics=$row[FORUM_TOPIC]; } } Now i know the sql is correct because its outputting one of the recent topics, but ONLY one it should be outputting 5... Can anyone help me with this. i have tried for loops but nothing i have done works and its really starting to drive me crazy Thanks in advance guys/girls.
  11. Any solution? Or just more questions?
  12. Hey thanks for your reply, i have already said what the lines are here they are again : Line 70 is this : strtolower($value); Line 88 is this : { Line 117 is this : { Sorry i don't know how to highlight the code. Thanks for any help in advance
  13. Im guessing nobody knows why this is happening then
  14. Thanks for you reply but. . . 1 what do you mean? 2 its something to do with the array?
×
×
  • 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.