Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
mysql_result() error.
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Unidentified" data-source="post: 299645" data-attributes="member: 18502"><p>I would like to show you that MySQL_Result is not really needed, you can use it better by doing the folliwing..</p><p></p><p>Basic MySQL you can make a function :</p><p></p><p><em>This is a Single Function. Output it by putting in your code echo Stats('cloudflare_resolved');</em></p><p>[CODE]<?php</p><p> function Stats($Retrieve){</p><p> $Query = MySQL_Query("SELECT * FROM `stats`");</p><p> WHILE($Result = MySQL_Fetch_Assoc($Query){</p><p> Return(Mysql_Real_Escape_String($Result[$Retrieve]));</p><p> }</p><p> }</p><p>?>[/CODE]</p><p>You Should really have a Sanitize Function...</p><p>[CODE]<?php</p><p> function Sanitize($Data){</p><p> return(mysql_real_escape_string($Data));</p><p> }</p><p> function Stats($Retrieve){</p><p> $Query = MySQL_Query("SELECT * FROM `stats`");</p><p> WHILE($Result = MySQL_Fetch_Assoc($Query){</p><p> Return(Sanitize($Result[$Retrieve]));</p><p> }</p><p> }</p><p>?>[/CODE]</p><p>For a MySQLi use..</p><p></p><p>[CODE]<?php</p><p> Class DB{</p><p> Private Static $Connect;</p><p> </p><p> Public Function __construct($Localhost, $Username, $Password, $Database)</p><p> {</p><p> self::$Connect = new Mysqli($Localhost, $Username, $Password, $Database);</p><p> if(self::$Connect->connect_errno){</p><p> echo"</p><p> Couldn't connect to Database</p><p> ";</p><p> }</p><p> }</p><p></p><p> Public Static Function Query($Query)</p><p> {</p><p> return(mysqli_query(self::$Connect, $Query));</p><p> }</p><p> </p><p> Public Static Function Sanitize($Data)</p><p> {</p><p> return(self::$Connect->real_escape_string($Data));</p><p> }</p><p> </p><p> Public Static Function Stats($Retrieve){</p><p> global $Mysqli;</p><p> $Query = $Mysqli::Query("SELECT * FROM `stats`");</p><p> WHILE($Result = mysqli_fetch_assoc($Query)){</p><p> Return($Mysqli::Sanitize($Result[$Retrieve]));</p><p> }</p><p> }</p><p> } $Mysqli = new DB("Localhost", "root", "Password", "Database");</p><p>?>[/CODE]</p><p></p><p><em>To Output this you write in your code echo $Mysqli::Stats('<em>cloudflare_resolved');</em></em></p></blockquote><p></p>
[QUOTE="Unidentified, post: 299645, member: 18502"] I would like to show you that MySQL_Result is not really needed, you can use it better by doing the folliwing.. Basic MySQL you can make a function : [I]This is a Single Function. Output it by putting in your code echo Stats('cloudflare_resolved');[/I] [CODE]<?php function Stats($Retrieve){ $Query = MySQL_Query("SELECT * FROM `stats`"); WHILE($Result = MySQL_Fetch_Assoc($Query){ Return(Mysql_Real_Escape_String($Result[$Retrieve])); } } ?>[/CODE] You Should really have a Sanitize Function... [CODE]<?php function Sanitize($Data){ return(mysql_real_escape_string($Data)); } function Stats($Retrieve){ $Query = MySQL_Query("SELECT * FROM `stats`"); WHILE($Result = MySQL_Fetch_Assoc($Query){ Return(Sanitize($Result[$Retrieve])); } } ?>[/CODE] For a MySQLi use.. [CODE]<?php Class DB{ Private Static $Connect; Public Function __construct($Localhost, $Username, $Password, $Database) { self::$Connect = new Mysqli($Localhost, $Username, $Password, $Database); if(self::$Connect->connect_errno){ echo" Couldn't connect to Database "; } } Public Static Function Query($Query) { return(mysqli_query(self::$Connect, $Query)); } Public Static Function Sanitize($Data) { return(self::$Connect->real_escape_string($Data)); } Public Static Function Stats($Retrieve){ global $Mysqli; $Query = $Mysqli::Query("SELECT * FROM `stats`"); WHILE($Result = mysqli_fetch_assoc($Query)){ Return($Mysqli::Sanitize($Result[$Retrieve])); } } } $Mysqli = new DB("Localhost", "root", "Password", "Database"); ?>[/CODE] [I]To Output this you write in your code echo $Mysqli::Stats('[I]cloudflare_resolved');[/I][/I] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
mysql_result() error.
Top