Jump to content

marcus

Members
  • Posts

    1,842
  • Joined

  • Last visited

Posts posted by marcus

  1. Um, lol, there's a lot easier way of doing it without using Smarty.

     

    <?php
    
    function tpl($output){
    $find = array("<{CONTENT}>","<{FOOTER}>");
    $repl = array(file_get_contents("content.php"), file_get_contents("footer.php"));
    
    return str_replace($find, $repl, $output);
    }
    
    ob_start("tpl");
    
    echo "<{CONTENT}>";
    echo "<{FOOTER}>";
    
    ob_end_flush();
    ?>

  2. That won't work.

     

    Why don't you actually test what you've made?

     

    <?php
    if ($_POST['submit'] == "Submit") {
        // connect to db
        $cn1 = mysql_connect('localhost', $dbuser, $dbpass) or die(mysql_error());
        mysql_select_db(ratemy_rater, $cn1) or die(mysql_error());
        // check to see if "New UserName" exist"
        $query = "SELECT m_user FROM rate_members WHERE m_user = $NewUser"; // look for New user in DB
        $ident = mysql_query($query, $cn1) or die(mysql_error($cn1));
        $result = mysql_fetch_assoc($ident);
    
        if ($result == false) { // the new username is not in use
            mysql_query("UPDATE m_user SET m_user = ".$NewUser." WHERE m_user = ".$CUser."") or die(mysql_error());
            header("Location: http://www.mysite.com/logout.php"); // log user out so they can re-enter with new name
            exit();
        } elseif ($result == true) {
            die("Username already in use, please select a another name. Link to update-name.php");
        }
    } else {
        echo "<form method=\"post\">";
        echo "Current UserName: <input type=\"text\" name=\"Cuser\" value=\"\"><br>";
        echo "New UserName: <input type=\"text\" name=\"NewUser\" value=\"\"><br>";
        echo "<input type=\"submit\" name=\"submit\" value=\"Submit\">";
    }
    ?>

  3. on the page with the clicking

     

    <?php
    $ip = $_SERVER['REMOTE_ADDR'];
    
    $sql = "SELECT * FROM `ip_log` WHERE `ip`='".$ip."'";
    $res = mysql_query($sql) or die(mysql_error());
    
    $err = false;
    
    if(mysql_num_rows($res) == 0){
    $sql2 = "INSERT INTO `ip_log` (`ip`,`clicks`) VALUES('".$ip."','1')";
    $res2 = mysql_query($sql2) or die(mysql_error());
    $err = false;
    }else {
    $row = mysql_fetch_assoc($res);
    
    if($row['clicks'] >= 5){
    	$err = true;
    }else {
    	$sql3 = "UPDATE `ip_log` SET `clicks`=`clicks`+1 WHERE `ip`='".$ip."'";
    	$res3 = mysql_query($sql3) or die(mysql_error());
    	$err = false;
    }
    }
    
    if($err){
    echo "You have already clicked this page 5 times!";
    }else {
    // whatever
    }
    ?>

     

    then i guess you can set a cron to run every 24 hours to reset em

  4. main_cats        sub_cats	     topics
    ---------       ----------     --------
    id	---|	id	---|	id
    name	   +---  mid	   +---  sid
    	name		name

     

    You have your main category being PHP, your sub-category PHP Help and your topic Forum Nav-Bar?

     

    <?php
    $topic_id = mysql_real_escape_string($_GET['id']); // example
    
    $sql = "SELECT * FROM `topics` WHERE `id`='".$topic_id."'";
    $res = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_assoc($res);
    
    $sql2 = "SELECT mid,name FROM `sub_cats` WHERE `id`='".$row['sid']."'";
    $res2 = mysql_query($sql2) or die(mysql_error());
    $row2 = mysql_fetch_assoc($res2);
    
    $sql3 = "SELECT name FROM `main_cats` WHERE `id`='".$row2['mid']."'";
    $res3 = mysql_query($sql3) or die(mysql_error());
    $row3 = mysql_fetch_assoc($res3);
    
    echo $row3['name'] . " > " . $row2['name'] . " > " . $row['name'];
    ?>

     

    I'm sure you can easily put that into one query, I don't deal with joins :x

  5. I suppose you can use switch as a method of viewing the latest records.

     

    <?php
    $from = $_GET['from'];
    
    function month(){
    $m = ((date("m")-1) > 0) ? date("m")-1 : 12;
    
    $day = 86400;
    $to = 31*$day;
    $t = 30*$day;
    $ms = array(1 => $to, 2 => 28*$day, 3 => $to, 4 => $t, 5 => $to, 6 => $t, 7 => $to, 8 => $to, 9 => $t, 10 => $to, 11 => $t, 12 => $to);
    
    return $ms[$m];
    }
    
    switch($from){
    case 'week': $seconds = 7*86400; break;
    case 'biweek': $seconds = 14*86400; break;
    case 'month': $seconds = month(); break;
    }
    
    // your query
    ?>

  6. Yep, just convert the dates to timestamps and sort them.

     

    <?php
    $date = strtotime(date("M d, y"));
    
    $dates[] = strtotime("+3 days", $date);
    $dates[] = strtotime("+1 week", $date);
    $dates[] = strtotime("+1 year", $date);
    $dates[] = strtotime("+1 month", $date);
    
    sort($dates);
    
    $closest = $dates[0];
    $farthest = $dates[3];
    
    echo date("M d, y", $closest); // plus 3 days
    echo "<br>";
    echo date("M d, y", $farthest); // plus 1 year
    
    echo "<br><br>"; // now all the dates
    
    foreach($dates AS $dated){
    echo date("M d, y", $dated) . "<br>";
    }
    ?>
    

  7. You can explode it.

     

    <?php
    $sql = "SELECT tags FROM `videos` WHERE `id`='5'";
    $res = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_assoc($res);
    
    $tags = explode(",", $row['tags']);
    
    foreach($tags AS $tag){
    echo "<a href=\"search.php?tag=".trim($tag)."\">".$tag."</a> ";
    }
    ?>

  8. For an ideal advanced search system, you can easily start by defining what table you're looking in.

     

    <?php
    $by = $_POST['by'];
    $type = $_POST['type'];
    $query = $_POST['query'];
    
    // of course you should protect the data above
    
    $sql = "SELECT * FROM `users`";
    
    switch($type){
    case 'exact': $addon = "='".$query."'"; break;
    case 'cont': $addon = " LIKE '%".$query."%'"; break;
    
    default: $addon = "='".$query."'";
    }
    
    switch($by){
    case 'username': $sql .= " WHERE `username`" . $addon; break;
    case 'email': $sql .= " WHERE `email`" . $addon; break;
    case 'name': $sql .= " WHERE `name`" . $addon; break;
    
    default: $sql .= " WHERE `username`" . $addon;
    }
    
    $res = mysql_query($sql) or die(mysql_error());
    
    if(mysql_num_rows($res) == 0){
    echo "Your search returned no results!";
    }else {
    while($row = mysql_fetch_assoc($res)){
    	echo $row['username'] . " // " . $row['email'] . " // " . $row['name'] . "<br>\n";
    }
    }
    ?>

  9. <?php
    $data = $_POST['main'];
    $name = $_POST['name'];
    
    if(!$data || !$name){
    echo "You need data and/or a name!";
    }else {
    $file = "/games/" . $name . ".php";
    
    if(file_exists($file)){
    	echo "The file <b>".$file."</b> already exists!\n";
    }else {
    	$f = fopen($file, "w+");
    	fwrite($f, $data);
    	fclose($f);
    
    	echo "The game file has been created!\n";
    }
    }
    ?>

×
×
  • 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.