0 Users appreciate this thread.
Quick code snippets [Updated constantly]
PLMasterSSB (2014-02-18 02:51:05)Helpful, but I'll just stick with if()
^ Click
(This Image was created from cooltext.com)
(Capt.)Orb (2014-02-19 15:13:53)Another new site. Wow.
Aviation fact: The a380 is the largest commerical aircraft in service!
Go to Splashiverse! Splashiverse
Go to Splashiverse! Splashiverse
Log in to submit a comment
Back to forum: Web Programming (HTML, JS, CSS, PHP, MySQL)
New registered users today: 7
Newest registered user: ElegantVulpes
I've been working on my new site, AR7Comm, and I've been working on common codes to make the use more easy. (For me at least, I code mostly on my phone)
The first one is shortif, a shortened version of the if() function, because my phone's physical keyboard does not include an equal key, making this pretty hard for me to use the if statement, which I use constantly.
[code=*php]
<?php
function shortif($var1, $var2){
if($var1 == $var2){
return true;
}
?>
[/code]
This only uses the == version though, and you can modify it to use the different if() usages.
[code=*php]
<?php
function shortif($var1, $var2){ // if var1 equals var2
if($var1 == $var2){
return true;
}
function shortgreater($var1, $var2){ // if var1 is greater than var2
if($var1 > $var2){
return true;
}
function shortless($var1, $var2){ // if var1 is less than var2
if($var1< $var2){
return true;
}
?>
[/code]
And to use them? Simple.
[code=*php]
<?php
if(shortif($thd, 1)){ // sample, thd is used in my forum script
echo 'AR7Comm General';
}
?>
[/code]
For the greater/less, the same applies. Just set them accordingly.[/spoiler]
The next one is for a forum. It can be used in two ways, as forumcount() and postcount().
This is for displaying the amount of threads on the main page of a forum. This is for MySQLi, but can easily be converted to MySQL, which is outdated.
[code=*php]<?php
function forumcount($num){
$querydata = "SELECT * FROM forums WHERE topic = $num"; // Define query
$query = mysqli_query($con, $querydata); // Activate query
echo mysqli_num_rows($query); // Echo number of rows
}
?>
[/code]
To use it is easy.
[code=*php]<?php
echo forumcount(1);
?>[/code]
The 1 will show the number of threads in category '1' of your forum. (AR7Comm General in my case) Change 1 to whatever category number you want.
This is for the main page as stated before. It needs to be modified to work with your forum script. (I will opensource mine when it's ready)[/spoiler]
This is for displaying the amount of posts on a thread on the thread list of your forum script. Put this code in the loop displaying the rows in your script.
[code=*php]<?php
function postcount($thd){
$querydata = "SELECT * FROM forumposts WHERE topic_id = $thd"; // Define query
$query = mysqli_query($con, $querydata); // Activate query
echo mysqli_num_rows($query); // Echo number of rows
}
?>
[/code]
To use it is simple. In the same loop, put (in my case):
[code=*php]
<?php echo postcount($row['id']); ?>
[/code]
This can be modified like the other to work with your forum script.[/spoiler]
2014-03-06 08:07:11